-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectionsScript
92 lines (87 loc) · 4.43 KB
/
ConnectionsScript
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
pipeline {
agent any
parameters {
choice(name: 'InstanceURL', choices: ['DEV', 'UAT', 'PROD'], description: 'Select the instance URL')
}
stages {
stage('Read CSV') {
steps {
script {
def instanceURL
def Username
def Password
switch(params.InstanceURL) {
case 'DEV':
instanceURL = 'https://testinstance-idevjxz332qf-ia.integration.ocp.oraclecloud.com'
Username = 'Devops_user'
Password = 'Oic_Jenkins#2023'
break
case 'UAT':
instanceURL = 'http://example.com/url2'
Username = 'username1'
Password = 'password1'
break
case 'PROD':
instanceURL = 'http://example.com/url3'
Username = 'username1'
Password = 'password1'
break
default:
echo 'Invalid instance URL'
return
}
def csvFile = readFile(params.CSVFileName).trim()
def records = csvFile.readLines().drop(1).collect { line -> line.tokenize(',') }
records.each { record ->
def field1 = record[0]
def field2 = record[1]
def field3 = record[2]
def field4 = record[3]
def conProperties = """
{
"connectionProperties": {
"propertyGroup": "CONNECTION_PROPS",
"propertyName": "connectionUrl",
"propertyType": "URL",
"propertyValue": "${field1}"
},
"securityPolicy": "BASIC_AUTH",
"securityProperties": [
{
"propertyGroup": "CREDENTIALS",
"propertyName": "username",
"propertyValue": "${field2}"
},
{
"propertyGroup": "CREDENTIALS",
"propertyName": "password",
"propertyValue": "${field3}"
}
]
}
"""
def payload = conProperties.replace('\n', '').trim()
writeFile file: 'payload.json', text: payload
//def integURL = "https://testinstance-idevjxz332qf-ia.integration.ocp.oraclecloud.com/ic/api/integration/v1/connections/${field4}"
//bat"""
//curl -X POST --user "Devops_user:Oic_Jenkins#2023" --header "X-HTTP-Method-Override:PATCH" --header "Content-Type:application/json" -d @payload.json "https://testinstance-idevjxz332qf-ia.integration.ocp.oraclecloud.com/ic/api/integration/v1/connections/${field4}" """
def selectedOption = "${params.Import_Method}".trim()
if (selectedOption == 'New') {
echo 'Adding new connection'
bat """
curl -X POST --user ${Username}:${Password} --header "X-HTTP-Method-Override:PATCH" --header "Content-Type:application/json" -d @payload.json "${instanceURL}/ic/api/integration/v1/connections/${field4}"
"""
} else if (selectedOption == 'Replace') {
echo 'Replacing a connection'
bat """
curl -X POST --user ${Username}:${Password} --header "X-HTTP-Method-Override:PATCH" --header "Content-Type:application/json" -d @payload.json "${instanceURL}/ic/api/integration/v1/connections/${field4}"
"""
} else {
echo 'No import method is selected'
}
}
}
}
}
}
}