Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): Adding cloud resources #3841

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 46 additions & 9 deletions cli/cmd/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,48 @@ var (
resourcemanager.WithResourceType("PollingProfile"),
)

envTokensClient = resourcemanager.NewClient(
httpClient, cliLogger,
"token", "tokens",
resourcemanager.WithTableConfig(resourcemanager.TableConfig{
Cells: []resourcemanager.TableCellConfig{
{Header: "ID", Path: "spec.id"},
{Header: "NAME", Path: "spec.name"},
{Header: "ROLE", Path: "spec.role"},
{Header: "ISSUED AT", Path: "spec.issuedAt"},
{Header: "EXPIRES AT", Path: "spec.expiresAt"},
},
}),
resourcemanager.WithResourceType("EnvironmentToken"),
)

orgInvitesClient = resourcemanager.NewClient(
httpClient, cliLogger,
"organizationinvite", "organizationinvites",
resourcemanager.WithTableConfig(resourcemanager.TableConfig{
Cells: []resourcemanager.TableCellConfig{
{Header: "ID", Path: "spec.id"},
{Header: "TO", Path: "spec.to"},
{Header: "Role", Path: "spec.role"},
{Header: "TYPE", Path: "spec.type"},
{Header: "STATUS", Path: "spec.status"},
},
}),
resourcemanager.WithResourceType("Invite"),
)

environmentClient = resourcemanager.NewClient(
httpClient, cliLogger,
"environment", "environments",
resourcemanager.WithTableConfig(resourcemanager.TableConfig{
Cells: []resourcemanager.TableCellConfig{
{Header: "ID", Path: "spec.id"},
{Header: "NAME", Path: "spec.name"},
},
}),
resourcemanager.WithResourceType("Environment"),
)

testPreprocessor = preprocessor.Test(cliLogger, func(ctx context.Context, input fileutil.File) (fileutil.File, error) {
updated, err := pollingProfileClient.Apply(ctx, input, resourcemanager.Formats.Get(resourcemanager.FormatYAML))
if err != nil {
Expand Down Expand Up @@ -138,13 +180,6 @@ var (
resourcemanager.WithDeprecatedAlias("Transaction"),
)

// deprecated resources
deprecatedEnvironmentClient = resourcemanager.NewClient(
httpClient, cliLogger,
"environment", "environments",
resourcemanager.WithProxyResource("variableset"),
)

deprecatedTransactionsClient = resourcemanager.NewClient(
httpClient, cliLogger,
"transaction", "transactions",
Expand Down Expand Up @@ -185,6 +220,8 @@ var (
}),
),
).
Register(envTokensClient).
Register(orgInvitesClient).
Register(pollingProfileClient).
Register(
resourcemanager.NewClient(
Expand Down Expand Up @@ -250,9 +287,9 @@ var (
Register(testClient).
Register(organizationsClient).
Register(environmentClient).
Register(environmentMeClient).

// deprecated resources
Register(deprecatedEnvironmentClient).
Register(deprecatedTransactionsClient)

organizationsClient = resourcemanager.NewClient(
Expand All @@ -267,7 +304,7 @@ var (
resourcemanager.WithListPath("elements"),
)

environmentClient = resourcemanager.NewClient(
environmentMeClient = resourcemanager.NewClient(
httpClient, cliLogger,
"env", "environments",
resourcemanager.WithTableConfig(resourcemanager.TableConfig{
Expand Down
7 changes: 7 additions & 0 deletions cli/config/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,13 @@ func SetupHttpClient(cfg Config) *resourcemanager.HTTPClient {
extraHeaders.Set("x-environment-id", cfg.EnvironmentID)
extraHeaders.Set("Authorization", fmt.Sprintf("Bearer %s", cfg.Jwt))

if cfg.OrganizationID == "" {
extraHeaders.Set("x-organization-id", "default")
}
if cfg.EnvironmentID == "" {
extraHeaders.Set("x-environment-id", "default")
}

return resourcemanager.NewHTTPClient(fmt.Sprintf("%s%s", cfg.URL(), cfg.Path()), extraHeaders)
}

Expand Down
27 changes: 0 additions & 27 deletions testing/cli-e2etest/testscenarios/test/run_test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,6 @@ func TestRunTestWithHttpTriggerAndVariableSetFile(t *testing.T) {
require.Equal("https://assets.pokemon.com/assets/cms2/img/pokedex/full/143.png", environmentVars.Spec.Values[1].Value)
})

t.Run("should pass when using the deprecated environment definition file", func(t *testing.T) {
result := tracetestcli.Exec(t, "get environment --id deprecated-pokeapi-env", tracetestcli.WithCLIConfig(cliConfig))
helpers.RequireExitCodeEqual(t, result, 0)
require.Contains(result.StdOut, "The resource `environment` is deprecated and will be removed in a future version. Please use `variableset` instead.")
require.Contains(result.StdOut, "Resource variableset with ID deprecated-pokeapi-env not found")

// When I try to run a test with a http trigger and a variable set file
// Then it should pass
environmentFile := env.GetTestResourcePath(t, "deprecated-environment")
testFile := env.GetTestResourcePath(t, "http-trigger-with-environment-file")

command := fmt.Sprintf("run test -f %s --environment %s", testFile, environmentFile)
result = tracetestcli.Exec(t, command, tracetestcli.WithCLIConfig(cliConfig))
helpers.RequireExitCodeEqual(t, result, 0)
require.Contains(result.StdOut, "✔ It should add a Pokemon correctly")
require.Contains(result.StdOut, "✔ It should save the correct data")

// When I try to get the variable set created on the previous step
// Then it should retrieve it correctly
result = tracetestcli.Exec(t, "get environment --id deprecated-pokeapi-env", tracetestcli.WithCLIConfig(cliConfig))
helpers.RequireExitCodeEqual(t, result, 0)

require.Contains(result.StdOut, "The resource `environment` is deprecated and will be removed in a future version. Please use `variableset` instead.")
require.Contains(result.StdOut, "VariableSet")
require.Contains(result.StdOut, "https://assets.pokemon.com/assets/cms2/img/pokedex/full/143.png")
})

t.Run("should pass when using variable set id", func(t *testing.T) {
// Given I am a Tracetest CLI user
// And I have my server recently created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,4 @@ func TestApplyVariableSet(t *testing.T) {
require.Equal("THIRD_VAR", updatedEnvironmentVars.Spec.Values[2].Key)
require.Equal("hello", updatedEnvironmentVars.Spec.Values[2].Value) // this value was added
})

t.Run("using the deprecated environment command to apply a variable set", func(t *testing.T) {
newEnvironmentPath := env.GetTestResourcePath(t, "deprecated-environment")

result := tracetestcli.Exec(t, fmt.Sprintf("apply environment --file %s", newEnvironmentPath), tracetestcli.WithCLIConfig(cliConfig))
helpers.RequireExitCodeEqual(t, result, 0)

require.Contains(result.StdOut, "The resource `environment` is deprecated and will be removed in a future version. Please use `variableset` instead.")
require.Contains(result.StdOut, "VariableSet")
require.Contains(result.StdOut, "deprecated-env")
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,4 @@ func TestGetVariableSet(t *testing.T) {
require.Equal(".env", singleLine["NAME"])
require.Equal("", singleLine["DESCRIPTION"])
})

t.Run("getting a variable set using the deprecated environment command", func(t *testing.T) {
result := tracetestcli.Exec(t, "get environment --id .env", tracetestcli.WithCLIConfig(cliConfig))

helpers.RequireExitCodeEqual(t, result, 0)
require.Contains(result.StdOut, "The resource `environment` is deprecated and will be removed in a future version. Please use `variableset` instead.")
require.Contains(result.StdOut, "VariableSet")
require.Contains(result.StdOut, ".env")
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,4 @@ func TestListVariableSets(t *testing.T) {
require.Equal("The", oneMoreEnvironmentVars.Spec.Values[1].Key)
require.Equal("Third", oneMoreEnvironmentVars.Spec.Values[1].Value)
})

t.Run("list using deprecated environment command", func(t *testing.T) {
result := tracetestcli.Exec(t, "list environment --sortBy name --sortDirection asc --skip 1 --take 2 --output yaml", tracetestcli.WithCLIConfig(cliConfig))

helpers.RequireExitCodeEqual(t, result, 0)
require.Contains(result.StdOut, "The resource `environment` is deprecated and will be removed in a future version. Please use `variableset` instead.")
require.Contains(result.StdOut, "VariableSet")
})
}

This file was deleted.

Loading