Skip to content

Commit

Permalink
feat: update output of 'domains' in order to take letsencrypt_enabled…
Browse files Browse the repository at this point in the history
…: false
  • Loading branch information
leo-scalingo committed Apr 19, 2024
1 parent 8eba5f7 commit 82e6f52
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions domains/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
var letsencryptStatusString = map[string]string{
string(scalingo.LetsEncryptStatusPendingDNS): "Pending DNS",
string(scalingo.LetsEncryptStatusNew): "Creating",
string(scalingo.LetsEncryptStatusCreated): "In use",
string(scalingo.LetsEncryptStatusCreated): "Created",
string(scalingo.LetsEncryptStatusDNSRequired): "DNS required",
string(scalingo.LetsEncryptStatusError): "Error",
}
Expand All @@ -31,7 +31,7 @@ func List(ctx context.Context, app string) error {
}

t := tablewriter.NewWriter(os.Stdout)
t.SetHeader([]string{"Domain", "TLS/SSL"})
t.SetHeader([]string{"Domain", "TLS/SSL", "Issuer", "Let's Encrypt Certificate"})
hasCanonical := false

for _, domain := range domains {
Expand All @@ -40,18 +40,32 @@ func List(ctx context.Context, app string) error {
hasCanonical = true
domainName += " (*)"
}
row := []string{domainName}
if !domain.SSL {
row = append(row, "-")
} else if domain.LetsEncrypt {
letsencryptStatus, ok := letsencryptStatusString[string(domain.LetsEncryptStatus)]

tls := "-"
letsEncrypt := "Disabled"
if domain.LetsEncryptEnabled {
// If the domain is using Let's Encrypt (and not a custom cert), we mention it
if domain.LetsEncrypt {
tls = "Let's Encrypt"
}
// In any case we display the state of creation of the Let's Encrypt certificate
// So if a customer certification is used, it is still mentionned we have it
var ok bool
letsEncrypt, ok = letsencryptStatusString[string(domain.LetsEncryptStatus)]
if !ok {
letsencryptStatus = string(domain.LetsEncryptStatus)
letsEncrypt = string(domain.LetsEncryptStatus)
}

if !domain.LetsEncrypt && domain.LetsEncryptStatus == scalingo.LetsEncryptStatusCreated {
letsEncrypt = "Created, Not in use"
}
row = append(row, fmt.Sprintf("Let's Encrypt: %s", letsencryptStatus))
} else {
row = append(row, fmt.Sprintf("Valid until %v", domain.Validity))
}

if domain.SSL && !domain.LetsEncrypt {
tls = fmt.Sprintf("Valid until %v", domain.Validity)
}

row := []string{domainName, tls, domain.TLSCert, letsEncrypt}
t.Append(row)
}
t.Render()
Expand Down

0 comments on commit 82e6f52

Please sign in to comment.