Skip to content

Commit

Permalink
opt api client
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyuhang0 committed Dec 13, 2023
1 parent 7dc2656 commit 59fa4fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
2 changes: 0 additions & 2 deletions internal/flag/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ const (
View string = "view"
ViewShort string = "v"
SpendingLimitMonthly string = "spending-limit-monthly"
UpdateField string = "field"
UpdateValue string = "value"
ServerlessLabels string = "labels"
ServerlessAnnotations string = "annotations"
Monthly string = "monthly"
Expand Down
18 changes: 8 additions & 10 deletions internal/service/cloud/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ type ClientDelegate struct {
sc *serverlessClient.TidbcloudServerless
}

func NewClientDelegate(publicKey string, privateKey string, apiUrl string, serverlessApiUrl string) (*ClientDelegate, error) {
c, ic, cc, bc, sc, err := NewApiClient(publicKey, privateKey, apiUrl, serverlessApiUrl)
func NewClientDelegate(publicKey string, privateKey string, apiUrl string, serverlessEndpoint string) (*ClientDelegate, error) {
c, ic, cc, bc, sc, err := NewApiClient(publicKey, privateKey, apiUrl, serverlessEndpoint)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -196,7 +196,7 @@ func (d *ClientDelegate) DeleteBranch(params *branchOp.BranchServiceDeleteBranch
return r, err
}

func NewApiClient(publicKey string, privateKey string, apiUrl string, serverlessApiUrl string) (*apiClient.GoTidbcloud, *importClient.TidbcloudImport,
func NewApiClient(publicKey string, privateKey string, apiUrl string, serverlessEndpoint string) (*apiClient.GoTidbcloud, *importClient.TidbcloudImport,
*connectInfoClient.TidbcloudConnectInfo, *branchClient.TidbcloudServerless, *serverlessClient.TidbcloudServerless, error) {
httpclient := &http.Client{
Transport: NewTransportWithAgent(&digest.Transport{
Expand All @@ -212,18 +212,16 @@ func NewApiClient(publicKey string, privateKey string, apiUrl string, serverless
}
transport := httpTransport.NewWithClient(u.Host, u.Path, []string{u.Scheme}, httpclient)

// serverless api
serverlessUrl, err := prop.ValidateApiUrl(serverlessApiUrl)
// v1beta1 api
serverlessURL, err := prop.ValidateApiUrl(serverlessEndpoint)
if err != nil {
return nil, nil, nil, nil, nil, err
}
newTransport := httpTransport.NewWithClient(serverlessUrl.Host, serverlessClient.DefaultBasePath, []string{serverlessUrl.Scheme}, httpclient)

// v1beta1 branch
branchTransport := httpTransport.NewWithClient(serverlessUrl.Host, "", []string{serverlessUrl.Scheme}, httpclient)
serverlessTransport := httpTransport.NewWithClient(serverlessURL.Host, serverlessClient.DefaultBasePath, []string{serverlessURL.Scheme}, httpclient)
branchTransport := httpTransport.NewWithClient(serverlessURL.Host, branchClient.DefaultBasePath, []string{serverlessURL.Scheme}, httpclient)

return apiClient.New(transport, strfmt.Default), importClient.New(transport, strfmt.Default), connectInfoClient.New(transport, strfmt.Default),
branchClient.New(branchTransport, strfmt.Default), serverlessClient.New(newTransport, strfmt.Default), nil
branchClient.New(branchTransport, strfmt.Default), serverlessClient.New(serverlessTransport, strfmt.Default), nil
}

// NewTransportWithAgent returns a new http.RoundTripper that add the User-Agent header,
Expand Down

0 comments on commit 59fa4fb

Please sign in to comment.