Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(domains): add 'Manual Action' column if needed #1048

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions cmd/domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ var (
}.Render(),

Action: func(c *cli.Context) error {
currentApp := detect.CurrentApp(c)
var err error
if c.Args().Len() == 0 {
err = domains.List(c.Context, currentApp)
} else {
cli.ShowCommandHelp(c, "domains")
if c.Args().Len() > 0 {
err := cli.ShowCommandHelp(c, "domains")
if err != nil {
errorQuit(c.Context, err)
}
return nil
}

currentApp := detect.CurrentApp(c)
err := domains.List(c.Context, currentApp)
if err != nil {
errorQuit(c.Context, err)
}
Expand Down
23 changes: 18 additions & 5 deletions domains/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
"context"
"fmt"
"os"
"slices"

Check failure on line 7 in domains/list.go

View workflow job for this annotation

GitHub Actions / Unit Tests

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.14/x64/src/slices)

"github.com/olekukonko/tablewriter"
"gopkg.in/errgo.v1"

"github.com/Scalingo/cli/config"
scalingo "github.com/Scalingo/go-scalingo/v6"
"github.com/Scalingo/go-utils/errors/v2"
)

var letsencryptStatusString = map[string]string{
Expand All @@ -23,16 +24,17 @@
func List(ctx context.Context, app string) error {
c, err := config.ScalingoClient(ctx)
if err != nil {
return errgo.Notef(err, "fail to get Scalingo client")
return errors.Wrapf(ctx, err, "get Scalingo client to list domains")
}

domains, err := c.DomainsList(ctx, app)
if err != nil {
return errgo.Mask(err)
return errors.Wrapf(ctx, err, "list domains")
}

t := tablewriter.NewWriter(os.Stdout)
t.SetHeader([]string{"Domain", "TLS/SSL"})
hasCanonical := false
headers := []string{"Domain", "TLS/SSL"}

for _, domain := range domains {
domainName := domain.Name
Expand All @@ -41,19 +43,30 @@
domainName += " (*)"
}
row := []string{domainName}

if !domain.SSL {
row = append(row, "-")
} else if domain.LetsEncrypt {
letsencryptStatus, ok := letsencryptStatusString[string(domain.LetsEncryptStatus)]
if !ok {
letsencryptStatus = string(domain.LetsEncryptStatus)
}
row = append(row, fmt.Sprintf("Let's Encrypt: %s", letsencryptStatus))
row = append(row, "Let's Encrypt "+letsencryptStatus)
} else {
row = append(row, fmt.Sprintf("Valid until %v", domain.Validity))
}

if domain.LetsEncryptStatus == scalingo.LetsEncryptStatusDNSRequired {
if !slices.Contains(headers, "Manual Action") {
headers = append(headers, "Manual Action")
}
row = append(row, fmt.Sprintf("%v \n%v", domain.AcmeDNSFqdn, domain.AcmeDNSValue))
}

t.Append(row)
}

t.SetHeader(headers)
t.Render()

if hasCanonical {
Expand Down
Loading