()
| 23 | ) |
| 24 | |
| 25 | func newArtifactUploadCmd() *cobra.Command { |
| 26 | var filePath string |
| 27 | var artifactCASConn *grpc.ClientConn |
| 28 | |
| 29 | cmd := &cobra.Command{ |
| 30 | Use: "upload", |
| 31 | Short: "upload an artifact", |
| 32 | PreRunE: func(cmd *cobra.Command, args []string) error { |
| 33 | var err error |
| 34 | |
| 35 | // Retrieve temporary credentials for uploading |
| 36 | artifactCASConn, err = wrappedArtifactConn(ActionOpts.CPConnection, pb.CASCredentialsServiceGetRequest_ROLE_UPLOADER, "") |
| 37 | if err != nil { |
| 38 | return err |
| 39 | } |
| 40 | |
| 41 | return nil |
| 42 | }, |
| 43 | RunE: func(cmd *cobra.Command, args []string) error { |
| 44 | opts := &action.ArtifactUploadOpts{ |
| 45 | ActionsOpts: ActionOpts, |
| 46 | ArtifactsCASConn: artifactCASConn, |
| 47 | } |
| 48 | |
| 49 | _, err := action.NewArtifactUpload(opts).Run(filePath) |
| 50 | return err |
| 51 | }, |
| 52 | PostRunE: func(cmd *cobra.Command, args []string) error { |
| 53 | if artifactCASConn != nil { |
| 54 | return artifactCASConn.Close() |
| 55 | } |
| 56 | |
| 57 | return nil |
| 58 | }, |
| 59 | } |
| 60 | |
| 61 | cmd.Flags().StringVarP(&filePath, "file", "f", "", "path to file to upload") |
| 62 | err := cmd.MarkFlagRequired("file") |
| 63 | cobra.CheckErr(err) |
| 64 | |
| 65 | return cmd |
| 66 | } |
no test coverage detected