- Notifications
You must be signed in to change notification settings - Fork906
fix(cli): replace $SESSION_TOKEN placeholder for external apps#17048
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -301,6 +301,10 @@ func (r *RootCmd) openApp() *serpent.Command { | ||
pathAppURL := strings.TrimPrefix(region.PathAppURL, baseURL.String()) | ||
appURL := buildAppLinkURL(baseURL, ws, agt, foundApp, region.WildcardHostname, pathAppURL) | ||
if foundApp.External { | ||
appURL = replacePlaceholderExternalSessionTokenString(client, appURL) | ||
} | ||
// Check if we're inside a workspace. Generally, we know | ||
// that if we're inside a workspace, `open` can't be used. | ||
insideAWorkspace := inv.Environ.Get("CODER") == "true" | ||
@@ -314,7 +318,7 @@ func (r *RootCmd) openApp() *serpent.Command { | ||
if !testOpenError { | ||
err = open.Run(appURL) | ||
} else { | ||
err = xerrors.New("test.open-error: " + appURL) | ||
} | ||
return err | ||
}, | ||
@@ -511,3 +515,15 @@ func buildAppLinkURL(baseURL *url.URL, workspace codersdk.Workspace, agent coder | ||
} | ||
return u.String() | ||
} | ||
// replacePlaceholderExternalSessionTokenString replaces any $SESSION_TOKEN | ||
// strings in the URL with the actual session token. | ||
// This is consistent behavior with the frontend. See: site/src/modules/resources/AppLink/AppLink.tsx | ||
func replacePlaceholderExternalSessionTokenString(client *codersdk.Client, appURL string) string { | ||
if !strings.Contains(appURL, "$SESSION_TOKEN") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Is this the only supported format? Not e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Nope, it's just | ||
return appURL | ||
} | ||
// We will just re-use the existing session token we're already using. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think this is fine for apps. For VS Code I think we generate a new one but since it’s long-lived in the editor, it makes sense to decouple them. Same doesn’t apply here. | ||
return strings.ReplaceAll(appURL, "$SESSION_TOKEN", client.SessionToken()) | ||
} |
Uh oh!
There was an error while loading.Please reload this page.