-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline-pat.yml
124 lines (109 loc) · 3.99 KB
/
pipeline-pat.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
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
121
122
123
124
trigger: none
parameters:
- name: Environment
type: string
values:
- prod
- non-prod
- name: Operation
type: string
values:
- CREATE
- LIST
variables: # Converting parameter to variable for conditional execution in the script
Env: ${{ parameters.Environment }}
operation: ${{ parameters.Operation }}
stages:
- stage: PAT_${{ variables.operation }}
jobs:
- job: ${{ variables.operation }}_PAT
pool:
name: '<your-agent-pool>'
steps:
- task: MicrosoftSecurityDevOps@1
displayName: 'Security Scan'
- task: AzureKeyVault@2
displayName: 'Retrieve secrets from Key Vault'
inputs:
azureSubscription: $(ServiceConnectionName)
KeyVaultName: $(KVName)
SecretsFilter: '*'
RunAsPreJob: true
# Make scripts executable
- script: |
chmod +x scripts/*.sh
ls -al scripts/
displayName: 'Make scripts executable'
# Install requirements
- task: Bash@3
displayName: 'Install AzureCLI'
inputs:
targetType: 'inline'
script: |
sudo apt-get update
sudo apt-get install -y jq
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
# PROD SP Script
- script: scripts/get_access_token.sh
displayName: 'Get Access token - PROD'
condition: eq(variables['Env'], 'prod')
env:
SP_APP_ID: $(sp-app-id)
CLIENT_SECRET: $(sp-secret-value)
AZ_TENANT_ID: $(az-tenant-id)
# NON_PROD SP Script
- script: scripts/get_access_token.sh
displayName: 'Get Access token - NON_PROD'
condition: eq(variables['Env'], 'non-prod')
env:
SP_APP_ID: $(sp-np-app-id)
CLIENT_SECRET: $(sp-np-secret-value)
AZ_TENANT_ID: $(az-tenant-id)
# List PATs
- script: scripts/list_pat.sh
displayName: List PATs
condition: eq(variables['operation'], 'LIST')
env:
DATABRICKS_URL: $(databricks-url)
ACCESS_TOKEN: $(access_token)
BUILD_ID: $(Build.BuildNumber)
# Generate PAT
- script: scripts/generate_pat.sh
displayName: 'Generate PAT'
condition: eq(variables['operation'], 'CREATE')
env:
DATABRICKS_URL: $(databricks-url)
ACCESS_TOKEN: $(access_token) # This variable is set in get_access_token.sh
DESCRIPTION: $(PATSecretName)
EXPIRY: $(TokenValidyDays)
- task: AzureCLI@2
displayName: 'Create/Update Key Vault Secret'
condition: eq(variables['operation'], 'CREATE')
inputs:
azureSubscription: $(ServiceConnectionName)
scriptType: 'bash'
scriptLocation: 'scriptPath'
scriptPath: 'scripts/update_kv.sh'
arguments: '$(KVName) $(PATSecretName) $(token_value) $(expiry_date_iso)'
- stage: SendEmail
dependsOn: PAT_${{ variables.operation }}
condition: eq(variables['operation'], 'CREATE')
jobs:
- job: CreateEmail
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self
# Install requirements
- script: |
python3 -m pip install --upgrade pip
pip3 install azure-communication-email
displayName: "Installing ACS Python module"
# Send email via ACS Client
- script: |
echo "Running python script..."
python3 scripts/send_email.py $(KVName) $(PATSecretName) $(databricks-url) $(RecipientEmail) $(SenderEmail)
displayName: "Send email via ACS Client"
env:
CONNECTION_STRING: $(MailClientConnectionString)
BUILD_ID: $(Build.BuildNumber)