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

[NETPROD-3585] Added name filter in doctl for certificates #1509

Merged
merged 5 commits into from
Feb 29, 2024
Merged
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
16 changes: 15 additions & 1 deletion commands/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ To upload a custom certificate, you need to provide a certificate name, the path
cmdCertificateList := CmdBuilder(cmd, RunCertificateList, "list", "Retrieve list of the account's stored certificates", `This command retrieves a list of all certificates associated with the account. The following details are shown for each certificate:`+certDetails, Writer,
aliasOpt("ls"), displayerType(&displayers.Certificate{}))
cmdCertificateList.Example = `The following example retrieves a list of all certificates associated with your account and uses the ` + "`" + `--format` + "`" + ` flag return only the IDs, names, and the domains associated with each ticket: doctl compute certificate list --format ID,Name,DNSNames`
AddStringFlag(cmdCertificateList, doctl.ArgCertificateName, "", "",
"Filter certificates by the specified name")

cmdCertificateDelete := CmdBuilder(cmd, RunCertificateDelete, "delete <id>",
"Delete the specified certificate", `Deletes the specified certificate.
Expand Down Expand Up @@ -184,8 +186,20 @@ func RunCertificateCreate(c *CmdConfig) error {

// RunCertificateList lists certificates.
func RunCertificateList(c *CmdConfig) error {

name, err := c.Doit.GetString(c.NS, doctl.ArgCertificateName)
if err != nil {
return err
}

cs := c.Certificates()
list, err := cs.List()
var list do.Certificates

if name == "" {
list, err = cs.List()
} else {
list, err = cs.ListByName(name)
}
if err != nil {
return err
}
Expand Down
11 changes: 11 additions & 0 deletions commands/certificates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ func TestCertificateList(t *testing.T) {
})
}

func TestCertificateListByName(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
name := "web-cert-01"
tm.certificates.EXPECT().ListByName(name).Return(testCertificateList, nil)

config.Doit.Set(config.NS, doctl.ArgCertificateName, name)
err := RunCertificateList(config)
assert.NoError(t, err)
})
}

func TestCertificateDelete(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
cID := "892071a0-bb95-49bc-8021-3afd67a210bf"
Expand Down
12 changes: 12 additions & 0 deletions do/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type CertificatesService interface {
Get(cID string) (*Certificate, error)
Create(cr *godo.CertificateRequest) (*Certificate, error)
List() (Certificates, error)
ListByName(cName string) (Certificates, error)
Delete(cID string) error
}

Expand Down Expand Up @@ -95,6 +96,17 @@ func (cs *certificatesService) List() (Certificates, error) {
return list, nil
}

func (cs *certificatesService) ListByName(cName string) (Certificates, error) {
c, _, err := cs.client.Certificates.ListByName(context.TODO(), cName, nil)

list := make([]Certificate, len(c))
for i := range c {
list[i] = Certificate{Certificate: &c[i]}
}

return list, err
}

func (cs *certificatesService) Delete(cID string) error {
_, err := cs.client.Certificates.Delete(context.TODO(), cID)
return err
Expand Down
1 change: 1 addition & 0 deletions do/mocks/CDNsService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions do/mocks/CertificatesService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
github.com/blang/semver v3.5.1+incompatible
github.com/creack/pty v1.1.11
github.com/digitalocean/godo v1.107.0
github.com/digitalocean/godo v1.109.1-0.20240228180303-16a4709be517
github.com/docker/cli v24.0.5+incompatible
github.com/docker/docker v24.0.7+incompatible
github.com/docker/docker-credential-helpers v0.7.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/digitalocean/godo v1.107.0 h1:P72IbmGFQvKOvyjVLyT59bmHxilA4E5hWi40rF4zNQc=
github.com/digitalocean/godo v1.107.0/go.mod h1:R6EmmWI8CT1+fCtjWY9UCB+L5uufuZH13wk3YhxycCs=
github.com/digitalocean/godo v1.109.1-0.20240228180303-16a4709be517 h1:vj0Sh/Ghq4MCkE+IM84lsA+9vMfnPpsacX7PRUJ0oh4=
github.com/digitalocean/godo v1.109.1-0.20240228180303-16a4709be517/go.mod h1:R6EmmWI8CT1+fCtjWY9UCB+L5uufuZH13wk3YhxycCs=
github.com/docker/cli v24.0.5+incompatible h1:WeBimjvS0eKdH4Ygx+ihVq1Q++xg36M/rMi4aXAvodc=
github.com/docker/cli v24.0.5+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8=
Expand Down
11 changes: 11 additions & 0 deletions vendor/github.com/digitalocean/godo/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 89 additions & 0 deletions vendor/github.com/digitalocean/godo/apps.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions vendor/github.com/digitalocean/godo/apps.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading