Skip to content

Commit

Permalink
[get/artifact] add command
Browse files Browse the repository at this point in the history
  • Loading branch information
maorfr committed Dec 26, 2018
1 parent 13effeb commit 5dcb021
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 9 deletions.
1 change: 1 addition & 0 deletions cmd/orca.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func NewGetCmd(out io.Writer) *cobra.Command {

cmd.AddCommand(orca.NewGetEnvCmd(out))
cmd.AddCommand(orca.NewGetResourceCmd(out))
cmd.AddCommand(orca.NewGetArtifactCmd(out))

return cmd
}
Expand Down
20 changes: 17 additions & 3 deletions docs/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,23 @@ Usage:
orca deploy artifact [flags]
Flags:
--file string path to file to deploy. Overrides $ORCA_FILE
--token string token to use for deployment. Overrides $ORCA_TOKEN
--url string url to deploy to. Overrides $ORCA_URL
--file string path of file to deploy. Overrides $ORCA_FILE
--token string artifactory token to use. Overrides $ORCA_TOKEN
--url string url of file to deploy. Overrides $ORCA_URL
```


### Get artifact
```
Get an artifact from Artifactory
Usage:
orca get artifact [flags]
Flags:
--file string path of file to write. Overrides $ORCA_FILE
--token string artifactory token to use. Overrides $ORCA_TOKEN
--url string url of file to get. Overrides $ORCA_URL
```

### Deploy chart
Expand Down
56 changes: 50 additions & 6 deletions pkg/orca/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package orca
import (
"errors"
"io"
"io/ioutil"
"log"
"os"

Expand All @@ -19,6 +20,49 @@ type artifactCmd struct {
out io.Writer
}

// NewGetArtifactCmd represents the get artifact command
func NewGetArtifactCmd(out io.Writer) *cobra.Command {
a := &artifactCmd{out: out}

cmd := &cobra.Command{
Use: "artifact",
Short: "Get an artifact from Artifactory",
Long: ``,
Args: func(cmd *cobra.Command, args []string) error {
if a.url == "" {
return errors.New("url of file to get has to be defined")
}
if a.token == "" {
return errors.New("artifactory token to use has to be defined")
}
if a.file == "" {
return errors.New("path of file to write has to be defined")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
artifact := utils.PerformRequest(utils.PerformRequestOptions{
Method: "GET",
URL: a.url,
Headers: []string{"X-JFrog-Art-Api:" + a.token},
ExpectedStatusCode: 200,
})
err := ioutil.WriteFile(a.file, artifact, 0644)
if err != nil {
log.Fatal(err)
}
},
}

f := cmd.Flags()

f.StringVar(&a.url, "url", os.Getenv("ORCA_URL"), "url of file to get. Overrides $ORCA_URL")
f.StringVar(&a.token, "token", os.Getenv("ORCA_TOKEN"), "artifactory token to use. Overrides $ORCA_TOKEN")
f.StringVar(&a.file, "file", os.Getenv("ORCA_FILE"), "path of file to write. Overrides $ORCA_FILE")

return cmd
}

// NewDeployArtifactCmd represents the deploy artifact command
func NewDeployArtifactCmd(out io.Writer) *cobra.Command {
a := &artifactCmd{out: out}
Expand All @@ -29,13 +73,13 @@ func NewDeployArtifactCmd(out io.Writer) *cobra.Command {
Long: ``,
Args: func(cmd *cobra.Command, args []string) error {
if a.url == "" {
return errors.New("url to deploy to has to be defined")
return errors.New("url of file to deploy has to be defined")
}
if a.token == "" {
return errors.New("token to use for deployment has to be defined")
return errors.New("artifactory token to use has to be defined")
}
if a.file == "" {
return errors.New("artifact to deploy has to be defined")
return errors.New("path of file to deploy has to be defined")
}
if _, err := os.Stat(a.file); err != nil {
return errors.New("artifact to deploy does not exist")
Expand All @@ -59,9 +103,9 @@ func NewDeployArtifactCmd(out io.Writer) *cobra.Command {

f := cmd.Flags()

f.StringVar(&a.url, "url", os.Getenv("ORCA_URL"), "url to deploy to. Overrides $ORCA_URL")
f.StringVar(&a.token, "token", os.Getenv("ORCA_TOKEN"), "token to use for deployment. Overrides $ORCA_TOKEN")
f.StringVar(&a.file, "file", os.Getenv("ORCA_FILE"), "path to file to deploy. Overrides $ORCA_FILE")
f.StringVar(&a.url, "url", os.Getenv("ORCA_URL"), "url of file to deploy. Overrides $ORCA_URL")
f.StringVar(&a.token, "token", os.Getenv("ORCA_TOKEN"), "artifactory token to use. Overrides $ORCA_TOKEN")
f.StringVar(&a.file, "file", os.Getenv("ORCA_FILE"), "path of file to deploy. Overrides $ORCA_FILE")

return cmd
}

0 comments on commit 5dcb021

Please sign in to comment.