()
| 23 | ) |
| 24 | |
| 25 | func newCASBackendAddOCICmd() *cobra.Command { |
| 26 | var repo, username, password string |
| 27 | cmd := &cobra.Command{ |
| 28 | Use: "oci", |
| 29 | Short: "Register a OCI CAS Backend", |
| 30 | PreRunE: func(_ *cobra.Command, _ []string) error { |
| 31 | return parseMaxBytesOption() |
| 32 | }, |
| 33 | RunE: func(cmd *cobra.Command, args []string) error { |
| 34 | // If we are setting the default, we list existing CAS backends |
| 35 | // and ask the user to confirm the rewrite |
| 36 | isDefault, err := cmd.Flags().GetBool("default") |
| 37 | cobra.CheckErr(err) |
| 38 | |
| 39 | isFallback, err := cmd.Flags().GetBool("fallback") |
| 40 | cobra.CheckErr(err) |
| 41 | |
| 42 | name, err := cmd.Flags().GetString("name") |
| 43 | cobra.CheckErr(err) |
| 44 | |
| 45 | description, err := cmd.Flags().GetString("description") |
| 46 | cobra.CheckErr(err) |
| 47 | |
| 48 | if isDefault { |
| 49 | if confirmed, err := confirmDefaultCASBackendOverride(ActionOpts, ""); err != nil { |
| 50 | return err |
| 51 | } else if !confirmed { |
| 52 | log.Info("Aborting...") |
| 53 | return nil |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | opts := &action.NewCASBackendAddOpts{ |
| 58 | Name: name, |
| 59 | Location: repo, Description: description, |
| 60 | Provider: "OCI", |
| 61 | Credentials: map[string]any{ |
| 62 | "username": username, |
| 63 | "password": password, |
| 64 | }, |
| 65 | Default: isDefault, |
| 66 | Fallback: isFallback, |
| 67 | MaxBytes: parsedMaxBytes, |
| 68 | } |
| 69 | |
| 70 | res, err := action.NewCASBackendAdd(ActionOpts).Run(opts) |
| 71 | if err != nil { |
| 72 | return err |
| 73 | } else if res == nil { |
| 74 | return nil |
| 75 | } |
| 76 | |
| 77 | return output.EncodeOutput(flagOutputFormat, res, casBackendItemTableOutput) |
| 78 | }, |
| 79 | } |
| 80 | |
| 81 | cmd.Flags().StringVar(&repo, "repo", "", "FQDN repository name, including path") |
| 82 | err := cmd.MarkFlagRequired("repo") |
no test coverage detected