diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..ce9c782 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,55 @@ +env: + - GO111MODULE=on + - CGO_ENABLED=1 +before: + hooks: + - go mod tidy + # You may remove this if you don't use go modules. + - go mod download + # you may remove this if you don't need go generate + #- go generate ./... +builds: + - env: + - CGO_ENABLED=1 + - GO111MODULE=on + - CC=o64-clang + - CXX=o64-clang++ + main: ./main.go + binary: platformer + goos: + - linux + - windows + - darwin + goarch: + - amd64 + ignore: + - goos: darwin + goarch: 386 +archives: + - format: tar.gz + format_overrides: + - goos: windows + format: zip + name_template: '{{.ProjectName}}_{{.Version}}_{{.Os}}-{{.Arch}}' + - replacements: + darwin: Darwin + linux: Linux + windows: Windows + 386: i386 + amd64: x86_64 + files: + - README.md + - LICENSE +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: '{{ .Tag }}-next' +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + - 'README' + - Merge pull request + - Merge branch diff --git a/cmd/login.go b/cmd/login.go index 5f3e4b7..11ba62a 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -104,7 +104,6 @@ func startServerAndAwaitToken(server *http.Server, tokenChan chan<- string, errc }) c := cors.New(cors.Options{ - // @TODO: add production/staging URLs AllowedMethods: []string{http.MethodPost, http.MethodOptions, http.MethodConnect}, AllowedOrigins: []string{"http://localhost:3000", "https://console.dev.x.platformer.com", "http://localhost:9999", "https://beta.console.platformer.com"}, AllowedHeaders: []string{"*"}, diff --git a/go.sum b/go.sum index 39d60b4..bc657ec 100644 --- a/go.sum +++ b/go.sum @@ -115,8 +115,6 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9 github.com/pelletier/go-toml v1.7.0 h1:7utD74fnzVc/cpcyy8sjrlFr5vYpypUixARcHIMIGuI= github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/platformer-com/platformer-cli v0.0.0-20200814035411-fb69fc54e438 h1:1T5djV+WXR3oEWpHD1y9YnRbF3ZlvYJRhB56iGrPOoc= -github.com/platformer-com/platformer-cli v0.0.0-20200814035411-fb69fc54e438/go.mod h1:DwHEBKdnzQviZ+EThJKC1XsAcgv0wCVMmpd7z+YPrY4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= diff --git a/internal/auth/status.go b/internal/auth/status.go index 95d3955..1917a23 100644 --- a/internal/auth/status.go +++ b/internal/auth/status.go @@ -24,6 +24,7 @@ func IsLoggedIn() bool { config.RemoveToken() return false } + if resp.StatusCode != 200 { config.RemoveToken() return false diff --git a/internal/auth/token.go b/internal/auth/token.go index 8fde07f..ce92a56 100644 --- a/internal/auth/token.go +++ b/internal/auth/token.go @@ -20,9 +20,8 @@ func FetchPermanentToken(token string) (string, error) { Description string `json:"description"` ExpiredIn *string `json:"expired_in"` }{ - // @todo - add proper values here - "test-service account", - "", + "cli-service account", + "Getting token for CLI use", nil, }) diff --git a/internal/config/config.go b/internal/config/config.go index 4b532e4..6c4df53 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -14,6 +14,8 @@ func SaveToken(token string) { // RemoveToken removes the locally saved token func RemoveToken() { + viper.Set("context.organization", "") + viper.Set("context.project", "") viper.Set("auth.token", "") _ = viper.WriteConfig() } diff --git a/internal/mizzen/connect_cluster.go b/internal/mizzen/connect_cluster.go index a609561..71784f7 100644 --- a/internal/mizzen/connect_cluster.go +++ b/internal/mizzen/connect_cluster.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "github.com/platformercloud/platformer-cli/internal/config" "github.com/platformercloud/platformer-cli/internal/util" "io/ioutil" "net/http" @@ -48,18 +49,25 @@ func register(orgID string, projectID string, clusterName string) (*credentials, ClusterName string `json:"cluster_name"` ProjectID string `json:"project_id"` OrganizationID string `json:"organization_id"` + ClusterType string `json:"cluster_type"` WhitelistIPs []string `json:"whitelist_ips"` }{ clusterName, projectID, orgID, + "private", []string{}, // Whitelist IPs are not set using the CLI }) client := &http.Client{ Timeout: time.Second * 30, } - r, err := client.Post(util.MizzenClusterRegistrationURL, "application/json", &body) + + req, _ := http.NewRequest("POST", util.MizzenClusterRegistrationURL, &body) + req.Header.Add("Authorization", config.GetToken()) + + r, err := client.Do(req) + if err != nil { return nil, fmt.Errorf("api request failed (register cluster): %w", err) }