()
| 38 | ) |
| 39 | |
| 40 | func newAttestationCmd() *cobra.Command { |
| 41 | cmd := &cobra.Command{ |
| 42 | Use: "attestation", |
| 43 | Aliases: []string{"att"}, |
| 44 | Short: "Craft Software Supply Chain Attestations", |
| 45 | Example: "Refer to https://docs.chainloop.dev/getting-started/attestation-crafting", |
| 46 | PersistentPreRunE: func(cmd *cobra.Command, args []string) error { |
| 47 | // For non-init attestation subcommands using local state, load the org |
| 48 | // from the crafting state so the gRPC connection uses the correct org header. |
| 49 | // This handles the case where `init --org X` was used but subsequent commands |
| 50 | // would otherwise fall back to the default org from the config file. |
| 51 | if orgFlag := cmd.Root().PersistentFlags().Lookup(confOptions.organization.flagName); cmd.Name() != "init" && !useAttestationRemoteState && (orgFlag == nil || !orgFlag.Changed) { |
| 52 | if org := orgFromLocalState(attestationLocalStatePath); org != "" { |
| 53 | viper.Set(confOptions.organization.viperKey, org) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // run the initialization of the root command plus the new logic |
| 58 | // specific to this attestation command |
| 59 | rootCmd := cmd.Parent().Parent() |
| 60 | if err := rootCmd.PersistentPreRunE(cmd, args); err != nil { |
| 61 | return err |
| 62 | } |
| 63 | |
| 64 | // If the subcommand has the attestation-id flag, |
| 65 | // we need to make sure that it's set if the remote-state flag is enabled |
| 66 | if useAttestationRemoteState && cmd.Flags().Lookup("attestation-id") != nil { |
| 67 | return cmd.MarkFlagRequired("attestation-id") |
| 68 | } |
| 69 | |
| 70 | return nil |
| 71 | }, |
| 72 | } |
| 73 | |
| 74 | cmd.PersistentFlags().Bool("remote-state", false, "Store the attestation state remotely (preview feature)") |
| 75 | // We do not need this flag in all the attestation subcommands just in init, but we don't want to remove it to not to break current integrations |
| 76 | cobra.CheckErr(cmd.PersistentFlags().MarkHidden("remote-state")) |
| 77 | |
| 78 | cmd.PersistentFlags().BoolVar(&GracefulExit, "graceful-exit", false, "exit 0 in case of error. NOTE: this flag will be removed once Chainloop reaches 1.0") |
| 79 | cmd.PersistentFlags().StringVar(&attestationLocalStatePath, "local-state-path", "", "path to store the attestation state locally, default: [tmpDir]/chainloop_attestation.tmp.json") |
| 80 | |
| 81 | cmd.AddCommand(newAttestationInitCmd(), newAttestationAddCmd(), newAttestationStatusCmd(), newAttestationPushCmd(), |
| 82 | newAttestationResetCmd(), newAttestationVerifyCmd()) |
| 83 | |
| 84 | return cmd |
| 85 | } |
| 86 | |
| 87 | func flagAttestationID(cmd *cobra.Command) { |
| 88 | cmd.Flags().StringVar(&attestationID, "attestation-id", "", "Unique identifier of the in-progress attestation") |
no test coverage detected