This repository has been archived by the owner on May 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VScode is caching template and provisioning service clients first tim…
…e when deploy to azure command runs (#202) * Initial changes * change variable name * change variable name * Changes env name * Review comments * review comments * Review comment * commit to run CI * test commit for testing check runs * Update remoteServiceUrlHelper.ts * Update remoteServiceUrlHelper.ts * Update remoteServiceUrlHelper.ts * revert test changes * URL bug fix * Cachced client fix * Cachced client fix * updated permissions * Changes desgined * Removed new line * removed unsed params * review comments Co-authored-by: Bishal Prasad <[email protected]>
- Loading branch information
1 parent
52765a3
commit f8a38b7
Showing
8 changed files
with
61 additions
and
22 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,43 @@ | ||
import { ServiceClientCredentials, TokenCredentials } from "ms-rest"; | ||
import { RemoteServiceUrlHelper, ServiceFramework } from "../helper/remoteServiceUrlHelper"; | ||
import { Messages } from '../resources/messages'; | ||
import { TemplateServiceClient } from "./github/TemplateServiceClient"; | ||
import { ITemplateServiceClient } from "./ITemplateServiceClient"; | ||
const UserAgent = "deploy-to-azure-vscode"; | ||
|
||
export class TemplateServiceClientFactory { | ||
|
||
public static async getClient(credentials?: ServiceClientCredentials, githubPatToken?: string): Promise<ITemplateServiceClient> { | ||
public static async getClient(): Promise<ITemplateServiceClient> { | ||
if (!!this.client) { | ||
return this.client; | ||
} | ||
|
||
if (!this.githubPatToken || !this.credentials) { | ||
throw new Error(Messages.UndefinedClientCredentials); | ||
} | ||
|
||
const serviceDefinition = await RemoteServiceUrlHelper.getTemplateServiceDefinition(); | ||
if (serviceDefinition.serviceFramework === ServiceFramework.Vssf) { | ||
this.client = new TemplateServiceClient(serviceDefinition.serviceUrl, credentials, { | ||
this.client = new TemplateServiceClient(serviceDefinition.serviceUrl, this.credentials, { | ||
"Content-Type": "application/json; charset=utf-8" | ||
}); | ||
} else { | ||
this.client = new TemplateServiceClient(serviceDefinition.serviceUrl, new TokenCredentials(githubPatToken, "token"), { | ||
this.client = new TemplateServiceClient(serviceDefinition.serviceUrl, new TokenCredentials(this.githubPatToken, "token"), { | ||
"User-Agent": UserAgent, | ||
"Content-Type": "application/json; charset=utf-8" | ||
}); | ||
} | ||
|
||
return this.client; | ||
} | ||
|
||
public static initialize(credentials: ServiceClientCredentials, githubPatToken: string): void { | ||
this.client = null; | ||
this.credentials = credentials; | ||
this.githubPatToken = githubPatToken | ||
} | ||
|
||
private static client: ITemplateServiceClient; | ||
private static credentials: ServiceClientCredentials; | ||
private static githubPatToken: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,39 @@ | ||
import { ServiceClientCredentials, TokenCredentials } from "ms-rest"; | ||
import { RemoteServiceUrlHelper, ServiceFramework } from "../helper/remoteServiceUrlHelper"; | ||
import { Messages } from '../resources/messages'; | ||
import { IProvisioningServiceClient } from "./IProvisioningServiceClient"; | ||
import { ProvisioningServiceClient } from "./ProvisioningServiceClient"; | ||
|
||
|
||
export class ProvisioningServiceClientFactory { | ||
public static async getClient(githubPatToken: string, credentials?: ServiceClientCredentials): Promise<IProvisioningServiceClient> { | ||
public static async getClient(): Promise<IProvisioningServiceClient> { | ||
if (!!this.client) { | ||
return this.client; | ||
} | ||
|
||
if (!this.githubPatToken || !this.credentials) { | ||
throw new Error(Messages.UndefinedClientCredentials); | ||
} | ||
|
||
const defaultHeaders: { [propertyName: string]: string } = { "Content-Type": "application/json" }; | ||
const serviceDefinition = await RemoteServiceUrlHelper.getProvisioningServiceDefinition(); | ||
if (serviceDefinition.serviceFramework === ServiceFramework.Vssf) { | ||
defaultHeaders["X-GITHUB-TOKEN"] = "token " + githubPatToken; | ||
this.client = new ProvisioningServiceClient(serviceDefinition, defaultHeaders, credentials); | ||
defaultHeaders["X-GITHUB-TOKEN"] = "token " + this.githubPatToken; | ||
this.client = new ProvisioningServiceClient(serviceDefinition, defaultHeaders, this.credentials); | ||
} else { | ||
this.client = new ProvisioningServiceClient(serviceDefinition, defaultHeaders, new TokenCredentials(githubPatToken, "token")); | ||
this.client = new ProvisioningServiceClient(serviceDefinition, defaultHeaders, new TokenCredentials(this.githubPatToken, "token")); | ||
} | ||
|
||
return this.client; | ||
} | ||
|
||
public static initialize(credentials: ServiceClientCredentials, githubPatToken: string): void { | ||
this.client = null; | ||
this.credentials = credentials; | ||
this.githubPatToken = githubPatToken | ||
} | ||
|
||
private static client: IProvisioningServiceClient; | ||
private static credentials: ServiceClientCredentials; | ||
private static githubPatToken: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters