mirror of
https://github.com/cert-manager/webhook-example.git
synced 2026-03-16 18:02:51 +01:00
fix: most simple copilot suggestions
This commit is contained in:
parent
f3a4903f27
commit
f6c70562bc
3 changed files with 34 additions and 39 deletions
|
|
@ -4,8 +4,7 @@ RUN apk add --no-cache git
|
|||
|
||||
WORKDIR /workspace
|
||||
|
||||
COPY go.mod .
|
||||
COPY go.sum .
|
||||
COPY . .
|
||||
|
||||
RUN go mod download
|
||||
|
||||
|
|
|
|||
2
main.go
2
main.go
|
|
@ -13,7 +13,7 @@ func main() {
|
|||
// Read the custom group name from environment variables
|
||||
groupName, ok := os.LookupEnv("GROUP_NAME")
|
||||
// Without a custom group name, return the default (also defined in the Helm chart)
|
||||
if !ok {
|
||||
if !ok || groupName == "" {
|
||||
groupName = "acme.pr0ton11.github.com"
|
||||
}
|
||||
// Start the webhook server with our solver
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@ type DeSECDNSProviderSolverConfig struct {
|
|||
|
||||
// A DNS-01 challenge solver for the DeSEC DNS Provider
|
||||
type DeSECDNSProviderSolver struct {
|
||||
// Client to communicate with the deSEC API
|
||||
client *desec.Client
|
||||
// Client to communicate with the kubernetes API
|
||||
k8s *kubernetes.Clientset
|
||||
}
|
||||
|
|
@ -35,14 +33,12 @@ func (s *DeSECDNSProviderSolver) Name() string {
|
|||
return "deSEC"
|
||||
}
|
||||
|
||||
// Returns the initialized API client or creates a new client if not initialized
|
||||
// Initializes a new client
|
||||
func (s *DeSECDNSProviderSolver) getClient(config *apiextensionsv1.JSON, namespace string) (*desec.Client, error) {
|
||||
// Check if client is not initialized
|
||||
if s.client == nil {
|
||||
if config == nil {
|
||||
return nil, fmt.Errorf("missing configuration in issuer found; webhook configuration requires apiKeySecretRef containing deSEC API token")
|
||||
}
|
||||
// Initialize the configuration object and unmarhal json
|
||||
// Initialize the configuration object and unmarshal json
|
||||
solverConfig := DeSECDNSProviderSolverConfig{}
|
||||
if err := json.Unmarshal(config.Raw, &solverConfig); err != nil {
|
||||
return nil, fmt.Errorf("invalid configuration in issuer found; webhook configuration requires apiKeySecretRef containing deSEC API token")
|
||||
|
|
@ -50,7 +46,7 @@ func (s *DeSECDNSProviderSolver) getClient(config *apiextensionsv1.JSON, namespa
|
|||
// Check if the namespace has been provided within the configuration
|
||||
// Otherwise use the namespace from the request
|
||||
if solverConfig.APIKeySecretRefNamespace != "" {
|
||||
fmt.Sprintf("k8s secret namespace has been overwitten in webhook configuration apiKeySecretRefNamespace from %s to %s", namespace, solverConfig.APIKeySecretRefNamespace)
|
||||
fmt.Sprintf("k8s secret namespace has been overwritten in webhook configuration apiKeySecretRefNamespace from %s to %s", namespace, solverConfig.APIKeySecretRefNamespace)
|
||||
namespace = solverConfig.APIKeySecretRefNamespace
|
||||
}
|
||||
// Check if the k8s client has been initialized
|
||||
|
|
@ -68,10 +64,10 @@ func (s *DeSECDNSProviderSolver) getClient(config *apiextensionsv1.JSON, namespa
|
|||
return nil, fmt.Errorf("k8s secret key %s not found in secret %s in namespace %s", solverConfig.APIKeySecretRef.Key, solverConfig.APIKeySecretRef.Name, namespace)
|
||||
}
|
||||
// Finally assign the client
|
||||
s.client = desec.New(string(token), desec.NewDefaultClientOptions())
|
||||
}
|
||||
client := desec.New(string(token), desec.NewDefaultClientOptions())
|
||||
|
||||
// Return the client (reuse if initialized)
|
||||
return s.client, nil
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// Present presents the TXT DNS entry after completion of the ACME DNS-01 challenge
|
||||
|
|
|
|||
Loading…
Reference in a new issue