Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customized api #13

Merged
merged 6 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions appetize/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
"github.com/bitrise-io/go-utils/log"
)

const apiEndPoint = "@api.appetize.io/v1/apps"

// Client ...
type Client struct {
token string
Expand Down Expand Up @@ -48,8 +46,8 @@ type Response struct {
// -- Public methods

// NewClient ...
func NewClient(token string, appPath string, artifact Artifact, publicKey string) *Client {
baseURL := baseURL(token, appPath, publicKey)
func NewClient(token string, appPath string, artifact Artifact, publicKey string, apiEndPoint string) *Client {
baseURL := baseURL(token, appPath, publicKey, apiEndPoint)
return &Client{
token: token,
baseURL: baseURL,
Expand Down Expand Up @@ -165,7 +163,7 @@ func (client *Client) performRequest(req *http.Request, requestResponse interfac
return body, nil
}

func baseURL(token, appPath, publicKey string) string {
func baseURL(token, appPath, publicKey string, apiEndPoint string) string {
baseURL := token + apiEndPoint

if publicKey != "" {
Expand Down
35 changes: 19 additions & 16 deletions appetize/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,33 @@ import "testing"

func Test_baseURL(t *testing.T) {
tests := []struct {
name string
token string
appPath string
publicKey string
want string
name string
token string
appPath string
publicKey string
apiEndPoint string
want string
}{
{
name: "test_1",
token: "token_abcdefg",
appPath: "./apps/XcodeArchiveTest.app.zip",
publicKey: "",
want: "https://token_abcdefg@api.appetize.io/v1/apps",
name: "test_1",
token: "token_abcdefg",
appPath: "./apps/XcodeArchiveTest.app.zip",
publicKey: "",
apiEndPoint: "@api.appetize.io/v1/apps",
want: "https://token_abcdefg@api.appetize.io/v1/apps",
},
{
name: "test_2",
token: "token_abcdefg",
appPath: "./apps/XcodeArchiveTest.app.zip",
publicKey: "pubkey",
want: "https://token_abcdefg@api.appetize.io/v1/apps/pubkey",
name: "test_2",
token: "token_abcdefg",
appPath: "./apps/XcodeArchiveTest.app.zip",
publicKey: "pubkey",
apiEndPoint: "@api.appetize.io/v1/apps",
want: "https://token_abcdefg@api.appetize.io/v1/apps/pubkey",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := baseURL(tt.token, tt.appPath, tt.publicKey); got != tt.want {
if got := baseURL(tt.token, tt.appPath, tt.publicKey, tt.apiEndPoint); got != tt.want {
t.Errorf("baseURL() = %v, want %v", got, tt.want)
}
})
Expand Down
18 changes: 10 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ var debugMode bool

// Config ...
type Config struct {
AppPath string `env:"app_path,required"`
Token stepconf.Secret `env:"appetize_token,required"`
PublicKey string `env:"public_key"`
Verbose bool `env:"verbose,required"`
AppPath string `env:"app_path,required"`
Token stepconf.Secret `env:"appetize_token,required"`
PublicKey string `env:"public_key"`
AppetizeApi string `env:"appetize_api"`
AppetizeHost string `env:"appetize_host"`
Verbose bool `env:"verbose,required"`
}

func main() {
Expand Down Expand Up @@ -57,7 +59,7 @@ func main() {
log.Infof("Upload")

// Network section
client := appetize.NewClient(string(cfg.Token), pth, artifact, cfg.PublicKey)
client := appetize.NewClient(string(cfg.Token), pth, artifact, cfg.PublicKey, cfg.AppetizeApi)

if cfg.PublicKey == "" {
log.Warnf("🚨 No public key provided")
Expand All @@ -77,7 +79,7 @@ func main() {

logDebugPretty(&response)

appURL := generateAppURL(response.PublicKey)
appURL := generateAppURL(response.PublicKey, cfg.AppetizeHost)

log.Printf("You can check your app at: %s", appURL)
fmt.Println()
Expand All @@ -97,10 +99,10 @@ func main() {
// -------------------------------------
// -- Private methods

func generateAppURL(publicKey string) string {
func generateAppURL(publicKey string, host string) string {
u := url.URL{
Scheme: "https",
Host: "appetize.io",
Host: host,
Path: path.Join("app", publicKey),
}
return u.String()
Expand Down
6 changes: 5 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,31 @@ func Test_generateAppURL(t *testing.T) {
tests := []struct {
name string
publicKey string
host string
want string
}{
{
name: "test_1",
publicKey: "u2c556dxrxjfjzy",
host: "appetize.io",
want: "https://appetize.io/app/u2c556dxrxjfjzy",
},
{
name: "test_2",
publicKey: "h0xgpvb1tvr",
host: "appetize.io",
want: "https://appetize.io/app/h0xgpvb1tvr",
},
{
name: "test_3",
publicKey: "lkwo92okosss",
host: "appetize.io",
want: "https://appetize.io/app/lkwo92okosss",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := generateAppURL(tt.publicKey); got != tt.want {
if got := generateAppURL(tt.publicKey, tt.host); got != tt.want {
t.Errorf("generateAppURL() = %v, want %v", got, tt.want)
}
})
Expand Down
12 changes: 12 additions & 0 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ inputs:
summary: The public key in case you want to deploy this build to an existing app
description: The public key in case you want to deploy this build to an existing app
is_required: false
- appetize_api: "@api.appetize.io/v1/apps"
opts:
title: Appetize.io api endpoint
summary: Allows for customized Appetize.io api endpoints, default is @api.appetize.io/v1/apps
description: Allows for customized Appetize.io api endpoints, default is @api.appetize.io/v1/apps
is_required: true
- appetize_host: appetize.io
opts:
title: Appetize.io host
summary: Allows for customized Appetize.io hosts, default is appetize.io
description: Allows for customized Appetize.io hosts, default is appetize.io
is_required: true
- verbose: "false"
opts:
title: Enable verbose logging
Expand Down
5 changes: 4 additions & 1 deletion vendor/github.com/bitrise-io/go-utils/pathutil/pathutil.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.