Skip to content

Commit

Permalink
validation for windows only
Browse files Browse the repository at this point in the history
  • Loading branch information
patelchandni committed Aug 15, 2022
1 parent 527511f commit fac4e56
Showing 1 changed file with 36 additions and 34 deletions.
70 changes: 36 additions & 34 deletions lib/utils/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const WebClient_1 = require("azure-actions-webclient/WebClient");
const logger_1 = require("./logger");
const exceptions_1 = require("../exceptions");
const authentication_type_1 = require("../constants/authentication_type");
const runtime_stack_1 = require("../constants/runtime_stack");
const fs = require("fs");
class Client {
static ping(url, retryCount = 1, retryIntervalSecond = 5) {
Expand Down Expand Up @@ -104,48 +105,49 @@ class Client {
let username = "";
let password = "";
let uri = "";
if (context.authenticationType === authentication_type_1.AuthenticationType.Scm) {
logger_1.Logger.Info("Validating deployment package for functions app before Zip Deploy (SCM)");
if (context.scmCredentials) {
username = context.scmCredentials.username;
password = context.scmCredentials.password;
uri = context.scmCredentials.uri;
}
}
else if (context.authenticationType === authentication_type_1.AuthenticationType.Rbac) {
// if (context.authenticationType === AuthenticationType.Scm) {
// Logger.Info("Validating deployment package for functions app before Zip Deploy (SCM)");
// if (context.scmCredentials){
// username = context.scmCredentials.username;
// password = context.scmCredentials.password;
// uri = context.scmCredentials.uri;
// }
// }
if (context.authenticationType === authentication_type_1.AuthenticationType.Rbac &&
context.os === runtime_stack_1.RuntimeStackConstant.Windows) {
logger_1.Logger.Info("Validating deployment package for functions app before Zip Deploy (RBAC)");
var publishingCredentials = yield context.appService.getPublishingCredentials();
if (publishingCredentials.properties["scmUri"]) {
username = publishingCredentials.properties["publishingUserName"];
password = publishingCredentials.properties["publishingPassword"];
uri = publishingCredentials.properties["scmUri"];
}
}
const base64Cred = Buffer.from(`${username}:${password}`).toString('base64');
let request = {
method: 'POST',
uri: `${uri}/api/zipdeploy/validate`,
headers: {
'Content-Type': 'application/json',
'Authorization': `Basic ${base64Cred}`
},
body: fs.createReadStream(webPackage)
};
let response = yield Client.webClient.sendRequest(request);
if (response.statusCode == 200) {
logger_1.Logger.Info(`##[debug]Validation passed response: ${JSON.stringify(response)}`);
if (response.body && response.body.result) {
logger_1.Logger.Warn(JSON.stringify(response.body.result));
const base64Cred = Buffer.from(`${username}:${password}`).toString('base64');
let request = {
method: 'POST',
uri: `${uri}/api/zipdeploy/validate`,
headers: {
'Content-Type': 'application/json',
'Authorization': `Basic ${base64Cred}`
},
body: fs.createReadStream(webPackage)
};
let response = yield Client.webClient.sendRequest(request);
if (response.statusCode == 200) {
logger_1.Logger.Info(`##[debug]Validation passed response: ${JSON.stringify(response)}`);
if (response.body && response.body.result) {
logger_1.Logger.Warn(JSON.stringify(response.body.result));
}
return null;
}
else if (response.statusCode == 400) {
logger_1.Logger.Info(`##[debug]Validation failed response: ${JSON.stringify(response)}`);
throw response;
}
else {
logger_1.Logger.Info(`##[debug]Skipping validation with status: ${response.statusCode}`);
return null;
}
return null;
}
else if (response.statusCode == 400) {
logger_1.Logger.Info(`##[debug]Validation failed response: ${JSON.stringify(response)}`);
throw response;
}
else {
logger_1.Logger.Info(`##[debug]Skipping validation with status: ${response.statusCode}`);
return null;
}
}
catch (error) {
Expand Down

0 comments on commit fac4e56

Please sign in to comment.