Skip to content

Commit b05f2a5

Browse files
committed
Added create version command
1 parent e12acaa commit b05f2a5

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

application/http/http_client.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package http
22

33
import (
44
"encoding/json"
5+
"fmt"
56
commonCliConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
67
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
78
"github.com/jfrog/jfrog-client-go/auth"
@@ -13,6 +14,8 @@ import (
1314
"net/http"
1415
)
1516

17+
const applicationApiPath = "application/api"
18+
1619
type AppHttpClient interface {
1720
GetHttpClient() *jfroghttpclient.JfrogHttpClient
1821
Post(path string, requestBody interface{}) (resp *http.Response, body []byte, err error)
@@ -76,21 +79,35 @@ func (c *appHttpClient) GetHttpClient() *jfroghttpclient.JfrogHttpClient {
7679
}
7780

7881
func (c *appHttpClient) Post(path string, requestBody interface{}) (resp *http.Response, body []byte, err error) {
79-
url, err := utils.BuildUrl(c.serverDetails.Url, path, nil)
82+
url, err := utils.BuildUrl(c.serverDetails.Url, applicationApiPath+path, nil)
8083
if err != nil {
8184
return nil, nil, err
8285
}
8386

84-
var requestContent []byte
85-
if requestBody != nil {
86-
requestContent, err = json.Marshal(requestBody)
87-
if err != nil {
88-
return nil, nil, errorutils.CheckError(err)
89-
}
87+
requestContent, err := c.toJsonBytes(requestBody)
88+
if err != nil {
89+
return nil, nil, err
9090
}
9191

92+
println("url: ", url)
93+
return c.client.SendPost(url, requestContent, c.getJsonHttpClientDetails())
94+
}
95+
96+
func (c *appHttpClient) toJsonBytes(payload interface{}) ([]byte, error) {
97+
if payload == nil {
98+
return nil, fmt.Errorf("request payload is required")
99+
}
100+
101+
jsonBytes, err := json.Marshal(payload)
102+
if err != nil {
103+
return nil, errorutils.CheckError(err)
104+
}
105+
return jsonBytes, nil
106+
}
107+
108+
func (c *appHttpClient) getJsonHttpClientDetails() *httputils.HttpClientDetails {
92109
var httpClientDetails httputils.HttpClientDetails
93110
httpClientDetails = c.authDetails.CreateHttpClientDetails()
94111
httpClientDetails.SetContentTypeApplicationJson()
95-
return c.client.SendPost(url, requestContent, &httpClientDetails)
112+
return &httpClientDetails
96113
}

application/service/version_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (vs *versionService) CreateAppVersion(ctx *Context, request *model.CreateAp
2323
return err
2424
}
2525

26-
response, _, err := httpClient.Post("application/version", request)
26+
response, _, err := httpClient.Post("/v1/version", request)
2727
if err != nil {
2828
return err
2929
}

0 commit comments

Comments
 (0)