Skip to content

Commit

Permalink
fix(enterprise): more fixes to login flow
Browse files Browse the repository at this point in the history
  • Loading branch information
eysi09 authored and thsig committed Jan 18, 2021
1 parent 32c14f8 commit 8e558e1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ ${renderCommands(commands)}
}
}

if (enterpriseApi.getDomain()) {
if (enterpriseApi.isUserLoggedIn) {
log.silly(`Connecting Garden instance to GE BufferedEventStream`)
bufferedEventStream.connect({
garden,
Expand Down
6 changes: 6 additions & 0 deletions core/src/enterprise/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class EnterpriseApi {
protected log: LogEntry
protected enterpriseDomain: string
protected intervalMsec = 4500 // Refresh interval in ms, it needs to be less than refreshThreshold/2
public isUserLoggedIn: boolean = false
protected apiPrefix = "api"

constructor(log: LogEntry) {
Expand Down Expand Up @@ -76,6 +77,11 @@ export class EnterpriseApi {
if (!tokenIsValid) {
await this.refreshToken()
}
// At this point we can be sure the user is logged in because we have
// a valid token or refreshing the token did not go through.
// TODO: Refactor to make a bit more robust (cc @emanuele and @thsig, you
// know what I'm talking about.)
this.isUserLoggedIn = true
this.startInterval()
}
}
Expand Down
11 changes: 6 additions & 5 deletions core/src/enterprise/workflow-lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ export async function registerWorkflowRun({
log.error(`An error occurred while registering workflow run: ${err.message}`)
throw err
}
const body = res.body

if (res && res["workflowRunUid"] && res["status"] === "success") {
return res["workflowRunUid"]
if (body && body["workflowRunUid"] && body["status"] === "success") {
return body["workflowRunUid"]
} else {
throw new EnterpriseApiError(
`Error while registering workflow run: Request failed with status ${res["status"]}`,
`Error while registering workflow run: Request failed with status ${body["status"]}`,
{
status: res["status"],
workflowRunUid: res["workflowRunUid"],
status: body["status"],
workflowRunUid: body["workflowRunUid"],
}
)
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export class Garden {
const projectId = config.id || null
let secrets: StringMap = {}
const enterpriseApi = opts.enterpriseApi || null
if (!opts.noEnterprise && enterpriseApi) {
if (!opts.noEnterprise && enterpriseApi?.isUserLoggedIn) {
const enterpriseInitResult = await enterpriseInit({ log, projectId, enterpriseApi, environmentName })
secrets = enterpriseInitResult.secrets
}
Expand Down

0 comments on commit 8e558e1

Please sign in to comment.