Skip to content

Commit 08080a7

Browse files
karlpipmebel123
authored andcommitted
api version
Signed-off-by: Karl Piplies <[email protected]>
1 parent a3b99cb commit 08080a7

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,5 @@ func initConfig() {
8181
rootCmd.MarkPersistentFlagRequired("token")
8282
rootCmd.MarkPersistentFlagRequired("host")
8383
}
84+
conf.EnsureApiVerison()
8485
}

conf/config.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"github.com/jinzhu/configor"
1616
)
1717

18+
const DefaultApiVersion = "v1"
19+
1820
var Config = struct {
1921
ProjectToken string `default:""`
2022
ProjectUUID string `default:""`
@@ -50,6 +52,7 @@ func rightPad2Len(s string, padStr string, overallLen int) string {
5052
var retStr = s + strings.Repeat(padStr, padCountInt)
5153
return retStr[:overallLen]
5254
}
55+
5356
func dumpStructToSystemOut(parentTitle string, data interface{}) interface{} {
5457
if reflect.ValueOf(data).Kind() == reflect.Struct {
5558
v := reflect.ValueOf(data)
@@ -93,3 +96,15 @@ func getEnvVariable(envKey string, defaultValue string) string {
9396
}
9497
return defaultValue
9598
}
99+
100+
func EnsureApiVerison() {
101+
Config.Host = strings.TrimSuffix(Config.Host, "/")
102+
if strings.HasSuffix(Config.Host, "/public") {
103+
Config.Host += "/" + DefaultApiVersion
104+
return
105+
}
106+
if !strings.HasSuffix(Config.Host, "/"+DefaultApiVersion) {
107+
fmt.Println("WARNING: non-default api version set, unexpected behavior is possible")
108+
}
109+
110+
}

disclosure-cli

207 KB
Binary file not shown.

pkg/helper/endoints.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
func GetProjectAPIURL(appendix string) string {
1515
if len(conf.Config.ProjectUUID) > 0 {
16-
return conf.Config.Host + "/v1/projects/" + conf.Config.ProjectUUID + appendix
16+
return conf.Config.Host + "/projects/" + conf.Config.ProjectUUID + appendix
1717
} else {
1818
fmt.Println("Missing flag u - uuid of the project")
1919
os.Exit(1)
@@ -23,7 +23,7 @@ func GetProjectAPIURL(appendix string) string {
2323

2424
func GetProjectVersionAPIURL(versionName, appendix string) string {
2525
if len(versionName) > 0 {
26-
url := conf.Config.Host + "/v1/projects/" + conf.Config.ProjectUUID + "/versions/" + versionName
26+
url := conf.Config.Host + "/projects/" + conf.Config.ProjectUUID + "/versions/" + versionName
2727
if len(appendix) > 0 {
2828
url = url + "/" + appendix
2929
}

0 commit comments

Comments
 (0)