Skip to content

Commit

Permalink
chore: ORDPR-4191
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahcpage committed Jul 16, 2022
1 parent e805f75 commit 69c75d6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 21 deletions.
3 changes: 2 additions & 1 deletion cmd/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ var certificatesCmd = &cobra.Command{
Aliases: []string{"certs", "cer"},
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// Cadence is not a factor in certs, so we hard-code allowUnsuppd to false for the last argument.
ar := assetreqs.New(token, "certificates", args[0], "", "",
assetFilePath, assetFileName, outFormat)
assetFilePath, assetFileName, outFormat, false)
err := ar.GetAsset()
if err != nil {
log.Fatalln(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/deploymentassets.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var deploymentAssetsCmd = &cobra.Command{
if len(args) == 3 {
cver = args[2]
}
ar := assetreqs.New(token, "deploymentAssets", args[0], args[1], cver, assetFilePath, assetFileName, outFormat)
ar := assetreqs.New(token, "deploymentAssets", args[0], args[1], cver, assetFilePath, assetFileName, outFormat, allowUnsuppd)
err := ar.GetAsset()
if err != nil {
log.Fatalln(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var licenseCmd = &cobra.Command{
Aliases: []string{"lic"},
Args: cobra.ExactArgs(3),
Run: func(cmd *cobra.Command, args []string) {
ar := assetreqs.New(token, "license", args[0], args[1], args[2], assetFilePath, assetFileName, outFormat)
ar := assetreqs.New(token, "license", args[0], args[1], args[2], assetFilePath, assetFileName, outFormat, allowUnsuppd)
err := ar.GetAsset()
if err != nil {
log.Fatalln(err)
Expand Down
11 changes: 10 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
cfgFile string
outFormat string
token string
allowUnsuppd bool
)

// Version is set by the build.
Expand All @@ -45,6 +46,7 @@ func init() {
// Authentication is required for all commands.
cobra.OnInitialize(initConfig, auth)

// Define global flags / options and set their default values.
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "",
"config file (default is $HOME/.viya4-orders-cli)")
rootCmd.PersistentFlags().StringVarP(&assetFileName, "file-name", "n", "",
Expand All @@ -57,6 +59,11 @@ func init() {
"output format - valid values:\n"+
"\tj, json\n\tt, text\n")

// Create and hide a flag to allow retrieval of assets at cadences that are no longer in support.
rootCmd.PersistentFlags().BoolVarP(&allowUnsuppd, "allowUnsupported", "u", false, "")
aus := rootCmd.PersistentFlags().Lookup("allowUnsupported")
aus.Hidden = true

// Disable completion command (provided by Cobra by default starting with v1.30)
rootCmd.CompletionOptions.DisableDefaultCmd = true
}
Expand Down Expand Up @@ -126,11 +133,13 @@ func setOptions() {
}
}

outFormat := viper.GetString("output")
outFormat = viper.GetString("output")
// Validate output flag value.
if outFormat != "text" && outFormat != "t" && outFormat != "json" && outFormat != "j" {
usageError("invalid value " + outFormat + " specified for -o, --output option!")
}

allowUnsuppd = viper.GetBool("allowUnsupported")
}

// usageError prints the given error followed by the tool usage text, and then exits.
Expand Down
44 changes: 27 additions & 17 deletions lib/assetreqs/assetreqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,30 @@ const (

// AssetReq provides fields that define the parameters of an order asset request.
type AssetReq struct {
token string
aName string
oNum string
cName string
cVer string
fPath string
fName string
oFmt string
token string
aName string
oNum string
cName string
cVer string
fPath string
fName string
oFmt string
allowUnsuppd bool
}

// New initializes an AssetReq struct.
func New(token string, assetName string, orderNum string, cadenceName string, cadenceVer string, filePath string,
fileName string, outputFormat string) (ar AssetReq) {
fileName string, outputFormat string, allowUnsuppd bool) (ar AssetReq) {
return AssetReq{
token: token,
aName: assetName,
oNum: orderNum,
cName: cadenceName,
cVer: cadenceVer,
fPath: filePath,
fName: fileName,
oFmt: outputFormat,
token: token,
aName: assetName,
oNum: orderNum,
cName: cadenceName,
cVer: cadenceVer,
fPath: filePath,
fName: fileName,
oFmt: outputFormat,
allowUnsuppd: allowUnsuppd,
}
}

Expand Down Expand Up @@ -169,6 +171,14 @@ func (ar AssetReq) buildReq() (req *http.Request, err error) {
}
req.Header.Set("Authorization", bearer)

// If the allowUnsupported option was used, pass along allowUnsupported=true as a query param on the API call.
if ar.allowUnsuppd {
q := req.URL.Query()
q.Add("allowUnsupported", "true")
req.URL.RawQuery = q.Encode()
output.AssetReqURL += "?allowUnsupported=true"
}

return req, nil
}

Expand Down

0 comments on commit 69c75d6

Please sign in to comment.