diff --git a/client.go b/client.go index 2617ced..c3eda12 100644 --- a/client.go +++ b/client.go @@ -33,6 +33,7 @@ const ( iamServiceName = "iam" kubernetesServiceName = "kubernetes_engine" loadBalancerServiceName = "load_balancer" + kmsServiceName = "key_management_service" mediaType = "application/json; charset=utf-8" serverServiceName = "cloud_server" ua = "bizfly-client-go/" + version @@ -80,6 +81,7 @@ type Client struct { KubernetesEngine KubernetesEngineService Service ServiceInterface Token TokenService + KMS KMSService } // Option set Client specific attributes @@ -165,6 +167,7 @@ func NewClient(options ...Option) (*Client, error) { c.CloudLoadBalancer = &cloudLoadBalancerService{client: c} c.Service = &service{client: c} c.Token = &token{client: c} + c.KMS = &kmsService{client: c} return c, nil } diff --git a/client_test.go b/client_test.go index 742afc1..119cff5 100644 --- a/client_test.go +++ b/client_test.go @@ -95,6 +95,12 @@ func setup() { ServiceURL: serverTest.URL + "/api/cloud-database", Region: testRegion, }, + { + Name: "KMS", + CanonicalName: kmsServiceName, + ServiceURL: serverTest.URL + "/api/ssl", + Region: testRegion, + }, } client.services = services if err != nil { diff --git a/go.mod b/go.mod index b3716c7..cf06a6a 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,4 @@ module github.com/bizflycloud/gobizfly go 1.16 -require ( - github.com/stretchr/testify v1.4.0 - golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect - golang.org/x/tools v0.14.0 // indirect -) +require github.com/stretchr/testify v1.4.0 diff --git a/go.sum b/go.sum index e4b7a13..8fdee58 100644 --- a/go.sum +++ b/go.sum @@ -5,64 +5,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= -golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= -golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= -golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= -golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= -golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= -golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= -golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= diff --git a/kms.go b/kms.go new file mode 100644 index 0000000..154d48f --- /dev/null +++ b/kms.go @@ -0,0 +1,10 @@ +package gobizfly + +type kmsService struct { + client *Client +} + +type KMSService interface { + Certificates() *kmsCertificateService + Secrets() *kmsSecretService +} diff --git a/kms_certificate.go b/kms_certificate.go new file mode 100644 index 0000000..6c91de5 --- /dev/null +++ b/kms_certificate.go @@ -0,0 +1,156 @@ +package gobizfly + +import ( + "context" + "encoding/json" + "io" + "net/http" +) + +type KMSCertificateService interface { + List(ctx context.Context) ([]*KMSCertificate, error) + Get(ctx context.Context, id string) (*KMSCertificate, error) + Create(ctx context.Context, req *KMSCertificateContainerCreateRequest) (*KMSCertificateCreateResponse, error) + Delete(ctx context.Context, id string) error +} + +type kmsCertificateService struct { + client *Client +} + +func (k *kmsService) Certificates() *kmsCertificateService { + return &kmsCertificateService{ + client: k.client, + } +} + +type KMSCertificate struct { + ContainerID string `json:"container_id"` + Name string `json:"name"` +} + +type KMSCertificateContainerCreateRequest struct { + CertContainer KMSCertContainer `json:"cert_container"` +} + +type KMSCertContainer struct { + Name string `json:"name"` + Certificate KMSCertificateCreateReqest `json:"certificate"` + PrivateKey KMSPrivateKeyCreateReqest `json:"private_key"` + PrivateKeyPassphrase KMSPrivateKeyPassphraseCreateReqest `json:"private_key_passphrase"` + Intermediates *KMSIntermediatesCreateReqest `json:"intermediates,omitempty"` +} + +type KMSCertificateCreateReqest struct { + Name string `json:"name"` + Payload string `json:"payload"` +} + +type KMSPrivateKeyCreateReqest struct { + Name string `json:"name"` + Payload string `json:"payload"` +} + +type KMSPrivateKeyPassphraseCreateReqest struct { + Name string `json:"name"` + Payload string `json:"payload"` +} + +type KMSIntermediatesCreateReqest struct { + Name string `json:"name,omitempty"` + Payload string `json:"payload,omitempty"` +} + +type KMSCertificateCreateResponse struct { + CertificateHref string `json:"certificate_href"` +} + +type KMSCertificateListResponse struct { + CertificateContainer []*KMSCertificate `json:"certificate_container"` + Total int `json:"total"` +} + +type KMSCertificateGetResponse struct { + ContainerID string `json:"container_id"` + Name string `json:"name"` + Certificate string `json:"certificate"` +} + +const ( + certificateServicePath = "/certificate_container" +) + +func (c *kmsCertificateService) List(ctx context.Context) ([]*KMSCertificate, error) { + path := certificateServicePath + req, err := c.client.NewRequest(ctx, http.MethodGet, kmsServiceName, path, nil) + if err != nil { + return nil, err + } + + resp, err := c.client.Do(ctx, req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + var respDecode KMSCertificateListResponse + if err := json.NewDecoder(resp.Body).Decode(&respDecode); err != nil { + return nil, err + } + + return respDecode.CertificateContainer, nil +} + +func (c *kmsCertificateService) Get(ctx context.Context, id string) (*KMSCertificateGetResponse, error) { + path := certificateServicePath + "/" + id + req, err := c.client.NewRequest(ctx, http.MethodGet, kmsServiceName, path, nil) + if err != nil { + return nil, err + } + resp, err := c.client.Do(ctx, req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + var data *KMSCertificateGetResponse + if err := json.NewDecoder(resp.Body).Decode(&data); err != nil { + return nil, err + } + return data, nil +} + +func (c *kmsCertificateService) Create(ctx context.Context, payload *KMSCertificateContainerCreateRequest) (*KMSCertificateCreateResponse, error) { + path := certificateServicePath + + req, err := c.client.NewRequest(ctx, http.MethodPost, kmsServiceName, path, payload) + if err != nil { + return nil, err + } + resp, err := c.client.Do(ctx, req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + var data *KMSCertificateCreateResponse + if err := json.NewDecoder(resp.Body).Decode(&data); err != nil { + return nil, err + } + return data, nil +} + +func (c *kmsCertificateService) Delete(ctx context.Context, id string) error { + path := certificateServicePath + "/" + id + req, err := c.client.NewRequest(ctx, http.MethodDelete, kmsServiceName, path, nil) + if err != nil { + return err + } + resp, err := c.client.Do(ctx, req) + if err != nil { + return err + } + _, _ = io.Copy(io.Discard, resp.Body) + + return resp.Body.Close() +} diff --git a/kms_secret.go b/kms_secret.go new file mode 100644 index 0000000..d7850ec --- /dev/null +++ b/kms_secret.go @@ -0,0 +1,25 @@ +package gobizfly + +import "context" + +type KMSSecretService interface { + List(ctx context.Context, page, total int) ([]*KMSKey, error) + Get(ctx context.Context, id string) (*KMSKey, error) + Create(ctx context.Context, key *KMSKey) (*KMSKey, error) + Delete(ctx context.Context, id string) error +} + +type kmsSecretService struct { + client *Client +} + +func (k *kmsService) Secrets() *kmsSecretService { + return &kmsSecretService{ + client: k.client, + } +} + +type KMSKey struct { + ID string `json:"id"` + Name string `json:"name"` +} diff --git a/kms_test.go b/kms_test.go new file mode 100644 index 0000000..e4e5401 --- /dev/null +++ b/kms_test.go @@ -0,0 +1,171 @@ +package gobizfly + +import ( + "fmt" + "net/http" + "testing" + + "github.com/bizflycloud/gobizfly/testlib" + "github.com/stretchr/testify/require" +) + +func TestListKMSCertificates1(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc(testlib.KMSURL(certificateServicePath), func(w http.ResponseWriter, r *http.Request) { + require.Equal(t, http.MethodGet, r.Method) + resp := ` +{ + "certificate_container": [ + { + "container_id": "366991bc-4622-458a-bbf5-4341bef3837e", + "name": "test1" + } + ], + "total": 1 +} + ` + _, _ = fmt.Fprint(w, resp) + }) + cert, err := client.KMS.Certificates().List(ctx) + if err != nil { + t.Fatal(err) + } + + require.NoError(t, err) + require.Equal(t, 1, len(cert)) + require.Equal(t, "test1", cert[0].Name) + require.Equal(t, "366991bc-4622-458a-bbf5-4341bef3837e", cert[0].ContainerID) + + t.Log(cert) +} + +func TestGetKMSCertificate(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc(testlib.KMSURL(certificateServicePath)+"/366991bc-4622-458a-bbf5-4341bef3837e", func(w http.ResponseWriter, r *http.Request) { + require.Equal(t, http.MethodGet, r.Method) + resp := ` +{ + "container_id": "366991bc-4622-458a-bbf5-4341bef3837e", + "name" : "test1", + "certificate": "certificate" +} + ` + _, _ = fmt.Fprint(w, resp) + }) + cert, err := client.KMS.Certificates().Get(ctx, "366991bc-4622-458a-bbf5-4341bef3837e") + if err != nil { + t.Fatal(err) + } + + require.NoError(t, err) + require.Equal(t, "test1", cert.Name) + require.Equal(t, "366991bc-4622-458a-bbf5-4341bef3837e", cert.ContainerID) + require.Equal(t, "certificate", cert.Certificate) + + t.Log(cert) +} + +func TestCreateKMSCertificate(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc(testlib.KMSURL(certificateServicePath), func(w http.ResponseWriter, r *http.Request) { + require.Equal(t, http.MethodPost, r.Method) + resp := ` +{ + "certificate_href": "/kms/certificate/366991bc-4622-458a-bbf5-4341bef3837e" +} + ` + _, _ = fmt.Fprint(w, resp) + }) + cert, err := client.KMS.Certificates().Create(ctx, &KMSCertificateContainerCreateRequest{ + CertContainer: KMSCertContainer{ + Name: "test1", + Certificate: KMSCertificateCreateReqest{ + Name: "certificate", + Payload: `-----BEGIN CERTIFICATE----- +MIID0DCCArigAwIBAgIBATANBgkqhkiG9w0BAQUFADB/MQswCQYDVQQGEwJGUjET +MBEGA1UECAwKU29tZS1TdGF0ZTEOMAwGA1UEBwwFUGFyaXMxDTALBgNVBAoMBERp +bWkxDTALBgNVBAsMBE5TQlUxEDAOBgNVBAMMB0RpbWkgQ0ExGzAZBgkqhkiG9w0B +CQEWDGRpbWlAZGltaS5mcjAeFw0xNDAxMjgyMDM2NTVaFw0yNDAxMjYyMDM2NTVa +MFsxCzAJBgNVBAYTAkZSMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJ +bnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxFDASBgNVBAMMC3d3dy5kaW1pLmZyMIIB +IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvpnaPKLIKdvx98KW68lz8pGa +RRcYersNGqPjpifMVjjE8LuCoXgPU0HePnNTUjpShBnynKCvrtWhN+haKbSp+QWX +SxiTrW99HBfAl1MDQyWcukoEb9Cw6INctVUN4iRvkn9T8E6q174RbcnwA/7yTc7p +1NCvw+6B/aAN9l1G2pQXgRdYC/+G6o1IZEHtWhqzE97nY5QKNuUVD0V09dc5CDYB +aKjqetwwv6DFk/GRdOSEd/6bW+20z0qSHpa3YNW6qSp+x5pyYmDrzRIR03os6Dau +ZkChSRyc/Whvurx6o85D6qpzywo8xwNaLZHxTQPgcIA5su9ZIytv9LH2E+lSwwID +AQABo3sweTAJBgNVHRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVy +YXRlZCBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQU+tugFtyN+cXe1wxUqeA7X+yS3bgw +HwYDVR0jBBgwFoAUhMwqkbBrGp87HxfvwgPnlGgVR64wDQYJKoZIhvcNAQEFBQAD +ggEBAIEEmqqhEzeXZ4CKhE5UM9vCKzkj5Iv9TFs/a9CcQuepzplt7YVmevBFNOc0 ++1ZyR4tXgi4+5MHGzhYCIVvHo4hKqYm+J+o5mwQInf1qoAHuO7CLD3WNa1sKcVUV +vepIxc/1aHZrG+dPeEHt0MdFfOw13YdUc2FH6AqEdcEL4aV5PXq2eYR8hR4zKbc1 +fBtuqUsvA8NWSIyzQ16fyGve+ANf6vXvUizyvwDrPRv/kfvLNa3ZPnLMMxU98Mvh +PXy3PkB8++6U4Y3vdk2Ni2WYYlIls8yqbM4327IKmkDc2TimS8u60CT47mKU7aDY +cbTV5RDkrlaYwm5yqlTIglvCv7o= +-----END CERTIFICATE-----`, + }, + PrivateKey: KMSPrivateKeyCreateReqest{ + Name: "private_key", + Payload: `-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAvpnaPKLIKdvx98KW68lz8pGaRRcYersNGqPjpifMVjjE8LuC +oXgPU0HePnNTUjpShBnynKCvrtWhN+haKbSp+QWXSxiTrW99HBfAl1MDQyWcukoE +b9Cw6INctVUN4iRvkn9T8E6q174RbcnwA/7yTc7p1NCvw+6B/aAN9l1G2pQXgRdY +C/+G6o1IZEHtWhqzE97nY5QKNuUVD0V09dc5CDYBaKjqetwwv6DFk/GRdOSEd/6b +W+20z0qSHpa3YNW6qSp+x5pyYmDrzRIR03os6DauZkChSRyc/Whvurx6o85D6qpz +ywo8xwNaLZHxTQPgcIA5su9ZIytv9LH2E+lSwwIDAQABAoIBAFml8cD9a5pMqlW3 +f9btTQz1sRL4Fvp7CmHSXhvjsjeHwhHckEe0ObkWTRsgkTsm1XLu5W8IITnhn0+1 +iNr+78eB+rRGngdAXh8diOdkEy+8/Cee8tFI3jyutKdRlxMbwiKsouVviumoq3fx +OGQYwQ0Z2l/PvCwy/Y82ffq3ysC5gAJsbBYsCrg14bQo44ulrELe4SDWs5HCjKYb +EI2b8cOMucqZSOtxg9niLN/je2bo/I2HGSawibgcOdBms8k6TvsSrZMr3kJ5O6J+ +77LGwKH37brVgbVYvbq6nWPL0xLG7dUv+7LWEo5qQaPy6aXb/zbckqLqu6/EjOVe +ydG5JQECgYEA9kKfTZD/WEVAreA0dzfeJRu8vlnwoagL7cJaoDxqXos4mcr5mPDT +kbWgFkLFFH/AyUnPBlK6BcJp1XK67B13ETUa3i9Q5t1WuZEobiKKBLFm9DDQJt43 +uKZWJxBKFGSvFrYPtGZst719mZVcPct2CzPjEgN3Hlpt6fyw3eOrnoECgYEAxiOu +jwXCOmuGaB7+OW2tR0PGEzbvVlEGdkAJ6TC/HoKM1A8r2u4hLTEJJCrLLTfw++4I +ddHE2dLeR4Q7O58SfLphwgPmLDezN7WRLGr7Vyfuv7VmaHjGuC3Gv9agnhWDlA2Q +gBG9/R9oVfL0Dc7CgJgLeUtItCYC31bGT3yhV0MCgYEA4k3DG4L+RN4PXDpHvK9I +pA1jXAJHEifeHnaW1d3vWkbSkvJmgVf+9U5VeV+OwRHN1qzPZV4suRI6M/8lK8rA +Gr4UnM4aqK4K/qkY4G05LKrik9Ev2CgqSLQDRA7CJQ+Jn3Nb50qg6hFnFPafN+J7 +7juWln08wFYV4Atpdd+9XQECgYBxizkZFL+9IqkfOcONvWAzGo+Dq1N0L3J4iTIk +w56CKWXyj88d4qB4eUU3yJ4uB4S9miaW/eLEwKZIbWpUPFAn0db7i6h3ZmP5ZL8Q +qS3nQCb9DULmU2/tU641eRUKAmIoka1g9sndKAZuWo+o6fdkIb1RgObk9XNn8R4r +psv+aQKBgB+CIcExR30vycv5bnZN9EFlIXNKaeMJUrYCXcRQNvrnUIUBvAO8+jAe +CdLygS5RtgOLZib0IVErqWsP3EI1ACGuLts0vQ9GFLQGaN1SaMS40C9kvns1mlDu +LhIhYpJ8UsCVt5snWo2N+M+6ANh5tpWdQnEK6zILh4tRbuzaiHgb +-----END RSA PRIVATE KEY-----`, + }, + PrivateKeyPassphrase: KMSPrivateKeyPassphraseCreateReqest{ + Name: "passphrase", + Payload: "", + }, + // Intermediates: KMSIntermediatesCreateReqest{}, + }, + }) + + require.NoError(t, err) + require.Equal(t, "/kms/certificate/366991bc-4622-458a-bbf5-4341bef3837e", cert.CertificateHref) + + t.Log(cert) +} + +func TestDeleteKMSCertificate(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc(testlib.KMSURL(certificateServicePath)+"/35ad8118-7212-463f-8cab-c351a25ec632", func(w http.ResponseWriter, r *http.Request) { + require.Equal(t, http.MethodDelete, r.Method) + w.WriteHeader(http.StatusNoContent) + }) + err := client.KMS.Certificates().Delete(ctx, "35ad8118-7212-463f-8cab-c351a25ec632") + + require.NoError(t, err) + + t.Log(err) +} diff --git a/testlib/url.go b/testlib/url.go index 9e1dea7..2221c7e 100644 --- a/testlib/url.go +++ b/testlib/url.go @@ -55,3 +55,7 @@ func VPCURL(path string) string { func DatabaseURL(path string) string { return "/api/cloud-database" + path } + +func KMSURL(path string) string { + return "/api/ssl" + path +}