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

CLI-140: integration tests on ci #263

Merged
merged 34 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
eda57a2
chore: initial try at workflow change
as-herzog Apr 23, 2021
c057136
chore: add env vars
as-herzog Apr 23, 2021
0b33221
chore: remove path
as-herzog Apr 23, 2021
a8b99b8
chore: add mocks
as-herzog Apr 23, 2021
5b04287
chore: try build before integration
as-herzog Apr 26, 2021
5267a1d
chore: revert
as-herzog Apr 26, 2021
5452a69
chore: build all platforms
as-herzog Apr 26, 2021
6ce685e
test: fix
as-herzog Apr 26, 2021
46c0731
test: run with verbose
as-herzog Apr 26, 2021
8d9d409
Merge branch 'main' into cli-140-integration-on-ci
as-herzog Apr 26, 2021
16384bd
test: skipped
as-herzog Apr 26, 2021
54b319c
Merge branch 'main' into cli-140-integration-on-ci
Widcket Apr 27, 2021
7736d2d
test: remove verbose
as-herzog Apr 30, 2021
e6b3aa2
chore: Merge branch 'cli-140-integration-on-ci' of github.com:auth0/a…
as-herzog Apr 30, 2021
946d02a
test: echo path
as-herzog Apr 30, 2021
ca0c543
test: add verbose flag back
as-herzog Apr 30, 2021
c2e8fbb
test: build before integration
as-herzog May 3, 2021
4ca5642
test: try bash
as-herzog May 3, 2021
977317d
test: switch order
as-herzog May 3, 2021
1e4a362
test: remove redundant build
as-herzog May 3, 2021
2dcb9f2
test: add to path
as-herzog May 3, 2021
1621e67
Merge branch 'main' into cli-140-integration-on-ci
as-herzog May 3, 2021
70a768b
fix: config generator include scopes
jfatta May 7, 2021
5e0632e
Merge branch 'main' into cli-140-integration-on-ci
jfatta May 7, 2021
46b13a0
fix makefile
jfatta May 7, 2021
74697e1
fix: config gen tenant name
jfatta May 7, 2021
268c5a9
fix: config generated token
jfatta May 7, 2021
0c5e51b
test: remove verbose
as-herzog May 7, 2021
b76d343
test: failure
as-herzog May 7, 2021
a650818
fix: revert fialure
as-herzog May 7, 2021
cac083a
test: cleanup even with failure
as-herzog May 7, 2021
f2f54ba
test: use bash
as-herzog May 7, 2021
c2400f1
test: cleanup
as-herzog May 7, 2021
c55da52
fix: test
as-herzog May 7, 2021
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
12 changes: 12 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ jobs:

- name: ci
run: PATH=$(go env GOPATH)/bin:$PATH make ci

- name: integration
# skip running this action if the PR is coming from a fork:
if: github.event.pull_request.head.repo.full_name == github.repository
run: PATH=$(go env GOPATH)/bin:$PATH make integration
env:
AUTH0_CLI_CLIENT_NAME: ${{ secrets.AUTH0_CLI_CLIENT_NAME }}
AUTH0_CLI_CLIENT_DOMAIN: ${{ secrets.AUTH0_CLI_CLIENT_DOMAIN }}
AUTH0_CLI_CLIENT_ID: ${{ secrets.AUTH0_CLI_CLIENT_ID }}
AUTH0_CLI_CLIENT_SECRET: ${{ secrets.AUTH0_CLI_CLIENT_SECRET }}
AUTH0_CLI_REUSE_CONFIG: ${{ secrets.AUTH0_CLI_REUSE_CONFIG }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we need AUTH0_CLI_REUSE_CONFIG on the secrets. It should be always false on CI if understood the code correctly; there's no config file to reuse here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if we tweak the CLI codebase to look for all those ENV vars and skip the config file completely if the vars are present?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, we don't want to support client id/secret auth mechanism on the code base. In any case, it could look for an ENV var with the access token and skip config file, but that has nothing to do with this PR.

AUTH0_CLI_OVERWRITE: ${{ secrets.AUTH0_CLI_OVERWRITE }}
10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ lint:

# Build for the native platform
build:
go build -ldflags "$(CTIMEVAR)" -o auth0 cmd/auth0/main.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. bad resolved merge conflict I guess 🤦🏼

.PHONY: build

# Build for the native platform
build:
go build -ldflags "$(CTIMEVAR)" -o $(GOBIN)/auth0 cmd/auth0/main.go
.PHONY: build

# Build a beta version of auth0-cli for all supported platforms
Expand All @@ -69,6 +65,6 @@ $(GOBIN)/commander:
$(GOBIN)/auth0-cli-config-generator:
go install ./pkg/auth0-cli-config-generator

integration: $(GOBIN)/auth0-cli-config-generator $(GOBIN)/commander
auth0-cli-config-generator && commander test commander.yaml
integration: build $(GOBIN)/auth0-cli-config-generator $(GOBIN)/commander
auth0-cli-config-generator && commander test commander.yaml --verbose
.PHONY: integration
20 changes: 19 additions & 1 deletion pkg/auth0-cli-config-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ type params struct {
clientSecret string
}

var requiredScopes = []string{
"openid",
"offline_access", // <-- to get a refresh token.
"create:clients", "delete:clients", "read:clients", "update:clients",
"create:resource_servers", "delete:resource_servers", "read:resource_servers", "update:resource_servers",
"create:rules", "delete:rules", "read:rules", "update:rules",
"read:users", "update:users",
"read:branding", "update:branding",
"read:client_keys", "read:logs", "read:tenant_settings",
}

func (p params) validate() error {
if p.clientName == "" {
return fmt.Errorf("Missing client name")
Expand Down Expand Up @@ -65,6 +76,7 @@ type tenant struct {
Domain string `json:"domain"`
AccessToken string `json:"access_token,omitempty"`
ExpiresAt time.Time `json:"expires_at"`
Scopes []string `json:"scopes,omitempty"`
}

func isLoggedIn(filePath string) bool {
Expand Down Expand Up @@ -168,7 +180,13 @@ func main() {
return err
}

t := tenant{p.clientName, p.clientDomain, token.AccessToken, token.Expiry}
t := tenant{
Name: p.clientName,
Domain: p.clientDomain,
AccessToken: token.AccessToken,
ExpiresAt: token.Expiry,
Scopes: requiredScopes,
Copy link
Contributor

@jfatta jfatta May 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the CLI is triggering a login flow if the scopes on the tenant are not equal to the defined on the auth package, this is a way we have to "revalidate" tokens if we change the scopes used.

Evidently, it would be hard to maintain (keep in sync) the config generator regarding tenant and other login details.

I would like to explore that alternative of skipping all file-related config if an access token is defined. That way the generator would be repurposed on a command to login and write the access token to a var, no need to know the tenant entity at all.

}

cfg := config{p.clientName, map[string]tenant{p.clientName: t}}
if err := persistConfig(p.filePath, cfg, overwrite); err != nil {
Expand Down