-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(worker): add workflow command add run result (#5805)
- Loading branch information
Showing
28 changed files
with
458 additions
and
78 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 was deleted.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
...artifactory/plugin-artifactory-download-artifact/plugin-artifactory-download-artifact.yml
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: artifactory-download-artifact-plugin | ||
type: integration-download_artifact | ||
integration: Artifactory | ||
integration: ArtifactManager | ||
author: "OVH SAS" | ||
description: "OVH Artifactory Download Artifact Plugin" |
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
2 changes: 1 addition & 1 deletion
2
...ons/artifactory/plugin-artifactory-upload-artifact/plugin-artifactory-upload-artifact.yml
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: artifactory-upload-artifact-plugin | ||
type: integration-upload_artifact | ||
integration: Artifactory | ||
integration: ArtifactManager | ||
author: "OVH SAS" | ||
description: "OVH Artifactory Upload Artifact Plugin" |
76 changes: 76 additions & 0 deletions
76
engine/api/integration/artifact_manager/artifactory/client.go
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,76 @@ | ||
package artifactory | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/jfrog/jfrog-client-go/artifactory" | ||
"github.com/jfrog/jfrog-client-go/artifactory/services" | ||
"github.com/ovh/cds/sdk" | ||
) | ||
|
||
type FileInfoResponse struct { | ||
Checksums *FileInfoChecksum `json:"checksums"` | ||
Created time.Time `json:"created"` | ||
CreatedBy string `json:"createdBy"` | ||
DownloadURI string `json:"downloadUri"` | ||
LastModified time.Time `json:"lastModified"` | ||
LastUpdated time.Time `json:"lastUpdated"` | ||
MimeType string `json:"mimeType"` | ||
ModifiedBy string `json:"modifiedBy"` | ||
OriginalChecksums *FileInfoChecksum `json:"originalChecksums"` | ||
Path string `json:"path"` | ||
RemoteURL string `json:"remoteUrl"` | ||
Repo string `json:"repo"` | ||
Size string `json:"size"` | ||
URI string `json:"uri"` | ||
} | ||
|
||
type FileInfoChecksum struct { | ||
Md5 string `json:"md5"` | ||
Sha1 string `json:"sha1"` | ||
Sha256 string `json:"sha256"` | ||
} | ||
|
||
type Client struct { | ||
Asm artifactory.ArtifactoryServicesManager | ||
} | ||
|
||
func (c *Client) GetFileInfo(repoName string, filePath string) (sdk.FileInfo, error) { | ||
fi := sdk.FileInfo{} | ||
repoDetails := services.RepositoryDetails{} | ||
if err := c.Asm.GetRepository(repoName, &repoDetails); err != nil { | ||
return fi, sdk.NewErrorFrom(sdk.ErrUnknownError, "unable to get repository %s: %v", repoName, err) | ||
} | ||
fi.Type = repoDetails.PackageType | ||
|
||
fileInfoURL := fmt.Sprintf("%sapi/storage/%s/%s", c.Asm.GetConfig().GetServiceDetails().GetUrl(), repoName, filePath) | ||
httpDetails := c.Asm.GetConfig().GetServiceDetails().CreateHttpClientDetails() | ||
re, body, _, err := c.Asm.Client().SendGet(fileInfoURL, true, &httpDetails) | ||
if err != nil { | ||
return fi, sdk.NewErrorFrom(sdk.ErrUnknownError, "unable to call artifactory: %v", err) | ||
} | ||
|
||
if re.StatusCode >= 400 { | ||
return fi, sdk.NewErrorFrom(sdk.ErrUnknownError, "unable to call artifactory [HTTP: %d] %s", re.StatusCode, string(body)) | ||
} | ||
|
||
var resp FileInfoResponse | ||
if err := json.Unmarshal(body, &resp); err != nil { | ||
return fi, sdk.NewErrorFrom(sdk.ErrUnknownError, "unable to read artifactory response %s: %v", string(body), err) | ||
} | ||
|
||
if resp.Size != "" { | ||
s, err := strconv.ParseInt(resp.Size, 10, 64) | ||
if err != nil { | ||
return fi, sdk.NewErrorFrom(sdk.ErrInvalidData, "size return by artifactory is not an integer %s: %v", resp.Size, err) | ||
} | ||
fi.Size = s | ||
} | ||
if resp.Checksums != nil { | ||
fi.Md5 = resp.Checksums.Md5 | ||
} | ||
return fi, nil | ||
} |
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,46 @@ | ||
package artifact_manager | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/jfrog/jfrog-client-go/artifactory" | ||
"github.com/jfrog/jfrog-client-go/artifactory/auth" | ||
"github.com/jfrog/jfrog-client-go/config" | ||
|
||
"github.com/jfrog/jfrog-client-go/utils/log" | ||
arti "github.com/ovh/cds/engine/api/integration/artifact_manager/artifactory" | ||
"github.com/ovh/cds/sdk" | ||
) | ||
|
||
type ArtifactManager interface { | ||
GetFileInfo(repoName string, filePath string) (sdk.FileInfo, error) | ||
} | ||
|
||
func NewClient(managerType, url, token string) (ArtifactManager, error) { | ||
switch managerType { | ||
case "artifactory": | ||
return newArtifactoryClient(url, token) | ||
} | ||
return nil, fmt.Errorf("artifact Manager %s not implemented", managerType) | ||
} | ||
|
||
func newArtifactoryClient(url string, token string) (ArtifactManager, error) { | ||
log.SetLogger(log.NewLogger(log.INFO, os.Stdout)) | ||
rtDetails := auth.NewArtifactoryDetails() | ||
rtDetails.SetUrl(url) | ||
rtDetails.SetAccessToken(token) | ||
serviceConfig, err := config.NewConfigBuilder(). | ||
SetServiceDetails(rtDetails). | ||
SetThreads(1). | ||
SetDryRun(false). | ||
Build() | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to create service config: %v", err) | ||
} | ||
asm, err := artifactory.New(serviceConfig) | ||
if err != nil { | ||
return nil, sdk.WrapError(err, "unable to create artifactory client") | ||
} | ||
return &arti.Client{Asm: asm}, nil | ||
} |
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
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
Oops, something went wrong.