-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathtest.yml
84 lines (76 loc) · 2.59 KB
/
test.yml
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
configuration:
arguments:
puppetParams:
debug: true
flows:
default:
- call: promptForAction
- log: "done"
promptForAction:
# Create Action Prompt Form
- ${execution.removeVariable('apiTokenForm')} # clear stale form data
- set:
options:
- "Create API Token"
- "Execute PQL Query"
- "Exit"
fields:
- action: { type: "string", label: "What do you want to do?", "placeholder": "Choose action here", allow: "${options}", search: true}
- form: actionForm
fields: ${fields}
- switch: ${actionForm.action}
"Create API Token":
- log: "Creating an API token"
- call: createToken
"Execute PQL Query":
- log: "Executing PQL Query"
- call: executeQuery
"Exit":
- log: "Exiting..."
- exit
- call: promptForAction
# Create an API Token
createToken:
- form: apiTokenForm # get user info
- task: puppet # create the token
in:
action: "createApiToken"
ignoreErrors: true
username: ${apiTokenForm.username}
password: ${apiTokenForm.password}
tokenLife: ${apiTokenForm.lifetime}
tokenLabel: ${apiTokenForm.label}
tokenDescription: ${apiTokenForm.description}
- if: ${result.ok}
then:
- log: "New api token: ${result.data}"
else:
- log: "Error creating api token: ${result.error}"
# execute a PQL query
executeQuery:
- form: queryForm # get the query
- task: puppet # execute it
in:
action: "pql"
ignoreErrors: true
queryString: ${queryForm.query}
- if: ${result.ok}
then:
# prove we got the results
- log: ${resource.prettyPrintJson(result.data)}
# filter down to only the certname values
- set:
certnames: ${result.data.stream().map(x -> x.get("certname")).toList()}
- log: "Only certnames:"
- log: ${resource.prettyPrintJson(certnames)}
else:
- log: "Error executing pql: ${result.error}"
forms:
apiTokenForm:
- username: { label: "Username", type: "string"}
- password: { label: "Password", type: "string", inputType: "password" }
- lifetime: { label: "Token Lifetime", type: "string", allow: ["10m", "1h", "1d", "1y"], value: "1h" }
- label: { label: "Token Label", type: "string?" }
- description: { label: "Token Description", type: "string?", value: "Created on ${datetime.current('yyyy-MM-dd HH:mm:ss')}" }
queryForm:
- query: { label: "Query String", type: "string", placeholder: "inventory{ limit 5 }" }