Skip to content

Commit

Permalink
cmd/atlas: allow ref env:// to known attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m committed Jan 31, 2024
1 parent c43249c commit 4b91ddf
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions cmd/atlas/internal/cmdapi/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,20 @@ func (e *Env) VarFromURL(s string) (string, error) {
if u.Host == "" || u.Path != "" || u.RawQuery != "" {
return "", fmt.Errorf("invalid env:// variable %q", s)
}
attr, ok := e.Attr(u.Host)
if !ok {
return "", fmt.Errorf("env://%s (attribute) not found in env.%s", s, e.Name)
}
sv, err := attr.String()
if err != nil {
return "", fmt.Errorf("env://%s: %w", s, err)
var sv string
switch u.Host {
case "url":
sv = e.URL
case "dev":
sv = e.DevURL
default:
attr, ok := e.Attr(u.Host)
if !ok {
return "", fmt.Errorf("env://%s (attribute) not found in env.%s", u.Host, e.Name)
}
if sv, err = attr.String(); err != nil {
return "", fmt.Errorf("env://%s: %w", u.Host, err)
}
}
if strings.HasPrefix(sv, envAttrScheme+"://") {
return "", fmt.Errorf("env://%s (attribute) cannot reference another env://", s)
Expand Down

0 comments on commit 4b91ddf

Please sign in to comment.