Skip to content

Commit

Permalink
v0.1.4 misc
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed Oct 4, 2024
1 parent 06c1d1f commit 531e84e
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"dependencies": {},
"scripts": {},
"devDependencies": {
"@stoplight/prism-cli": "5.9.0"
"@stoplight/prism-cli": "5.10.0"
}
}
15 changes: 9 additions & 6 deletions service/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,17 @@ func (c *Env) Perform(ctx context.Context, drv *ui.Driver) error {
return fmt.Errorf("Unknown method: %s. Please choose either `export` or `dotenv`.", envOutput)
}

var lclDomain string
for _, d := range attachment.Domains {
if strings.HasSuffix(d, ".lcl.host") {
lclDomain = d
break
var lclUrl string
if attachment != nil {
var lclDomain string
for _, d := range attachment.Domains {
if strings.HasSuffix(d, ".lcl.host") {
lclDomain = d
break
}
}
lclUrl = fmt.Sprintf("https://%s:%d", lclDomain, *service.LocalhostPort)
}
lclUrl := fmt.Sprintf("https://%s:%d", lclDomain, *service.LocalhostPort)

drv.Activate(ctx, &models.EnvNextSteps{
LclUrl: lclUrl,
Expand Down
39 changes: 39 additions & 0 deletions service/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,43 @@ func TestServiceEnv(t *testing.T) {

uitest.TestGolden(t, drv.Golden())
})

t.Run("basics unattached service display", func(t *testing.T) {
if srv.IsProxy() {
t.Skip("service env unsupported in proxy mode")
}

cfg.Test.Prefer = map[string]cli.ConfigTestPrefer{
"/v0/orgs/org-slug/services/service-name/attachments": {
Example: "empty",
},
}
ctx = cli.ContextWithConfig(ctx, cfg)

drv, tm := uitest.TestTUI(ctx, t)
cmd := Env{
Clipboard: new(clipboard.Mock),
}
errc := make(chan error, 1)

go func() {
errc <- cmd.UI().RunTUI(ctx, drv)
errc <- tm.Quit()
}()

uitest.WaitForGoldenContains(t, drv, errc,
"? How would you like to manage your environment variables?",
)

tm.Send(tea.KeyMsg{Type: tea.KeyDown})
tm.Send(tea.KeyMsg{Type: tea.KeyDown})
tm.Send(tea.KeyMsg{Type: tea.KeyEnter})

tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second*3))
if err := <-errc; err != nil {
t.Fatal(err)
}

uitest.TestGolden(t, drv.Golden())
})
}
4 changes: 3 additions & 1 deletion service/models/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ func (m *EnvNextSteps) View() string {

fmt.Fprintln(&b, ui.Header("Next Steps"))
fmt.Fprintln(&b, ui.StepAlert(ui.Action("(Re)Start your server.")))
fmt.Fprintln(&b, ui.StepAlert(fmt.Sprintf("%s: %s", ui.Action("Check out your encrypted site"), ui.URL(m.LclUrl))))
if m.LclUrl != "" {
fmt.Fprintln(&b, ui.StepAlert(fmt.Sprintf("%s: %s", ui.Action("Check out your encrypted site"), ui.URL(m.LclUrl))))
}
fmt.Fprintln(&b, ui.StepHint("These certificates will renew automatically, time to enjoy effortless encryption."))

return b.String()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
─── Client ─────────────────────────────────────────────────────────────────────
* Checking authentication: probing credentials locally…⠋
─── Client ─────────────────────────────────────────────────────────────────────
* Checking authentication: testing credentials remotely…⠋
─── ServiceEnvHeader ───────────────────────────────────────────────────────────

# Fetch Environment Variables for Service `anchor service env`
─── ServiceEnvHint ─────────────────────────────────────────────────────────────

# Fetch Environment Variables for Service `anchor service env`
| We'll set your environment variables to provide configuration and credentials.
─── Fetcher[github.com/anchordotdev/cli/api.Organization] ──────────────────────

# Fetch Environment Variables for Service `anchor service env`
| We'll set your environment variables to provide configuration and credentials.
* Fetching organizations…⠋
─── Fetcher[github.com/anchordotdev/cli/api.Organization] ──────────────────────

# Fetch Environment Variables for Service `anchor service env`
| We'll set your environment variables to provide configuration and credentials.
- Using org-slug, the only available organization. You can also use `--org org-slug`.
─── Fetcher[github.com/anchordotdev/cli/api.Realm] ─────────────────────────────

# Fetch Environment Variables for Service `anchor service env`
| We'll set your environment variables to provide configuration and credentials.
- Using org-slug, the only available organization. You can also use `--org org-slug`.
* Fetching realms…⠋
─── Fetcher[github.com/anchordotdev/cli/api.Realm] ─────────────────────────────

# Fetch Environment Variables for Service `anchor service env`
| We'll set your environment variables to provide configuration and credentials.
- Using org-slug, the only available organization. You can also use `--org org-slug`.
- Using realm-slug, the only available realm. You can also use `--realm realm-slug`.
─── Fetcher[github.com/anchordotdev/cli/api.Service] ───────────────────────────

# Fetch Environment Variables for Service `anchor service env`
| We'll set your environment variables to provide configuration and credentials.
- Using org-slug, the only available organization. You can also use `--org org-slug`.
- Using realm-slug, the only available realm. You can also use `--realm realm-slug`.
* Fetching services…⠋
─── Fetcher[github.com/anchordotdev/cli/api.Service] ───────────────────────────

# Fetch Environment Variables for Service `anchor service env`
| We'll set your environment variables to provide configuration and credentials.
- Using org-slug, the only available organization. You can also use `--org org-slug`.
- Using realm-slug, the only available realm. You can also use `--realm realm-slug`.
- Using service-name, the only available service. You can also use `--service service-name`.
─── EnvFetch ───────────────────────────────────────────────────────────────────

# Fetch Environment Variables for Service `anchor service env`
| We'll set your environment variables to provide configuration and credentials.
- Using org-slug, the only available organization. You can also use `--org org-slug`.
- Using realm-slug, the only available realm. You can also use `--realm realm-slug`.
- Using service-name, the only available service. You can also use `--service service-name`.
* Fetching service-name environment variables…⠋
─── EnvFetch ───────────────────────────────────────────────────────────────────

# Fetch Environment Variables for Service `anchor service env`
| We'll set your environment variables to provide configuration and credentials.
- Using org-slug, the only available organization. You can also use `--org org-slug`.
- Using realm-slug, the only available realm. You can also use `--realm realm-slug`.
- Using service-name, the only available service. You can also use `--service service-name`.
─── EnvMethod ──────────────────────────────────────────────────────────────────

# Fetch Environment Variables for Service `anchor service env`
| We'll set your environment variables to provide configuration and credentials.
- Using org-slug, the only available organization. You can also use `--org org-slug`.
- Using realm-slug, the only available realm. You can also use `--realm realm-slug`.
- Using service-name, the only available service. You can also use `--service service-name`.
? How would you like to manage your environment variables?
> Add export commands to your clipboard.
Add dotenv contents to your clipboard.
Display export commands. ! WARNING: could be observed by others.
─── EnvMethod ──────────────────────────────────────────────────────────────────

# Fetch Environment Variables for Service `anchor service env`
| We'll set your environment variables to provide configuration and credentials.
- Using org-slug, the only available organization. You can also use `--org org-slug`.
- Using realm-slug, the only available realm. You can also use `--realm realm-slug`.
- Using service-name, the only available service. You can also use `--service service-name`.
? How would you like to manage your environment variables?
Add export commands to your clipboard.
> Add dotenv contents to your clipboard.
Display export commands. ! WARNING: could be observed by others.
─── EnvMethod ──────────────────────────────────────────────────────────────────

# Fetch Environment Variables for Service `anchor service env`
| We'll set your environment variables to provide configuration and credentials.
- Using org-slug, the only available organization. You can also use `--org org-slug`.
- Using realm-slug, the only available realm. You can also use `--realm realm-slug`.
- Using service-name, the only available service. You can also use `--service service-name`.
? How would you like to manage your environment variables?
Add export commands to your clipboard.
Add dotenv contents to your clipboard.
> Display export commands. ! WARNING: could be observed by others.
─── EnvMethod ──────────────────────────────────────────────────────────────────

# Fetch Environment Variables for Service `anchor service env`
| We'll set your environment variables to provide configuration and credentials.
- Using org-slug, the only available organization. You can also use `--org org-slug`.
- Using realm-slug, the only available realm. You can also use `--realm realm-slug`.
- Using service-name, the only available service. You can also use `--service service-name`.
- Selected display environment variable method. You can also use `--method display`.
─── EnvDisplay ─────────────────────────────────────────────────────────────────

# Fetch Environment Variables for Service `anchor service env`
| We'll set your environment variables to provide configuration and credentials.
- Using org-slug, the only available organization. You can also use `--org org-slug`.
- Using realm-slug, the only available realm. You can also use `--realm realm-slug`.
- Using service-name, the only available service. You can also use `--service service-name`.
- Selected display environment variable method. You can also use `--method display`.

export ACME_CONTACT="[email protected]"
export ACME_DIRECTORY_URL="http://anchor.lcl.host/org-slug/realm-slug/x509/ca/acme"
export HTTPS_PORT="4433"

- Displayed service-name export commands.
! Be sure to load these into your environment.
─── EnvNextSteps ───────────────────────────────────────────────────────────────

# Fetch Environment Variables for Service `anchor service env`
| We'll set your environment variables to provide configuration and credentials.
- Using org-slug, the only available organization. You can also use `--org org-slug`.
- Using realm-slug, the only available realm. You can also use `--realm realm-slug`.
- Using service-name, the only available service. You can also use `--service service-name`.
- Selected display environment variable method. You can also use `--method display`.

export ACME_CONTACT="[email protected]"
export ACME_DIRECTORY_URL="http://anchor.lcl.host/org-slug/realm-slug/x509/ca/acme"
export HTTPS_PORT="4433"

- Displayed service-name export commands.
! Be sure to load these into your environment.

# Next Steps
! (Re)Start your server.
| These certificates will renew automatically, time to enjoy effortless encryption.

0 comments on commit 531e84e

Please sign in to comment.