Skip to content

Commit fa02a0f

Browse files
authored
Merge pull request #1414 from jfrog/dev
2 parents 27631d8 + c43614b commit fa02a0f

File tree

11 files changed

+98
-22
lines changed

11 files changed

+98
-22
lines changed

artifactory/utils/search.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,18 @@ func SearchResultNoDate(reader *content.ContentReader) (contentReader *content.C
166166
return
167167
}
168168

169+
// SearchFiles performs a search operation using the provided spec files.
170+
// This is a wrapper around SearchFilesBySpecs for backward compatibility.
169171
func SearchFiles(servicesManager artifactory.ArtifactoryServicesManager, spec *spec.SpecFiles) (searchResults []*content.ContentReader, callbackFunc func() error, err error) {
172+
return SearchFilesBySpecs(servicesManager, spec.Files)
173+
}
174+
175+
// SearchFilesBySpecs performs a search operation using the provided file specifications.
176+
// It supports multiple source types including artifacts, packages, and release bundles.
177+
func SearchFilesBySpecs(servicesManager artifactory.ArtifactoryServicesManager, files []spec.File) (searchResults []*content.ContentReader, callbackFunc func() error, err error) {
178+
if len(files) == 0 {
179+
return nil, nil, errorutils.CheckErrorf("no files provided for search")
180+
}
170181
callbackFunc = func() error {
171182
var errs error
172183
for _, reader := range searchResults {
@@ -177,8 +188,8 @@ func SearchFiles(servicesManager artifactory.ArtifactoryServicesManager, spec *s
177188

178189
var curSearchParams services.SearchParams
179190
var curReader *content.ContentReader
180-
for i := 0; i < len(spec.Files); i++ {
181-
curSearchParams, err = GetSearchParams(spec.Get(i))
191+
for i := 0; i < len(files); i++ {
192+
curSearchParams, err = GetSearchParams(&files[i])
182193
if err != nil {
183194
return
184195
}

artifactory/utils/weblogin.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,25 @@ func DoWebLogin(serverDetails *config.ServerDetails) (token auth.CommonTokenPara
3535
return
3636
}
3737
log.Info("After logging in via your web browser, please enter the code if prompted: " + coreutils.PrintBoldTitle(uuidStr[len(uuidStr)-4:]))
38-
if err = browser.OpenURL(clientUtils.AddTrailingSlashIfNeeded(serverDetails.Url) + "ui/login?jfClientSession=" + uuidStr + "&jfClientName=JFrog-CLI&jfClientCode=1"); err != nil {
39-
return
38+
39+
loginUrl := clientUtils.AddTrailingSlashIfNeeded(serverDetails.Url) + "ui/login?jfClientSession=" + uuidStr + "&jfClientName=JFrog-CLI&jfClientCode=1"
40+
log.Info("Please open the following URL in your browser to authenticate:")
41+
log.Info(loginUrl)
42+
43+
// Attempt to open in browser if available
44+
if err = browser.OpenURL(loginUrl); err != nil {
45+
log.Warn("Failed to automatically open the browser. Please open the URL manually.")
46+
// Do not return, continue the flow
4047
}
48+
4149
time.Sleep(1 * time.Second)
4250
log.Debug("Attempting to get the authentication token...")
4351
token, err = accessManager.GetLoginAuthenticationToken(uuidStr)
4452
if err != nil {
4553
return
4654
}
4755
if token.AccessToken == "" {
48-
return token, errorutils.CheckErrorf("failed getting authentication token after web log")
56+
return token, errorutils.CheckErrorf("failed getting authentication token after web login")
4957
}
5058
log.Info("You're now logged in!")
5159
return

common/commands/config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,10 @@ func exchangeOidcTokenAndSetAccessToken(cc *ConfigCommand) error {
231231
SetProjectKey(cc.oidcSetupParams.ProjectKey).
232232
SetRepository(cc.oidcSetupParams.Repository).
233233
SetJobId(cc.oidcSetupParams.JobId).
234-
SetRunId(cc.oidcSetupParams.RunId)
234+
SetRunId(cc.oidcSetupParams.RunId).
235+
SetVcsRevision(cc.oidcSetupParams.VcsRevision).
236+
SetVcsBranch(cc.oidcSetupParams.VcsBranch).
237+
SetVcsUrl(cc.oidcSetupParams.VcsUrl)
235238

236239
// Usage report will be sent only after execution in order to have valid token
237240
err := ExecAndThenReportUsage(exchangeOidcTokenCmd)

common/spec/specfiles.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
clientutils "github.com/jfrog/jfrog-client-go/utils"
88
"github.com/jfrog/jfrog-client-go/utils/errorutils"
99
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
10+
"strings"
1011
)
1112

1213
type SpecFiles struct {
@@ -43,7 +44,10 @@ func CreateSpecFromBuildNameNumberAndProject(buildName, buildNumber, projectKey
4344
return nil, errorutils.CheckErrorf("build name and build number must be provided")
4445
}
4546

46-
buildString := buildName + "/" + buildNumber
47+
escapedBuildName := strings.ReplaceAll(buildName, "/", "\\/")
48+
escapedBuildNumber := strings.ReplaceAll(buildNumber, "/", "\\/")
49+
50+
buildString := escapedBuildName + "/" + escapedBuildNumber
4751
specFile := &SpecFiles{
4852
Files: []File{
4953
{
@@ -89,6 +93,10 @@ type File struct {
8993
Transitive string
9094
TargetPathInArchive string
9195
include []string
96+
Package string `json:"package,omitempty"`
97+
Version string `json:"version,omitempty"`
98+
Type string `json:"type,omitempty"`
99+
RepoKey string `json:"repoKey,omitempty"`
92100
}
93101

94102
func (f File) GetInclude() []string {
@@ -213,6 +221,11 @@ func ValidateSpec(files []File, isTargetMandatory, isSearchBasedSpec bool) error
213221
isExplode, _ := file.IsExplode(false)
214222
isBypassArchiveInspection, _ := file.IsBypassArchiveInspection(false)
215223
isTransitive, _ := file.IsTransitive(false)
224+
isPackage := len(file.Package) > 0
225+
isVersion := len(file.Version) > 0
226+
isType := len(file.Type) > 0
227+
isRepoKey := len(file.RepoKey) > 0
228+
216229
if isPathMapping {
217230
if !isAql {
218231
return errorutils.CheckErrorf("pathMapping is supported only with aql")
@@ -230,11 +243,9 @@ func ValidateSpec(files []File, isTargetMandatory, isSearchBasedSpec bool) error
230243
if !isSearchBasedSpec && !isPattern {
231244
return errorutils.CheckErrorf("spec must include a pattern")
232245
}
233-
if isBuild && isBundle {
234-
return fileSpecValidationError("build", "bundle")
235-
}
236-
if isSearchBasedSpec && !isAql && !isPattern && !isBuild && !isBundle {
237-
return errorutils.CheckErrorf("spec must include either aql, pattern, build or bundle")
246+
247+
if isSearchBasedSpec && !isAql && !isPattern && !isBuild && !isBundle && !isPackage {
248+
return errorutils.CheckErrorf("spec must include either aql, pattern, build, bundle or package")
238249
}
239250
if isOffset {
240251
if isBuild {
@@ -255,9 +266,6 @@ func ValidateSpec(files []File, isTargetMandatory, isSearchBasedSpec bool) error
255266
return fileSpecValidationError("bundle", "limit")
256267
}
257268
}
258-
if isAql && isPattern {
259-
return fileSpecValidationError("aql", "pattern")
260-
}
261269
if isAql && isExclusions {
262270
return fileSpecValidationError("aql", "exclusions")
263271
}
@@ -291,6 +299,11 @@ func ValidateSpec(files []File, isTargetMandatory, isSearchBasedSpec bool) error
291299
if isBypassArchiveInspection && !isExplode {
292300
return errorutils.CheckErrorf("spec cannot include 'bypass-archive-inspection' if 'explode' is not included")
293301
}
302+
if isPackage {
303+
if !isVersion || !isType || !isRepoKey {
304+
return errorutils.CheckErrorf("spec with type 'package' must include 'version', 'type' and 'repo_key'")
305+
}
306+
}
294307
}
295308
return nil
296309
}

common/spec/specfiles_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,13 @@ func TestCreateSpecFromBuildNameAndNumber(t *testing.T) {
4545
assert.Nil(t, spec)
4646
assert.EqualError(t, err, "build name and build number must be provided")
4747
})
48+
49+
t.Run("Build Name and Number with Slashes", func(t *testing.T) {
50+
spec, err := CreateSpecFromBuildNameNumberAndProject("my/build/name", "1/2/3", "test")
51+
52+
assert.NoError(t, err)
53+
assert.NotNil(t, spec)
54+
assert.Equal(t, "my\\/build\\/name/1\\/2\\/3", spec.Files[0].Build)
55+
assert.Equal(t, "test", spec.Files[0].Project)
56+
})
4857
}

general/token/oidctokenexchange.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package token
33
import (
44
"encoding/json"
55
"fmt"
6+
"os"
7+
"strings"
8+
69
rtUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
710
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
811
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
912
"github.com/jfrog/jfrog-client-go/access/services"
1013
"github.com/jfrog/jfrog-client-go/auth"
1114
"github.com/jfrog/jfrog-client-go/utils/log"
12-
"os"
13-
"strings"
1415
)
1516

1617
const (
@@ -73,6 +74,9 @@ type OidcParams struct {
7374
JobId string
7475
RunId string
7576
Repository string
77+
VcsUrl string
78+
VcsBranch string
79+
VcsRevision string
7680
}
7781

7882
type ExchangeCommandOutputStruct struct {
@@ -133,6 +137,21 @@ func (otc *OidcTokenExchangeCommand) SetRepository(repo string) *OidcTokenExchan
133137
return otc
134138
}
135139

140+
func (otc *OidcTokenExchangeCommand) SetVcsUrl(vcsUrl string) *OidcTokenExchangeCommand {
141+
otc.VcsUrl = vcsUrl
142+
return otc
143+
}
144+
145+
func (otc *OidcTokenExchangeCommand) SetVcsBranch(vcsBranch string) *OidcTokenExchangeCommand {
146+
otc.VcsBranch = vcsBranch
147+
return otc
148+
}
149+
150+
func (otc *OidcTokenExchangeCommand) SetVcsRevision(vcsRevision string) *OidcTokenExchangeCommand {
151+
otc.VcsRevision = vcsRevision
152+
return otc
153+
}
154+
136155
func (otc *OidcTokenExchangeCommand) Response() (response *auth.OidcTokenResponseData) {
137156
return otc.response
138157
}
@@ -192,5 +211,13 @@ func (otc *OidcTokenExchangeCommand) getOidcTokenParams() services.CreateOidcTok
192211
oidcTokenParams.Audience = otc.Audience
193212
oidcTokenParams.ProviderName = otc.ProviderName
194213
oidcTokenParams.ProviderType = otc.ProviderType.String()
214+
oidcTokenParams.Context = &services.Context{
215+
VcsCommit: &services.VcsCommit{
216+
VcsUrl: otc.VcsUrl,
217+
Branch: otc.VcsBranch,
218+
Revision: otc.VcsRevision,
219+
},
220+
}
221+
195222
return oidcTokenParams
196223
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ require (
114114
sigs.k8s.io/yaml v1.4.0 // indirect
115115
)
116116

117-
// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20250610112448-de5e55438dba
117+
replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20250629142537-bb24db402fe1
118118

119119
// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20250611113558-c1a092f216fd
120120

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ github.com/jfrog/build-info-go v1.10.14 h1:PWnw+rBwiQTHZ5q+84+E8MHFjtAQkB3+Oc2sK
113113
github.com/jfrog/build-info-go v1.10.14/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE=
114114
github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s=
115115
github.com/jfrog/gofrog v1.7.6/go.mod h1:ntr1txqNOZtHplmaNd7rS4f8jpA5Apx8em70oYEe7+4=
116-
github.com/jfrog/jfrog-client-go v1.54.1 h1:IvobRCmwFS/HDht6Vv1JtGzPPytmOX3qS57hRC5fU98=
117-
github.com/jfrog/jfrog-client-go v1.54.1/go.mod h1:1v0eih4thdPA4clBo9TuvAMT25sGDr1IQJ81DXQ/lBY=
116+
github.com/jfrog/jfrog-client-go v1.28.1-0.20250629142537-bb24db402fe1 h1:0t6dQHoalUDNVrfZujD3iCmDGLDl+ndHclFkmONSpq0=
117+
github.com/jfrog/jfrog-client-go v1.28.1-0.20250629142537-bb24db402fe1/go.mod h1:1v0eih4thdPA4clBo9TuvAMT25sGDr1IQJ81DXQ/lBY=
118118
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
119119
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
120120
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=

plugins/components/conversionlayer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func convertSubcommands(subcommands []Namespace, nameSpaces ...string) ([]cli.Co
4444
for _, ns := range subcommands {
4545
nameSpaceCommand := cli.Command{
4646
Name: ns.Name,
47+
Aliases: ns.Aliases,
4748
Usage: ns.Description,
4849
Hidden: ns.Hidden,
4950
Category: ns.Category,

plugins/components/structure.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func CreateEmbeddedApp(name string, commands []Command, namespaces ...Namespace)
3030

3131
type Namespace struct {
3232
Name string
33+
Aliases []string
3334
Description string
3435
Hidden bool
3536
Category string

0 commit comments

Comments
 (0)