This repository has been archived by the owner on Jun 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
scriptCredentials.groovy
executable file
·83 lines (69 loc) · 2.58 KB
/
scriptCredentials.groovy
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
/*
Format: Electric Flow DSL
File: scriptCredentials.groovy
Description: Examples of how to insert user/password into scripts without exposing them
Set up Instructions
-------------------
Edit the resource name lines below to point to Window and/or Linux hosts
Run:
ectool --format json evalDsl --dslFile scriptCredentials.groovy
*/
// Default resources
def winResource = 'host'
def linResource = 'local'
project "Use Credentials in scripts",{
credential "TestCreds",
userName: "me",
password: "mypass"
procedure "Use Credentials with Groovy",{
formalParameter "config", defaultValue: "TestCreds"
step "Get password", { attachCredential credentialName: 'TestCreds' },
command: '''\
password = "ectool getFullCredential TestCreds --value password".execute().text
userName = "ectool getFullCredential TestCreds --value userName".execute().text
print "Username: $userName\\n"
print "Password: $password\\n"
'''.stripIndent(),
shell: "ec-groovy",
resourceName: winResource
}
procedure "Use Credentials with PowerShell shell",{
formalParameter "config", defaultValue: "TestCreds"
step "Get password", { attachCredential credentialName: 'TestCreds' },
command: '''\
$password = (ectool getFullCredential TestCreds --value password) | Out-String
$userName = (ectool getFullCredential TestCreds --value userName) | Out-String
echo Username: $userName
echo Password: $password
'''.stripIndent(),
resourceName: winResource,
shell: '''powershell "& '{0}.ps1'" '''
}
procedure "Use Credentials with Windows cmd",{
formalParameter "config", defaultValue: "TestCreds"
step "Get password", { attachCredential credentialName: 'TestCreds' },
command: '''\
FOR /F "tokens=* USEBACKQ" %%F IN (`ectool getFullCredential TestCreds --value password`) DO (
SET password=%%F
)
FOR /F "tokens=* USEBACKQ" %%F IN (`ectool getFullCredential TestCreds --value userName`) DO (
SET userName=%%F
)
echo Username: %userName%
echo Password: %password%
'''.stripIndent(),
resourceName: winResource
}
procedure "Use Credentials with bash",{
formalParameter "config", defaultValue: "TestCreds"
step "Get password", { attachCredential credentialName: 'TestCreds' },
command: '''\
userName=`ectool getFullCredential TestCreds --value userName`
password=`ectool getFullCredential TestCreds --value password`
echo Username: $userName
echo Password: $password
'''.stripIndent(),
resourceName: linResource,
shell: 'bash'
}
}