Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrog-ecosystem committed Jun 24, 2024
2 parents ddfd958 + cdab7b3 commit c3e450d
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 147 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ After the build process completes, you will find the `jf` or `jf.exe` executable
This project heavily depends on the following modules:

- [github.com/jfrog/jfrog-client-go](https://github.com/jfrog/jfrog-client-go)
- [github.com/jfrog/jfrog-cli-core](github.com/jfrog/jfrog-cli-core)
- [github.com/jfrog/build-info-go](github.com/jfrog/build-info-go)
- [github.com/jfrog/gofrog](github.com/jfrog/gofrog)
- [github.com/jfrog/jfrog-cli-core](https://github.com/jfrog/jfrog-cli-core)
- [github.com/jfrog/build-info-go](https://github.com/jfrog/build-info-go)
- [github.com/jfrog/gofrog](https://github.com/jfrog/gofrog)

#### Local Development

Expand Down
65 changes: 30 additions & 35 deletions access_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package main

import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
coreEnvSetup "github.com/jfrog/jfrog-cli-core/v2/general/envsetup"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
coreTests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
"github.com/jfrog/jfrog-cli/utils/tests"
"github.com/jfrog/jfrog-client-go/access/services"
"github.com/jfrog/jfrog-client-go/auth"
"github.com/jfrog/jfrog-client-go/http/httpclient"
clientUtils "github.com/jfrog/jfrog-client-go/utils"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/io/httputils"
clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests"
"github.com/stretchr/testify/assert"
"net/http"
"testing"
Expand Down Expand Up @@ -74,40 +73,11 @@ func authenticateAccess() string {
return cred
}

func TestSetupInvitedUser(t *testing.T) {
initAccessTest(t)
tempDirPath, createTempDirCallback := coreTests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()
setEnvCallBack := clientTestUtils.SetEnvWithCallbackAndAssert(t, coreutils.HomeDir, tempDirPath)
defer setEnvCallBack()
setupServerDetails := &config.ServerDetails{Url: *tests.JfrogUrl, AccessToken: *tests.JfrogAccessToken}
encodedCred := encodeConnectionDetails(setupServerDetails, t)
setupCmd := coreEnvSetup.NewEnvSetupCommand().SetEncodedConnectionDetails(encodedCred)
suffix := setupCmd.SetupAndConfigServer()
assert.Empty(t, suffix)
configs, err := config.GetAllServersConfigs()
assert.NoError(t, err)
assert.Equal(t, 1, len(configs))
// Verify config values
assert.Equal(t, configs[0].Url, *tests.JfrogUrl)
assert.Equal(t, *tests.JfrogUrl+"artifactory/", configs[0].ArtifactoryUrl)
// Verify token was refreshed
assert.NotEqual(t, *tests.JfrogAccessToken, configs[0].AccessToken)
assert.NotEmpty(t, configs[0].RefreshToken)
}

func encodeConnectionDetails(serverDetails *config.ServerDetails, t *testing.T) string {
jsonConnectionDetails, err := json.Marshal(serverDetails)
assert.NoError(t, err)
encoded := base64.StdEncoding.EncodeToString(jsonConnectionDetails)
return encoded
}

func TestRefreshableAccessTokens(t *testing.T) {
initAccessTest(t)

server := &config.ServerDetails{Url: *tests.JfrogUrl, AccessToken: *tests.JfrogAccessToken}
err := coreEnvSetup.GenerateNewLongTermRefreshableAccessToken(server)
err := generateNewLongTermRefreshableAccessToken(server)
assert.NoError(t, err)
assert.NotEmpty(t, server.RefreshToken)
configCmd := commands.NewConfigCommand(commands.AddOrEdit, tests.ServerId).SetDetails(server).SetInteractive(false)
Expand Down Expand Up @@ -162,6 +132,32 @@ func TestRefreshableAccessTokens(t *testing.T) {
cleanArtifactoryTest()
}

// Take the short-lived token and generate a long term (1 year expiry) refreshable accessToken.
func generateNewLongTermRefreshableAccessToken(server *config.ServerDetails) (err error) {
accessManager, err := utils.CreateAccessServiceManager(server, false)
if err != nil {
return
}
// Create refreshable accessToken with 1 year expiry from the given short expiry token.
params := createLongExpirationRefreshableTokenParams()
token, err := accessManager.CreateAccessToken(*params)
if err != nil {
return
}
server.AccessToken = token.AccessToken
server.RefreshToken = token.RefreshToken
return
}

func createLongExpirationRefreshableTokenParams() *services.CreateTokenParams {
params := services.CreateTokenParams{}
// Using the platform's default expiration (1 year by default).
params.ExpiresIn = nil
params.Refreshable = clientUtils.Pointer(true)
params.Audience = "*@*"
return &params
}

// After refreshing an access token, assert that the access token and the refresh token were changed, and the Artifactory refresh token remained empty.
func assertAccessTokensChanged(t *testing.T, curAccessToken, curRefreshToken string) (newAccessToken, newRefreshToken string, err error) {
var newArtifactoryRefreshToken string
Expand All @@ -177,8 +173,7 @@ func assertAccessTokensChanged(t *testing.T, curAccessToken, curRefreshToken str
}

const (
userScope = "applied-permissions/user"
defaultExpiry = 31536000
userScope = "applied-permissions/user"
)

var atcTestCases = []struct {
Expand Down
2 changes: 1 addition & 1 deletion build/npm/v2-jf/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/npm/v2-jf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jfrog-cli-v2-jf",
"version": "2.58.2",
"version": "2.59.0",
"description": "🐸 Command-line interface for JFrog Artifactory, Xray, Distribution, Pipelines and Mission Control 🐸",
"homepage": "https://github.com/jfrog/jfrog-cli",
"preferGlobal": true,
Expand Down
2 changes: 1 addition & 1 deletion build/npm/v2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/npm/v2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jfrog-cli-v2",
"version": "2.58.2",
"version": "2.59.0",
"description": "🐸 Command-line interface for JFrog Artifactory, Xray, Distribution, Pipelines and Mission Control 🐸",
"homepage": "https://github.com/jfrog/jfrog-cli",
"preferGlobal": true,
Expand Down
10 changes: 6 additions & 4 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"github.com/docker/docker/api/types/mount"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -208,7 +209,7 @@ func TestPushFatManifestImage(t *testing.T) {
Privileged().
Networks(rtNetwork).
Name("buildx_container").
Mount(workspace, "/workspace", false).
Mount(mount.Mount{Type: mount.TypeBind, Source: workspace, Target: "/workspace", ReadOnly: false}).
Cmd("--insecure-registry", tests.RtContainerHostName).
// Docker daemon take times to load. In order to check if it's available we wait for a log message to indications that the Docker daemon has finished initializing.
WaitFor(wait.ForLog("API listen on /var/run/docker.sock").WithStartupTimeout(5*time.Minute)).
Expand Down Expand Up @@ -493,9 +494,10 @@ func runKaniko(t *testing.T, imageToPush string) string {
_, err = tests.NewContainerRequest().
Image(kanikoImage).
Networks(rtNetwork).
Mount(workspace, "/workspace", false).
Mount(credentialsFile, "/kaniko/.docker/config.json", true).
Cmd("--dockerfile="+dockerFile, "--destination="+imageToPush, "--insecure", "--skip-tls-verify", "--image-name-with-digest-file="+KanikoOutputFile).
Mount(
mount.Mount{Type: mount.TypeBind, Source: workspace, Target: "/workspace", ReadOnly: false},
mount.Mount{Type: mount.TypeBind, Source: credentialsFile, Target: "/kaniko/.docker/config.json", ReadOnly: true}).
Cmd("--dockerfile=/workspace/"+dockerFile, "--destination="+imageToPush, "--insecure", "--skip-tls-verify", "--image-name-with-digest-file="+KanikoOutputFile).
WaitFor(wait.ForExit().WithExitTimeout(300000*time.Millisecond)).
Build(context.Background(), true)
assert.NoError(t, err)
Expand Down
7 changes: 4 additions & 3 deletions docs/common/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,17 @@ const (
JfrogCliMinChecksumDeploySizeKb = ` JFROG_CLI_MIN_CHECKSUM_DEPLOY_SIZE_KB
[Default: 10]
Minimum file size in KB for which JFrog CLI performs checksum deploy optimization.
Support with upload command`
Supported by the upload command`

JfrogCliFailNoOp = ` JFROG_CLI_FAIL_NO_OP
[Default: false]
Set to true if you'd like the command to return exit code 2 in case of no files are affected.
Support by the following commands: copy, delete, delete-props, set-props, download, move, search and upload`

JfrogCliUploadEmptyArchive = ` ` + services.JfrogCliUploadEmptyArchiveEnv + `
JfrogCliUploadEmptyArchive = ` ` + services.JfrogCliUploadEmptyArchiveEnv + `
[Default: false]
Set to true if you'd like to upload an empty archive when '--archive' is set but all files were excluded by exclusions pattern. `
Set to true if you'd like to upload an empty archive when '--archive' is set but all files were excluded by exclusions pattern.
Supported by the upload command`

JfrogCliEncryptionKey = ` JFROG_CLI_ENCRYPTION_KEY
If provided, encrypt the sensitive data stored in the config with the provided key. Must be exactly 32 characters.`
Expand Down
32 changes: 0 additions & 32 deletions general/envsetup/envsetup.go

This file was deleted.

32 changes: 21 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,29 @@ module github.com/jfrog/jfrog-cli

go 1.22.3

// Should not be updated to 0.2.6 due to a bug (https://github.com/jfrog/jfrog-cli-core/pull/372)
replace github.com/c-bata/go-prompt => github.com/c-bata/go-prompt v0.2.5
replace (
// Should not be updated to 0.2.6 due to a bug (https://github.com/jfrog/jfrog-cli-core/pull/372)
github.com/c-bata/go-prompt => github.com/c-bata/go-prompt v0.2.5

// Should not be updated to 0.2.0-beta.2 due to a bug (https://github.com/jfrog/jfrog-cli-core/pull/372)
replace github.com/pkg/term => github.com/pkg/term v1.1.0
// Should not be updated to 0.2.0-beta.2 due to a bug (https://github.com/jfrog/jfrog-cli-core/pull/372)
github.com/pkg/term => github.com/pkg/term v1.1.0
)

require (
github.com/agnivade/levenshtein v1.1.1
github.com/agnivade/levenshtein v1.0.1
github.com/buger/jsonparser v1.1.1
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1
github.com/docker/docker v25.0.5+incompatible
github.com/gocarina/gocsv v0.0.0-20231116093920-b87c2d0e983a
github.com/jfrog/archiver/v3 v3.6.0
github.com/jfrog/build-info-go v1.9.29
github.com/jfrog/gofrog v1.7.2
github.com/jfrog/gofrog v1.7.3
github.com/jfrog/jfrog-cli-core/v2 v2.53.1
github.com/jfrog/jfrog-cli-platform-services v1.3.0
github.com/jfrog/jfrog-cli-security v1.3.0
github.com/jfrog/jfrog-cli-security v1.4.0
github.com/jfrog/jfrog-client-go v1.41.0
github.com/jszwec/csvutil v1.10.0
github.com/stretchr/testify v1.9.0
github.com/testcontainers/testcontainers-go v0.23.0
github.com/testcontainers/testcontainers-go v0.31.0
github.com/urfave/cli v1.22.15
github.com/xeipuuv/gojsonschema v1.2.0
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8
Expand Down Expand Up @@ -50,7 +53,6 @@ require (
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.5+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dsnet/compress v0.0.2-0.20230904184137-39efe44ab707 // indirect
Expand All @@ -63,6 +65,7 @@ require (
github.com/go-git/go-git/v5 v5.12.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -78,6 +81,7 @@ require (
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -102,11 +106,14 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/term v1.2.0-beta.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
Expand All @@ -115,13 +122,16 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/ulikunitz/xz v0.5.12 // indirect
github.com/vbauerster/mpb/v7 v7.5.3 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
Expand All @@ -143,7 +153,7 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/eyalbe4/jfrog-cli-core/v2 v2.53.1-0.20240603040428-a33e0e7a9a03
// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240620112945-9428cc3373ab

// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240530101935-539b5837ce04

Expand Down
Loading

0 comments on commit c3e450d

Please sign in to comment.