Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as util from "util";
import * as yaml from 'js-yaml';
const matchPatternForImageName = new RegExp(/\:\/\/(.+?)\@/);
const matchPatternForDigest = new RegExp(/\@sha256\:(.+)/);
const matchPatternForFileArgument = new RegExp(/-f\s|-filename\s/);
const matchPatternForServerUrl = new RegExp(/https\:\/\/(.+)/);
const matchPatternForSource = new RegExp(/source:(.+)/ig);
const matchPatternForChartPath = new RegExp(/chart path:(.+)/i);
const orgUrl = tl.getVariable('System.TeamFoundationCollectionUri');
const build = "build";
const hostType = tl.getVariable("System.HostType").toLowerCase();
const isBuild = hostType === build;
const deploymentTypes: string[] = ["deployment", "replicaset", "daemonset", "pod", "statefulset"];
const workingDirectory = tl.getVariable("System.DefaultWorkingDirectory");
const branch = tl.getVariable("Build.SourceBranchName") || tl.getVariable("Build.SourceBranch");
const repositoryProvider = tl.getVariable("Build.Repository.Provider");
const repositoryUrl = tl.getVariable("Build.Repository.Uri");
const pipelineUrlLabel = "Pipeline_Url";
const clusterUrlLabel = "Cluster_Url";
const manifestUrlLabel = "Manifest_Url";
// ToDo: Add UTs for public methods
export function getDeploymentMetadata(deploymentObject: any, allPods: any, deploymentStrategy: string, clusterInfo: any, manifestUrls: string[]): any {
let imageIds: string[] = [];
let containers = [];
try {
let kind: string = deploymentObject.kind;
if (isPodEntity(kind)) {
containers = deploymentObject.spec.containers;
}
else {
private checkBuildContext(): boolean {
let requiredVariables: string[] = ['System.DefaultWorkingDirectory', 'build.artifactStagingDirectory', 'build.buildNumber'];
for (let requiredVariable of requiredVariables) {
if (!tl.getVariable(requiredVariable)) {
console.log(tl.loc('codeAnalysisDisabled', requiredVariable));
return false;
}
}
return true;
}
}
import * as tl from "azure-pipelines-task-lib/task";
export class NuGetConfigHelper {
tempNugetConfigPath = tl.getVariable("Agent.HomeDirectory") + "\\tempNuGet_.config";
getSourcesFromConfig() {
tl.debug("getting package sources");
let result = [{ feedName: "mockFeedName", feedUri: "mockFeedUri" }];
return result;
}
setSources(packageSources, includeAuth) {
packageSources.forEach((source) => {
tl.debug(`adding package source uri: ${source.feedUri}`);
});
}
}
public close() {
if (tl.getVariable('KUBECONFIG')) {
tl.setVariable('KUBECONFIG', '');
}
}
}
export function getPipelineUrl(): string {
let pipelineUrl = "";
const pipelineId = tl.getVariable("System.DefinitionId");
if (isBuild) {
pipelineUrl = orgUrl + tl.getVariable("System.TeamProject") + "/_build?definitionId=" + pipelineId;
}
else {
pipelineUrl = orgUrl + tl.getVariable("System.TeamProject") + "/_release?definitionId=" + pipelineId;
}
return pipelineUrl;
}
export function getTempDirectory(): string {
return tl.getVariable('agent.tempDirectory') || os.tmpdir();
}
function getEnvironmentResourceAddress(clusterUrl: any): string {
const environmentName = tl.getVariable("Environment.Name");
const environmentResourceName = tl.getVariable("Environment.ResourceName");
if (!environmentName && !environmentResourceName) {
if (clusterUrl && clusterUrl["url"]) {
return clusterUrl["url"];
}
return "";
}
return util.format("%s/%s", environmentName, environmentResourceName);
}
private getExistingDockerConfigFilePath(): string {
this.configurationDirPath = tl.getVariable("DOCKER_CONFIG");
let configurationFilePath = this.configurationDirPath ? path.join(this.configurationDirPath, "config.json") : "";
if (this.configurationDirPath && this.isPathInTempDirectory(configurationFilePath) && fs.existsSync(configurationFilePath)) {
return configurationFilePath;
}
return null;
}
constructor(explicitVersioning: boolean = false) {
this.explicitVersioning = explicitVersioning;
let proxyUrl: string = tl.getVariable("agent.proxyurl");
var requestOptions: httpInterfaces.IRequestOptions = proxyUrl ? {
proxy: {
proxyUrl: proxyUrl,
proxyUsername: tl.getVariable("agent.proxyusername"),
proxyPassword: tl.getVariable("agent.proxypassword"),
proxyBypassHosts: tl.getVariable("agent.proxybypasslist") ? JSON.parse(tl.getVariable("agent.proxybypasslist")) : null
}
} : {};
this.httpCallbackClient = new httpClient.HttpClient(tl.getVariable("AZURE_HTTP_USER_AGENT"), null, requestOptions);
this.channels = [];
}
private removeConfigDirAndUnsetEnvVariable(): void {
let dockerConfigDirPath = tl.getVariable("DOCKER_CONFIG");
if (dockerConfigDirPath && this.isPathInTempDirectory(dockerConfigDirPath) && fs.existsSync(dockerConfigDirPath)) {
tl.debug(tl.loc('DeletingDockerConfigDirectory', dockerConfigDirPath));
del.sync(dockerConfigDirPath, {force: true});
}
this.unsetEnvironmentVariable();
}