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

log into pr preview environments #865

Merged
merged 3 commits into from
Nov 17, 2022
Merged

log into pr preview environments #865

merged 3 commits into from
Nov 17, 2022

Conversation

jemishp
Copy link
Contributor

@jemishp jemishp commented Nov 9, 2022

Description

Users can now log into pr preview environments using astro cli

🎟 Issue(s)

Related #805 Related #808

🧪 Functional Testing

astro login pr5993.cloud.astronomer-dev.io

Welcome to the Astro CLI 🚀

To learn more about Astro, go to https://docs.astronomer.io

Please enter your account email: preview@astronomer.io

Press Enter to open the browser to log in or ^C to quit…
done
 CONTEXT DOMAIN                      WORKSPACE
 pr5993.astronomer-dev.io            cla9y4l9q0176jggw9njp6ehx

 Switched context

"Sample Workspace 1" Workspace found. This is your default Workspace.

Successfully authenticated to Astronomer

📋 Checklist

  • Rebased from the main (or release if patching) branch (before testing)
  • Ran make test before taking out of draft
  • Ran make lint before taking out of draft
  • Added/updated applicable tests
  • Tested against Astro-API (if necessary).
  • Tested against Houston-API and Astronomer (if necessary).
  • Communicated to/tagged owners of respective clients potentially impacted by these changes.
  • Updated any related documentation

@jemishp jemishp linked an issue Nov 9, 2022 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Nov 9, 2022

Codecov Report

Base: 87.11% // Head: 87.14% // Increases project coverage by +0.02% 🎉

Coverage data is based on head (7664623) compared to base (f9557e4).
Patch coverage: 95.08% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #865      +/-   ##
==========================================
+ Coverage   87.11%   87.14%   +0.02%     
==========================================
  Files         106      107       +1     
  Lines        9083     9068      -15     
==========================================
- Hits         7913     7902      -11     
+ Misses        689      688       -1     
+ Partials      481      478       -3     
Impacted Files Coverage Δ
config/config.go 80.00% <ø> (ø)
config/context.go 75.70% <ø> (ø)
cloud/deploy/deploy.go 72.72% <33.33%> (-0.41%) ⬇️
context/context.go 82.05% <66.66%> (-2.76%) ⬇️
cloud/auth/auth.go 81.27% <100.00%> (+0.38%) ⬆️
cloud/deployment/deployment.go 89.35% <100.00%> (+0.10%) ⬆️
cloud/organization/organization.go 76.69% <100.00%> (+1.69%) ⬆️
cmd/auth.go 89.09% <100.00%> (ø)
config/cloud.go 77.14% <100.00%> (-9.07%) ⬇️
pkg/domainutil/domain.go 100.00% <100.00%> (ø)
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

// See https://github.com/astronomer/astrohub-cli/issues/7 for regexp rationale
// This will need to be handled as part of the permanent solution to issue #432
CloudDomainRegex = regexp.MustCompile(`(cloud\.|^)astronomer(?:(-dev|-stage|-perf))?\.io`)
PRPreviewDomainRegex = regexp.MustCompile(`(pr\d{4}\.)astronomer(-dev)\.io$`)
Copy link

@jcom000 jcom000 Nov 9, 2022

Choose a reason for hiding this comment

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

4+, and i think -dev is mandatory

Copy link

Choose a reason for hiding this comment

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

^(pr\d{4+}\).astronomer-dev\.io$
matches := re.FindStringSubmatch would get you one result here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it to ^(pr\d{4,6}).astronomer-dev\.io$ so that it still has an upper limit on the numbers.

pkg/domainutil/domain.go Outdated Show resolved Hide resolved
@jemishp jemishp force-pushed the 805-allow-pr-preview-logins branch 5 times, most recently from 9a883db to 3ed56f9 Compare November 11, 2022 05:16
}

func getPRSubDomain(domain string) (prSubDomain, restOfDomain string) {
if isPrPreviewDomain(domain) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this is a duplicate check, since the caller already checks if it's a pr preview domain and then only calls this method

- `auth.Login()` succeeds with a valid pr preview env
- `auth.formatDomain()` and `auth.ValidateDomain()` allow pr preview
- `config.IsCloudContext()` allows pr preview
- add a pr prveiew context to `testing.NewTestConfig()`
- TODO - address a few TODOs
- anytime we need to check domain or URLs to be derived from a domain for the user login flow, we use the `domainutil` package
- tighten up the domain and pr preview regexes
- able to transform astrohub url -> core api url for valid domains
- remove redundant `GetCloudAPIURL()`
- `deploy.go` and `deplyment.go` use `GetDeploymentURL()` to print the dashboard url
- resolves #806
- resolves #807
Copy link
Contributor

@kushalmalani kushalmalani left a comment

Choose a reason for hiding this comment

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

LGTM...i tested this against local and dev environment to make sure we are not causing a regression

Great work on this @jemishp 🎉

@jemishp jemishp merged commit 04bacf0 into main Nov 17, 2022
@jemishp jemishp deleted the 805-allow-pr-preview-logins branch November 17, 2022 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modify auth.go and how it validates domains Modify context.CloudDomainRegex to allow pr preview environments
5 participants