-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented a new API endpoint to check if a release bundle exists in…
… RBV2.
- Loading branch information
1 parent
d77d8c8
commit f7f636c
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package services | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/jfrog/jfrog-client-go/utils" | ||
"github.com/jfrog/jfrog-client-go/utils/distribution" | ||
"github.com/jfrog/jfrog-client-go/utils/errorutils" | ||
"github.com/jfrog/jfrog-client-go/utils/log" | ||
"net/http" | ||
"path" | ||
) | ||
|
||
const ( | ||
isExistInRbV2Endpoint = "api/v2/release_bundle/existence" | ||
) | ||
|
||
func (rbs *ReleaseBundlesService) IsExist(projectName, releaseBundleNameAndVersion string) (bool, error) { | ||
queryParams := distribution.GetProjectQueryParam(projectName) | ||
restApi := path.Join(isExistInRbV2Endpoint, releaseBundleNameAndVersion) | ||
requestFullUrl, err := utils.BuildUrl(rbs.GetLifecycleDetails().GetUrl(), restApi, queryParams) | ||
|
||
if err != nil { | ||
return false, err | ||
} | ||
|
||
httpClientDetails := rbs.GetLifecycleDetails().CreateHttpClientDetails() | ||
httpClientDetails.SetContentTypeApplicationJson() | ||
|
||
resp, body, _, err := rbs.client.SendGet(requestFullUrl, true, &httpClientDetails) | ||
if err != nil { | ||
return false, err | ||
} | ||
log.Debug("Artifactory response:", resp.Status) | ||
|
||
if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusAccepted, http.StatusOK); err != nil { | ||
return false, err | ||
} | ||
|
||
response := &isReleaseBundleExistResponse{} | ||
if err := json.Unmarshal(body, response); err != nil { | ||
return false, err | ||
} | ||
|
||
return response.Exists, nil | ||
} | ||
|
||
func GetIsExistReleaseBundleApi(releaseBundleNameAndVersion string) string { | ||
return path.Join(isExistInRbV2Endpoint, releaseBundleNameAndVersion) | ||
} | ||
|
||
type isReleaseBundleExistResponse struct { | ||
Exists bool `json:"exists"` | ||
} |