diff --git a/core/src/cli/cli.ts b/core/src/cli/cli.ts index d9326e257a..b563034027 100644 --- a/core/src/cli/cli.ts +++ b/core/src/cli/cli.ts @@ -290,7 +290,7 @@ ${renderCommands(commands)} } } - if (enterpriseApi.getDomain()) { + if (enterpriseApi.isUserLoggedIn) { log.silly(`Connecting Garden instance to GE BufferedEventStream`) bufferedEventStream.connect({ garden, diff --git a/core/src/enterprise/api.ts b/core/src/enterprise/api.ts index 4744bc0e58..997490c56e 100644 --- a/core/src/enterprise/api.ts +++ b/core/src/enterprise/api.ts @@ -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) { @@ -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() } } diff --git a/core/src/enterprise/workflow-lifecycle.ts b/core/src/enterprise/workflow-lifecycle.ts index 29120f73ba..dee33e3c00 100644 --- a/core/src/enterprise/workflow-lifecycle.ts +++ b/core/src/enterprise/workflow-lifecycle.ts @@ -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"], } ) } diff --git a/core/src/garden.ts b/core/src/garden.ts index 670ddc3d90..e87e6d935d 100644 --- a/core/src/garden.ts +++ b/core/src/garden.ts @@ -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 }