refactor: clean code
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
package certcenter
|
||||
|
||||
import (
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/request"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/response"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/volcengineutil"
|
||||
)
|
||||
|
||||
const opImportCertificateCommon = "ImportCertificate"
|
||||
|
||||
func (c *CertCenter) ImportCertificateCommonRequest(input *map[string]interface{}) (req *request.Request, output *map[string]interface{}) {
|
||||
op := &request.Operation{
|
||||
Name: opImportCertificateCommon,
|
||||
HTTPMethod: "POST",
|
||||
HTTPPath: "/",
|
||||
}
|
||||
|
||||
if input == nil {
|
||||
input = &map[string]interface{}{}
|
||||
}
|
||||
|
||||
output = &map[string]interface{}{}
|
||||
req = c.newRequest(op, input, output)
|
||||
|
||||
req.HTTPRequest.Header.Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *CertCenter) ImportCertificateCommon(input *map[string]interface{}) (*map[string]interface{}, error) {
|
||||
req, out := c.ImportCertificateCommonRequest(input)
|
||||
return out, req.Send()
|
||||
}
|
||||
|
||||
func (c *CertCenter) ImportCertificateCommonWithContext(ctx volcengine.Context, input *map[string]interface{}, opts ...request.Option) (*map[string]interface{}, error) {
|
||||
req, out := c.ImportCertificateCommonRequest(input)
|
||||
req.SetContext(ctx)
|
||||
req.ApplyOptions(opts...)
|
||||
return out, req.Send()
|
||||
}
|
||||
|
||||
const opImportCertificate = "ImportCertificate"
|
||||
|
||||
func (c *CertCenter) ImportCertificateRequest(input *ImportCertificateInput) (req *request.Request, output *ImportCertificateOutput) {
|
||||
op := &request.Operation{
|
||||
Name: opImportCertificate,
|
||||
HTTPMethod: "POST",
|
||||
HTTPPath: "/",
|
||||
}
|
||||
|
||||
if input == nil {
|
||||
input = &ImportCertificateInput{}
|
||||
}
|
||||
|
||||
output = &ImportCertificateOutput{}
|
||||
req = c.newRequest(op, input, output)
|
||||
|
||||
req.HTTPRequest.Header.Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *CertCenter) ImportCertificate(input *ImportCertificateInput) (*ImportCertificateOutput, error) {
|
||||
req, out := c.ImportCertificateRequest(input)
|
||||
return out, req.Send()
|
||||
}
|
||||
|
||||
func (c *CertCenter) ImportCertificateWithContext(ctx volcengine.Context, input *ImportCertificateInput, opts ...request.Option) (*ImportCertificateOutput, error) {
|
||||
req, out := c.ImportCertificateRequest(input)
|
||||
req.SetContext(ctx)
|
||||
req.ApplyOptions(opts...)
|
||||
return out, req.Send()
|
||||
}
|
||||
|
||||
type ImportCertificateInput struct {
|
||||
_ struct{} `type:"structure" json:",omitempty"`
|
||||
|
||||
Tag *string `type:"string" json:",omitempty"`
|
||||
|
||||
ProjectName *string `type:"string" json:",omitempty"`
|
||||
|
||||
Repeatable *bool `type:"boolean" json:",omitempty"`
|
||||
|
||||
NoVerifyAndFixChain *bool `type:"boolean" json:",omitempty"`
|
||||
|
||||
CertificateInfo *ImportCertificateInputCertificateInfo `type:"structure" json:",omitempty"`
|
||||
|
||||
Tags *[]ImportCertificateInputTag `type:"list" json:",omitempty"`
|
||||
}
|
||||
|
||||
func (s ImportCertificateInput) String() string {
|
||||
return volcengineutil.Prettify(s)
|
||||
}
|
||||
|
||||
func (s *ImportCertificateInput) Validate() error {
|
||||
invalidParams := request.ErrInvalidParams{Context: "ImportCertificateInput"}
|
||||
|
||||
if invalidParams.Len() > 0 {
|
||||
return invalidParams
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ImportCertificateInputCertificateInfo struct {
|
||||
CertificateChain *string `type:"string" json:",omitempty"`
|
||||
|
||||
PrivateKey *string `type:"string" json:",omitempty"`
|
||||
}
|
||||
|
||||
type ImportCertificateInputTag struct {
|
||||
Key *string `type:"string" json:",omitempty" required:"true"`
|
||||
|
||||
Value *string `type:"string" json:",omitempty" required:"true"`
|
||||
}
|
||||
|
||||
type ImportCertificateOutput struct {
|
||||
_ struct{} `type:"structure" json:",omitempty"`
|
||||
|
||||
Metadata *response.ResponseMetadata
|
||||
|
||||
InstanceId *string `type:"string" json:",omitempty"`
|
||||
|
||||
RepeatId *string `type:"string" json:",omitempty"`
|
||||
}
|
||||
|
||||
func (s ImportCertificateOutput) String() string {
|
||||
return volcengineutil.Prettify(s)
|
||||
}
|
||||
14
internal/pkg/sdk3rd/volcengine/certcenter/interface.go
Normal file
14
internal/pkg/sdk3rd/volcengine/certcenter/interface.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package certcenter
|
||||
|
||||
import (
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/request"
|
||||
)
|
||||
|
||||
type CertCenterAPI interface {
|
||||
ImportCertificate(*ImportCertificateInput) (*ImportCertificateOutput, error)
|
||||
ImportCertificateWithContext(volcengine.Context, *ImportCertificateInput, ...request.Option) (*ImportCertificateOutput, error)
|
||||
ImportCertificateRequest(*ImportCertificateInput) (*request.Request, *ImportCertificateOutput)
|
||||
}
|
||||
|
||||
var _ CertCenterAPI = (*CertCenter)(nil)
|
||||
71
internal/pkg/sdk3rd/volcengine/certcenter/service.go
Normal file
71
internal/pkg/sdk3rd/volcengine/certcenter/service.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package certcenter
|
||||
|
||||
import (
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/client"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/client/metadata"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/corehandlers"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/request"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/signer/volc"
|
||||
"github.com/volcengine/volcengine-go-sdk/volcengine/volcenginequery"
|
||||
)
|
||||
|
||||
type CertCenter struct {
|
||||
*client.Client
|
||||
}
|
||||
|
||||
var initClient func(*client.Client)
|
||||
|
||||
var initRequest func(*request.Request)
|
||||
|
||||
const (
|
||||
ServiceName = "certificate_service"
|
||||
EndpointsID = ServiceName
|
||||
ServiceID = "certificate_service"
|
||||
)
|
||||
|
||||
func New(p client.ConfigProvider, cfgs ...*volcengine.Config) *CertCenter {
|
||||
c := p.ClientConfig(EndpointsID, cfgs...)
|
||||
return newClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion, c.SigningName)
|
||||
}
|
||||
|
||||
func newClient(cfg volcengine.Config, handlers request.Handlers, endpoint, signingRegion, signingName string) *CertCenter {
|
||||
svc := &CertCenter{
|
||||
Client: client.New(
|
||||
cfg,
|
||||
metadata.ClientInfo{
|
||||
ServiceName: ServiceName,
|
||||
ServiceID: ServiceID,
|
||||
SigningName: signingName,
|
||||
SigningRegion: signingRegion,
|
||||
Endpoint: endpoint,
|
||||
APIVersion: "2024-10-01",
|
||||
},
|
||||
handlers,
|
||||
),
|
||||
}
|
||||
|
||||
svc.Handlers.Build.PushBackNamed(corehandlers.SDKVersionUserAgentHandler)
|
||||
svc.Handlers.Build.PushBackNamed(corehandlers.AddHostExecEnvUserAgentHandler)
|
||||
svc.Handlers.Sign.PushBackNamed(volc.SignRequestHandler)
|
||||
svc.Handlers.Build.PushBackNamed(volcenginequery.BuildHandler)
|
||||
svc.Handlers.Unmarshal.PushBackNamed(volcenginequery.UnmarshalHandler)
|
||||
svc.Handlers.UnmarshalMeta.PushBackNamed(volcenginequery.UnmarshalMetaHandler)
|
||||
svc.Handlers.UnmarshalError.PushBackNamed(volcenginequery.UnmarshalErrorHandler)
|
||||
|
||||
if initClient != nil {
|
||||
initClient(svc.Client)
|
||||
}
|
||||
|
||||
return svc
|
||||
}
|
||||
|
||||
func (c *CertCenter) newRequest(op *request.Operation, params, data interface{}) *request.Request {
|
||||
req := c.NewRequest(op, params, data)
|
||||
|
||||
if initRequest != nil {
|
||||
initRequest(req)
|
||||
}
|
||||
|
||||
return req
|
||||
}
|
||||
Reference in New Issue
Block a user