Skip to content

Commit

Permalink
Added godo changes for fetching certificate by name
Browse files Browse the repository at this point in the history
  • Loading branch information
guptado committed Feb 28, 2024
1 parent 67da5b5 commit 19a55d2
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions digitalocean/certificate/datasource_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,14 @@ func dataSourceDigitalOceanCertificateRead(ctx context.Context, d *schema.Resour
}

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

certs, resp, err := client.Certificates.List(context.Background(), opts)
cert, resp, err := client.Certificates.ListByName(context.Background(), name, nil)
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
}
}

return nil, fmt.Errorf("Certificate %s not found", name)
return cert, err
}

0 comments on commit 19a55d2

Please sign in to comment.