@@ -3,6 +3,9 @@ package cli
33import (
44 "errors"
55 "fmt"
6+ "os"
7+ "strings"
8+
69 "github.com/jfrog/jfrog-cli-artifactory/evidence/cli/docs/create"
710 "github.com/jfrog/jfrog-cli-artifactory/evidence/cli/docs/verify"
811 jfrogArtClient "github.com/jfrog/jfrog-cli-artifactory/evidence/utils"
@@ -15,8 +18,6 @@ import (
1518 "github.com/jfrog/jfrog-client-go/utils"
1619 "github.com/jfrog/jfrog-client-go/utils/errorutils"
1720 "golang.org/x/exp/slices"
18- "os"
19- "strings"
2021)
2122
2223func GetCommands () []components.Command {
@@ -118,6 +119,15 @@ func validateCreateEvidenceCommonContext(ctx *components.Context) error {
118119 return pluginsCommon .WrongNumberOfArgumentsHandler (ctx )
119120 }
120121
122+ // If sigstore-bundle is provided, validate conflicting parameters
123+ // We check both IsFlagSet and assertValueProvided to ensure the flag is both set and has a value
124+ if ctx .IsFlagSet (sigstoreBundle ) && assertValueProvided (ctx , sigstoreBundle ) == nil {
125+ if err := validateSigstoreBundleConflicts (ctx ); err != nil {
126+ return err
127+ }
128+ return nil
129+ }
130+
121131 if (! ctx .IsFlagSet (predicate ) || assertValueProvided (ctx , predicate ) != nil ) && ! ctx .IsFlagSet (typeFlag ) {
122132 return errorutils .CheckErrorf ("'predicate' is a mandatory field for creating evidence: --%s" , predicate )
123133 }
@@ -136,6 +146,34 @@ func validateCreateEvidenceCommonContext(ctx *components.Context) error {
136146 return nil
137147}
138148
149+ // validateSigstoreBundleConflicts checks if conflicting parameters are provided when using sigstore-bundle.
150+ // When --sigstore-bundle is used, the following parameters cannot be provided:
151+ // --key, --key-alias, --predicate, --predicate-type
152+ // Returns an error if any conflicting parameters are found.
153+ func validateSigstoreBundleConflicts (ctx * components.Context ) error {
154+ var conflictingParams []string
155+
156+ // Check each conflicting parameter
157+ if ctx .IsFlagSet (key ) && ctx .GetStringFlagValue (key ) != "" {
158+ conflictingParams = append (conflictingParams , "--key" )
159+ }
160+ if ctx .IsFlagSet (keyAlias ) && ctx .GetStringFlagValue (keyAlias ) != "" {
161+ conflictingParams = append (conflictingParams , "--key-alias" )
162+ }
163+ if ctx .IsFlagSet (predicate ) && ctx .GetStringFlagValue (predicate ) != "" {
164+ conflictingParams = append (conflictingParams , "--predicate" )
165+ }
166+ if ctx .IsFlagSet (predicateType ) && ctx .GetStringFlagValue (predicateType ) != "" {
167+ conflictingParams = append (conflictingParams , "--predicate-type" )
168+ }
169+
170+ if len (conflictingParams ) > 0 {
171+ return errorutils .CheckErrorf ("The following parameters cannot be used with --sigstore-bundle: %s. When using --sigstore-bundle, these values are extracted from the bundle itself." , strings .Join (conflictingParams , ", " ))
172+ }
173+
174+ return nil
175+ }
176+
139177func ensureKeyExists (ctx * components.Context , key string ) error {
140178 if ctx .IsFlagSet (key ) && assertValueProvided (ctx , key ) == nil {
141179 return nil
@@ -165,6 +203,10 @@ func getAndValidateSubject(ctx *components.Context) ([]string, error) {
165203 }
166204
167205 if len (foundSubjects ) == 0 {
206+ // If sigstore-bundle is provided, subject will be extracted from bundle
207+ if ctx .IsFlagSet (sigstoreBundle ) && assertValueProvided (ctx , sigstoreBundle ) == nil {
208+ return []string {subjectRepoPath }, nil // Return subjectRepoPath as the type for routing
209+ }
168210 // If we have no subject - we will try to create EVD on build
169211 if ! attemptSetBuildNameAndNumber (ctx ) {
170212 return nil , errorutils .CheckErrorf ("subject must be one of the fields: [%s]" , strings .Join (subjectTypes , ", " ))
0 commit comments