Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createAuthHandlers(artifactoryService) {
let artifactoryUser = tl.getEndpointAuthorizationParameter(artifactoryService, "username", true);
let artifactoryPassword = tl.getEndpointAuthorizationParameter(artifactoryService, "password", true);
let artifactoryAccessToken = tl.getEndpointAuthorizationParameter(artifactoryService, "apitoken", true);
// Check if Artifactory should be accessed using access-token.
if (artifactoryAccessToken) {
return [new clientHandlers.BearerCredentialHandler(artifactoryAccessToken)]
}
// Check if Artifactory should be accessed anonymously.
if (artifactoryUser === "") {
return [];
}
// Use basic authentication.
return [new clientHandlers.BasicCredentialHandler(artifactoryUser, artifactoryPassword)];
}
export async function body_as_text(url: string, token: string = ''): Promise {
const bearer = token ? [ new BearerCredentialHandler(token) ] : undefined;
let client = new httpm.HttpClient("mihails-strasuns/setup-dlang", bearer);
return (await (await client.get(url)).readBody()).trim();
}
export async function getCacheEntry(
keys: string[]
): Promise {
const cacheUrl = getCacheUrl();
const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
const bearerCredentialHandler = new BearerCredentialHandler(token);
const resource = `_apis/artifactcache/cache?keys=${encodeURIComponent(
keys.join(",")
)}`;
const restClient = new RestClient("actions/cache", cacheUrl, [
bearerCredentialHandler
]);
const response = await restClient.get(
resource,
getRequestOptions()
);
if (response.statusCode === 204) {
return null;
}
return __awaiter(this, void 0, void 0, function* () {
const bearer = token ? [new Handlers_1.BearerCredentialHandler(token)] : undefined;
let client = new httpm.HttpClient("mihails-strasuns/setup-dlang", bearer);
return (yield (yield client.get(url)).readBody()).trim();
});
}
export async function saveCache(
stream: NodeJS.ReadableStream,
key: string
): Promise {
const cacheUrl = getCacheUrl();
const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
const bearerCredentialHandler = new BearerCredentialHandler(token);
const resource = `_apis/artifactcache/cache/${encodeURIComponent(key)}`;
const postUrl = cacheUrl + resource;
const restClient = new RestClient("actions/cache", undefined, [
bearerCredentialHandler
]);
const requestOptions = getRequestOptions();
requestOptions.additionalHeaders = {
"Content-Type": "application/octet-stream"
};
const response = await restClient.uploadStream(
"POST",
postUrl,