-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibrary.fs
120 lines (95 loc) · 4.33 KB
/
Library.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
namespace Fake.Azure.Cli
(*
Task.json:
{
"name": "connectedServiceNameARM",
"aliases": [
"azureSubscription"
],
"type": "connectedService:AzureRM",
"label": "Azure subscription",
"required": true,
"helpMarkDown": "Select an Azure resource manager subscription for the deployment"
},
https://github.com/Microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureCLIV1/azureclitask.ts
var servicePrincipalId: string = tl.getEndpointAuthorizationParameter(connectedService, "serviceprincipalid", false);
let authType: string = tl.getEndpointAuthorizationParameter(connectedService, 'authenticationType', true);
let cliPassword: string = null;
if (authType == "spnCertificate") {
tl.debug('certificate based endpoint');
let certificateContent: string = tl.getEndpointAuthorizationParameter(connectedService, "servicePrincipalCertificate", false);
cliPassword = path.join(tl.getVariable('Agent.TempDirectory') || tl.getVariable('system.DefaultWorkingDirectory'), 'spnCert.pem');
fs.writeFileSync(cliPassword, certificateContent);
this.cliPasswordPath = cliPassword;
}
else {
tl.debug('key based endpoint');
cliPassword = tl.getEndpointAuthorizationParameter(connectedService, "serviceprincipalkey", false);
}
var tenantId: string = tl.getEndpointAuthorizationParameter(connectedService, "tenantid", false);
var subscriptionID: string = tl.getEndpointDataParameter(connectedService, "SubscriptionID", true);
// set az cli config dir
this.setConfigDirectory();
//login using svn
this.throwIfError(tl.execSync("az", "login --service-principal -u \"" + servicePrincipalId + "\" -p \"" + cliPassword + "\" --tenant \"" + tenantId + "\""), tl.loc("LoginFailed"));
this.isLoggedIn = true;
//set the subscription imported to the current subscription
this.throwIfError(tl.execSync("az", "account set --subscription \"" + subscriptionID + "\""), tl.loc("ErrorInSettingUpSubscription"));
https://github.com/Microsoft/azure-pipelines-task-lib/blob/350e635901a8a657523458213a0426a8d136bcdc/node/task.ts#L351
/**
* Gets the endpoint authorization parameter value for a service endpoint with specified key
* If the endpoint authorization parameter is not set and is not optional, it will throw.
*
* @param id name of the service endpoint
* @param key key to find the endpoint authorization parameter
* @param optional optional whether the endpoint authorization scheme is optional
* @returns {string} value of the endpoint authorization parameter value
*/
export function getEndpointAuthorizationParameter(id: string, key: string, optional: boolean): string {
var authParam = im._vault.retrieveSecret('ENDPOINT_AUTH_PARAMETER_' + id + '_' + key.toUpperCase());
if (!optional && !authParam) {
throw new Error(loc('LIB_EndpointAuthNotExist', id));
}
debug(id + ' auth param ' + key + ' = ' + authParam);
return authParam;
}
/**
* Interface for EndpointAuthorization
* Contains a schema and a string/string dictionary of auth data
*/
export interface EndpointAuthorization {
/** dictionary of auth data */
parameters: {
[key: string]: string;
};
/** auth scheme such as OAuth or username/password etc... */
scheme: string;
}
/**
* Gets the authorization details for a service endpoint
* If the authorization was not set and is not optional, it will throw.
*
* @param id name of the service endpoint
* @param optional whether the url is optional
* @returns string
*/
export function getEndpointAuthorization(id: string, optional: boolean): EndpointAuthorization {
var aval = im._vault.retrieveSecret('ENDPOINT_AUTH_' + id);
if (!optional && !aval) {
setResult(TaskResult.Failed, loc('LIB_EndpointAuthNotExist', id));
}
console.log(id + ' exists ' + (aval !== null));
debug(id + ' exists ' + (aval !== null));
var auth: EndpointAuthorization;
try {
auth = <EndpointAuthorization>JSON.parse(aval);
}
catch (err) {
throw new Error(loc('LIB_InvalidEndpointAuth', aval));
}
return auth;
}
*)
module Say =
let hello name =
printfn "Hello %s" name