More updates
This commit is contained in:
parent
f1715c4dd0
commit
9ffe0139eb
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.21
|
|||||||
toolchain go1.22.1
|
toolchain go1.22.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cert-manager/cert-manager v1.14.4
|
github.com/jetstack/cert-manager v1.7.3
|
||||||
github.com/miekg/dns v1.1.58
|
github.com/miekg/dns v1.1.58
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.9.0
|
||||||
k8s.io/apiextensions-apiserver v0.29.0
|
k8s.io/apiextensions-apiserver v0.29.0
|
||||||
|
|||||||
@ -4,9 +4,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"domain"
|
|
||||||
|
|
||||||
v1alpha1 "github.com/cert-manager/cert-manager/pkg/acme/webhook/apis/acme/v1alpha1"
|
v1alpha1 "github.com/jetstack/cert-manager/pkg/acme/webhook/apis/acme/v1alpha1"
|
||||||
|
"github.com/stuurmcp/cert-manager-webhook-sthome/pkg/domain"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/cert-manager/cert-manager/pkg/acme/webhook"
|
"github.com/cert-manager/cert-manager/pkg/acme/webhook"
|
||||||
acme "github.com/cert-manager/cert-manager/pkg/acme/webhook/apis/acme/v1alpha1"
|
acme "github.com/jetstack/cert-manager/pkg/acme/webhook/apis/acme/v1alpha1"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
acme "github.com/cert-manager/cert-manager/pkg/acme/webhook/apis/acme/v1alpha1"
|
acme "github.com/jetstack/cert-manager/pkg/acme/webhook/apis/acme/v1alpha1"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|||||||
80
pkg/dns/utils.go
Normal file
80
pkg/dns/utils.go
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
package dns
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/jetstack/cert-manager/pkg/acme/webhook/apis/acme/v1alpha1"
|
||||||
|
"github.com/scaleway/cert-manager-webhook-scaleway/pkg/util"
|
||||||
|
"github.com/scaleway/scaleway-sdk-go/scw"
|
||||||
|
"github.com/stuurmcp/cert-manager-webhook-sthome/pkg/domain"
|
||||||
|
|
||||||
|
//domain "github.com/scaleway/scaleway-sdk-go/api/domain/v2beta1"
|
||||||
|
//"github.com/scaleway/scaleway-sdk-go/scw"
|
||||||
|
extapi "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// loadConfig is a small helper function that decodes JSON configuration into
|
||||||
|
// the typed config struct.
|
||||||
|
func loadConfig(cfgJSON *extapi.JSON) (ProviderConfig, error) {
|
||||||
|
cfg := ProviderConfig{}
|
||||||
|
// handle the 'base case' where no configuration has been provided
|
||||||
|
if cfgJSON == nil {
|
||||||
|
return cfg, nil
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(cfgJSON.Raw, &cfg); err != nil {
|
||||||
|
return cfg, fmt.Errorf("error decoding solver config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ProviderSolver) getDomainAPI(ch *v1alpha1.ChallengeRequest) (*domain.API, error) {
|
||||||
|
config, err := loadConfig(ch.Config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to load config: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
accessKey := os.Getenv(scw.ScwAccessKeyEnv)
|
||||||
|
secretKey := os.Getenv(scw.ScwSecretKeyEnv)
|
||||||
|
|
||||||
|
if config.AccessKey != nil && config.SecretKey != nil {
|
||||||
|
accessKeySecret, err := p.client.CoreV1().Secrets(ch.ResourceNamespace).Get(context.Background(), config.AccessKey.Name, metav1.GetOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not get secret %s: %w", config.AccessKey.Name, err)
|
||||||
|
}
|
||||||
|
secretKeySecret, err := p.client.CoreV1().Secrets(ch.ResourceNamespace).Get(context.Background(), config.SecretKey.Name, metav1.GetOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not get secret %s: %w", config.SecretKey.Name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
accessKeyData, ok := accessKeySecret.Data[config.AccessKey.Key]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("could not get key %s in secret %s", config.AccessKey.Key, config.AccessKey.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
secretKeyData, ok := secretKeySecret.Data[config.SecretKey.Key]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("could not get key %s in secret %s", config.SecretKey.Key, config.SecretKey.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
accessKey = string(accessKeyData)
|
||||||
|
secretKey = string(secretKeyData)
|
||||||
|
}
|
||||||
|
|
||||||
|
scwClient, err := scw.NewClient(
|
||||||
|
scw.WithEnv(),
|
||||||
|
scw.WithAuth(accessKey, secretKey),
|
||||||
|
scw.WithUserAgent("cert-manager-webhook-scaleway/"+util.GetVersion().Version),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to initialize scaleway client: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
domainAPI := domain.NewAPI(scwClient)
|
||||||
|
|
||||||
|
return domainAPI, nil
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user