Skip to content

Commit 229ebca

Browse files
committed
add authorization header to migrate api call
1 parent 3ec9a41 commit 229ebca

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

pkg/api/api.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package api
33
import (
44
"encoding/json"
55
"errors"
6+
"fmt"
67
"io/ioutil"
78
"net/http"
89
"net/url"
@@ -66,7 +67,7 @@ func GetZones() (config.Region, error) {
6667
arvanConfig := config.GetConfigInfo()
6768
arvanURL, err := url.Parse(arvanConfig.GetServer())
6869
if err != nil {
69-
return regions, nil
70+
return regions, fmt.Errorf("invalid config")
7071
}
7172

7273
httpReq, err := http.NewRequest("GET", arvanURL.Scheme + "://" + arvanURL.Host+regionsEndpoint, nil)

pkg/paas/migration.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"strconv"
1313
"strings"
14+
"net/url"
1415

1516
"github.com/arvancloud/cli/pkg/api"
1617
"github.com/arvancloud/cli/pkg/config"
@@ -23,7 +24,7 @@ import (
2324
)
2425

2526
const (
26-
migrationEndpoint = "/paas/v1/migrations"
27+
migrationEndpoint = "/paas/v1/migrate"
2728
redColor = "\033[31m"
2829
greenColor = "\033[32m"
2930
yellowColor = "\033[33m"
@@ -95,10 +96,13 @@ func NewCmdMigrate(in io.Reader, out, errout io.Writer) *cobra.Command {
9596
requset := Request{
9697
Namespace: project,
9798
Source: currentRegionName,
98-
Destination: destinationRegion.RegionName,
99+
Destination: fmt.Sprintf("%s-%s", destinationRegion.RegionName, destinationRegion.Name),
99100
}
100101

101-
migrate(requset)
102+
err = migrate(requset)
103+
if err != nil {
104+
log.Println(err)
105+
}
102106
},
103107
}
104108

@@ -233,11 +237,21 @@ func httpPost(endpoint string, payload interface{}) (*Response, error) {
233237
if err != nil {
234238
return nil, err
235239
}
240+
arvanConfig := config.GetConfigInfo()
241+
arvanURL, err := url.Parse(arvanConfig.GetServer())
242+
if err != nil {
243+
return nil, fmt.Errorf("invalid config")
244+
}
236245

237-
httpReq, err := http.NewRequest(http.MethodPost, getArvanPaasServerBase()+endpoint, bytes.NewBuffer(requestBody))
246+
httpReq, err := http.NewRequest(http.MethodPost, arvanURL.Scheme + "://" + arvanURL.Host+endpoint, bytes.NewBuffer(requestBody))
238247
if err != nil {
239248
return nil, err
240249
}
250+
apikey := arvanConfig.GetApiKey()
251+
if apikey != "" {
252+
httpReq.Header.Add("Authorization", apikey)
253+
}
254+
241255
httpReq.Header.Add("accept", "application/json")
242256
httpReq.Header.Add("User-Agent", rest.DefaultKubernetesUserAgent())
243257
httpResp, err := http.DefaultClient.Do(httpReq)

0 commit comments

Comments
 (0)