Skip to content

Commit

Permalink
[NETPROD-3585] Optimised fetching certificates by name (#1115)
Browse files Browse the repository at this point in the history
* Optimized fetching certificates by name

* Added godo changes for fetching certificate by name

* added latest godo

* Integrated godo with finding certificate by name

* included vendor modules

* included vendor module changes

* moved err check above
  • Loading branch information
guptado authored Feb 29, 2024
1 parent 2d8425f commit f1c7d18
Show file tree
Hide file tree
Showing 12 changed files with 531 additions and 60 deletions.
38 changes: 10 additions & 28 deletions digitalocean/certificate/datasource_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,37 +93,19 @@ func dataSourceDigitalOceanCertificateRead(ctx context.Context, d *schema.Resour
}

func FindCertificateByName(client *godo.Client, name string) (*godo.Certificate, error) {
opts := &godo.ListOptions{
Page: 1,
PerPage: 200,
}

for {
certs, resp, err := client.Certificates.List(context.Background(), opts)
if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, nil
}
if err != nil {
return nil, fmt.Errorf("Error retrieving certificates: %s", err)
}

for _, cert := range certs {
if cert.Name == name {
return &cert, nil
}
}

if resp.Links == nil || resp.Links.IsLastPage() {
break
}
cert, resp, err := client.Certificates.ListByName(context.Background(), name, nil)
if err != nil {
return nil, fmt.Errorf("Error retrieving certificates: %s", err)
}

page, err := resp.Links.CurrentPage()
if err != nil {
return nil, fmt.Errorf("Error retrieving certificates: %s", err)
}
if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, nil
}

opts.Page = page + 1
if len(cert) == 0 {
return nil, fmt.Errorf("certificate not found")
}

return nil, fmt.Errorf("Certificate %s not found", name)
return &cert[0], err
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/digitalocean/terraform-provider-digitalocean

require (
github.com/aws/aws-sdk-go v1.42.18
github.com/digitalocean/godo v1.108.0
github.com/digitalocean/godo v1.109.1-0.20240228180303-16a4709be517
github.com/hashicorp/awspolicyequivalence v1.5.0
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/digitalocean/godo v1.108.0 h1:fWyMENvtxpCpva1UbKzOFnyAS04N1FNuBWWfPeTGquQ=
github.com/digitalocean/godo v1.108.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/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
Expand Down
7 changes: 7 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

0 comments on commit f1c7d18

Please sign in to comment.