From 7a3a1f123a68db06f55373cbbc00936b2aa3b95a Mon Sep 17 00:00:00 2001 From: Andrei Lukyanchyk Date: Thu, 28 Nov 2024 15:46:25 +0100 Subject: [PATCH] CDI-908: upd SSL certs --- sslcerts/service.go | 9 +++++++++ sslcerts/sslcerts.go | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/sslcerts/service.go b/sslcerts/service.go index 024e574..f6c2c2b 100644 --- a/sslcerts/service.go +++ b/sslcerts/service.go @@ -35,6 +35,15 @@ func (s *Service) Get(ctx context.Context, id int64) (*Cert, error) { return &cert, nil } +func (s *Service) Update(ctx context.Context, id int64, req *UpdateRequest) (*Cert, error) { + var cert Cert + if err := s.r.Request(ctx, http.MethodPatch, fmt.Sprintf("/cdn/sslData/%d", id), req, &cert); err != nil { + return nil, fmt.Errorf("request: %w", err) + } + + return &cert, nil +} + func (s *Service) Delete(ctx context.Context, id int64) error { if err := s.r.Request(ctx, http.MethodDelete, fmt.Sprintf("/cdn/sslData/%d", id), nil, nil); err != nil { return fmt.Errorf("request: %w", err) diff --git a/sslcerts/sslcerts.go b/sslcerts/sslcerts.go index 462fc77..27ed28c 100644 --- a/sslcerts/sslcerts.go +++ b/sslcerts/sslcerts.go @@ -8,6 +8,7 @@ import ( type SSLCertService interface { Create(ctx context.Context, req *CreateRequest) (*Cert, error) Get(ctx context.Context, id int64) (*Cert, error) + Update(ctx context.Context, id int64, req *UpdateRequest) (*Cert, error) Delete(ctx context.Context, id int64) error } @@ -24,8 +25,16 @@ type Cert struct { } type CreateRequest struct { - Name string `json:"name"` - Cert string `json:"sslCertificate"` - PrivateKey string `json:"sslPrivateKey"` - Automated bool `json:"automated"` + Name string `json:"name"` + Cert string `json:"sslCertificate"` + PrivateKey string `json:"sslPrivateKey"` + Automated bool `json:"automated"` + ValidateRootCA bool `json:"validate_root_ca,omitempty"` +} + +type UpdateRequest struct { + Name string `json:"name,omitempty"` + Cert string `json:"sslCertificate,omitempty"` + PrivateKey string `json:"sslPrivateKey,omitempty"` + ValidateRootCA bool `json:"validate_root_ca,omitempty"` }