Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit bd7ed34

Browse files
committed
Merge remote-tracking branch 'origin/7.2.6'
2 parents 9a0a10a + 6f2bbba commit bd7ed34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2123
-120
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/config.ini
2+
__pycache__/

apiclient.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
import sys
55
import os
6-
sys.path.append(os.path.realpath('modules'))
76
import json
8-
from RestApiClient import RestApiClient
97
from optparse import OptionParser
108
import re
119

10+
import importlib
11+
sys.path.append(os.path.realpath('modules'))
12+
client_module = importlib.import_module('RestApiClient')
13+
1214

1315
# This is to modify the behaviour of the OptParser to make it check arguments
1416
# more strictly
@@ -90,7 +92,7 @@ def get_parser():
9092

9193
def print_api():
9294

93-
api_client = RestApiClient()
95+
api_client = client_module.RestApiClient()
9496

9597
response = api_client.call_api('help/capabilities', 'GET')
9698
response_json = json.loads(response.read().decode('utf-8'))
@@ -163,7 +165,7 @@ def make_request(args):
163165

164166
# Create an API for the version specified by the user. If args.version is
165167
# None the latest version will be used.
166-
api_client = RestApiClient(version=args.version)
168+
api_client = client_module.RestApiClient(version=args.version)
167169

168170
# Make a copy of the headers so we are able to set some custom headers.
169171
headers = api_client.get_headers()

asset_model/01_GetAssets.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414

1515
import sys
1616
import os
17-
sys.path.append(os.path.realpath('../modules'))
1817
import json
19-
from RestApiClient import RestApiClient
20-
import SampleUtilities as SampleUtilities
18+
19+
import importlib
20+
sys.path.append(os.path.realpath('../modules'))
21+
client_module = importlib.import_module('RestApiClient')
22+
SampleUtilities = importlib.import_module('SampleUtilities')
2123

2224

2325
def main():
2426
# Create our client.
25-
client = RestApiClient(version='3.0')
27+
client = client_module.RestApiClient(version='5.0')
2628

2729
# Using the /asset_model/assets endpoint with a GET request.
2830
SampleUtilities.pretty_print_request(client, 'asset_model/assets', 'GET')

asset_model/02_GetProperties.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212

1313
import sys
1414
import os
15-
sys.path.append(os.path.realpath('../modules'))
1615
import json
17-
from RestApiClient import RestApiClient
18-
import SampleUtilities as SampleUtilities
16+
17+
import importlib
18+
sys.path.append(os.path.realpath('../modules'))
19+
client_module = importlib.import_module('RestApiClient')
20+
SampleUtilities = importlib.import_module('SampleUtilities')
1921

2022

2123
def main():
2224
# Create our client.
23-
client = RestApiClient(version='3.0')
25+
client = client_module.RestApiClient(version='5.0')
2426

2527
# Using the /asset_model/properties endpoint with a GET request.
2628
SampleUtilities.pretty_print_request(client, 'asset_model/properties',

asset_model/03_GetSavedSearches.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212

1313
import sys
1414
import os
15-
sys.path.append(os.path.realpath('../modules'))
1615
import json
17-
from RestApiClient import RestApiClient
18-
import SampleUtilities as SampleUtilities
16+
17+
import importlib
18+
sys.path.append(os.path.realpath('../modules'))
19+
client_module = importlib.import_module('RestApiClient')
20+
SampleUtilities = importlib.import_module('SampleUtilities')
1921

2022

2123
def main():
2224
# Create our client.
23-
client = RestApiClient(version='3.0')
25+
client = client_module.RestApiClient(version='5.0')
2426

2527
# Using the /asset_model/savedsearches endpoint with a GET request.
2628
SampleUtilities.pretty_print_request(client, 'asset_model/saved_searches',

asset_model/04_SearchAssets.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@
1616

1717
import sys
1818
import os
19-
sys.path.append(os.path.realpath('../modules'))
2019
import json
21-
from RestApiClient import RestApiClient
22-
import SampleUtilities as SampleUtilities
20+
21+
import importlib
22+
sys.path.append(os.path.realpath('../modules'))
23+
client_module = importlib.import_module('RestApiClient')
24+
SampleUtilities = importlib.import_module('SampleUtilities')
2325

2426

2527
def main():
2628
# Create our client.
27-
client = RestApiClient(version='3.0')
29+
client = client_module.RestApiClient(version='5.0')
2830

2931
# Using the /asset_model/properties endpoint with a GET request.
3032
SampleUtilities.pretty_print_request(client, 'asset_model/saved_searches',
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env python3
2+
# This sample demonstrates how to use the GET analytics/custom_actions
3+
# /interpreters endpoint in the REST API.
4+
5+
# The scenario demonstrates the following actions:
6+
# - How to get all custom action interpreters.
7+
# - How to retrieve specific custom action interpreters.
8+
9+
# To view a list of the endpoints with the parameters they accept, you can view
10+
# the REST API interactive help page on your deployment at
11+
# https://<hostname>/api_doc. You can also retrieve a list of available
12+
# endpoints with the REST API itself at the /api/help/capabilities endpoint.
13+
import json
14+
import sys
15+
import os
16+
17+
import importlib
18+
sys.path.append(os.path.realpath('../modules'))
19+
client_module = importlib.import_module('RestApiClient')
20+
SampleUtilities = importlib.import_module('SampleUtilities')
21+
22+
23+
def main():
24+
# Create our client.
25+
restClient = client_module.RestApiClient(version='5.0')
26+
# Endpoint used in this sample.
27+
interpreter_endpoint = 'analytics/custom_actions/interpreters'
28+
# Using the analytics/custom_actions/interpreters
29+
# endpoint with GET request.
30+
SampleUtilities.pretty_print_request(restClient,
31+
interpreter_endpoint,
32+
'GET')
33+
# Getting collection of available interpreters.
34+
response = restClient.call_api(interpreter_endpoint, 'GET')
35+
# Checking for a successful response code.
36+
if (response.code != 200):
37+
print('Failed to retrieve custom action interpreter list')
38+
SampleUtilities.pretty_print_response(response)
39+
sys.exit(1)
40+
# Extracting interpreters from response.
41+
response_body = json.loads(response.read().decode('utf-8'))
42+
total_retrieved = len(response_body)
43+
# Print total interpreters received.
44+
print(str(total_retrieved) +
45+
' custom action interpreters were retrieved')
46+
47+
interpreter_id = None
48+
49+
if (total_retrieved > 0):
50+
51+
print("Retrieved interpreters:\n")
52+
format_str = 'id=[{0}], name=[{1}]'
53+
# Iterating over retrieved interpreters.
54+
for interpreter in response_body:
55+
inter_id = str(interpreter['id'])
56+
inter_name = str(interpreter['name'])
57+
58+
print(format_str.format(inter_id, inter_name))
59+
interpreter_id = inter_id
60+
61+
print()
62+
63+
# Demonstrating getting specific custom action interpreters using
64+
# an id retrieved from the previous call.
65+
if (interpreter_id is not None):
66+
# Appending interpreter endpoint with id received earlier.
67+
interpreter_endpoint += '/' + interpreter_id
68+
SampleUtilities.pretty_print_request(restClient,
69+
interpreter_endpoint,
70+
'GET')
71+
# Getting specific interpreter
72+
response = restClient.call_api(interpreter_endpoint,
73+
'GET')
74+
# Checking for a successful response code.
75+
if (response.code != 200):
76+
print('Failed to retrieve custom action interpreter with id ' +
77+
interpreter_id)
78+
SampleUtilities.pretty_print_response(response)
79+
sys.exit(1)
80+
# Extracting interpreter from response.
81+
response_body = json.loads(response.read().decode('utf-8'))
82+
print('Successfully retrieved custom action interpreter with id ' +
83+
str(response_body['id']))
84+
85+
if __name__ == "__main__":
86+
main()
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env python3
2+
# This sample demonstrates how to use the GET analytics/custom_actions/scripts
3+
# endpoint in the REST API.
4+
5+
# For this scenario to work there must already be custom action scripts on the
6+
# system the sample is being run against.
7+
# The scenario demonstrates the following actions:
8+
# - How to get all custom action scripts
9+
# - How to retrieve specific custom action scripts
10+
11+
# To view a list of the endpoints with the parameters they accept, you can view
12+
# the REST API interactive help page on your deployment at
13+
# https://<hostname>/api_doc. You can also retrieve a list of available
14+
# endpoints with the REST API itself at the /api/help/capabilities endpoint.
15+
16+
import sys
17+
import os
18+
import json
19+
20+
import importlib
21+
sys.path.append(os.path.realpath('../modules'))
22+
client_module = importlib.import_module('RestApiClient')
23+
SampleUtilities = importlib.import_module('SampleUtilities')
24+
25+
26+
def main():
27+
# Create our client.
28+
restClient = client_module.RestApiClient(version='5.0')
29+
# Endpoint used in this sample.
30+
scripts_endpoint = 'analytics/custom_actions/scripts'
31+
# Using the analytics/custom_actions/scripts endpoint with GET request.
32+
SampleUtilities.pretty_print_request(restClient,
33+
scripts_endpoint,
34+
'GET')
35+
# Calling endpoint to get all available scripts.
36+
response = restClient.call_api(scripts_endpoint, 'GET')
37+
38+
# Checking for a successful response code.
39+
if (response.code != 200):
40+
print('Failed to retrieve custom action script list')
41+
SampleUtilities.pretty_print_response(response)
42+
sys.exit(1)
43+
# Extract the script metadata from the response.
44+
response_body = json.loads(response.read().decode('utf-8'))
45+
total_retrieved = len(response_body)
46+
# Print total received
47+
print(str(total_retrieved) + ' custom action scripts were retrieved')
48+
49+
script_id = None
50+
51+
if (total_retrieved > 0):
52+
53+
print('Retrieved scripts:\n')
54+
format_str = 'id=[{0}], file name=[{1}]'
55+
# Iterating over each script received.
56+
for script in response_body:
57+
58+
retrieved_id = str(script['id'])
59+
file_name = str(script['file_name'])
60+
61+
print(format_str.format(retrieved_id, file_name))
62+
# Setting for use later with the /scripts/{id}
63+
# endpoint.
64+
script_id = script['id']
65+
66+
print()
67+
68+
# Demonstrating getting specific scripts using
69+
# an id retrieved from the previous call.
70+
if (script_id is not None):
71+
scripts_endpoint += '/' + str(script_id)
72+
SampleUtilities.pretty_print_request(restClient,
73+
scripts_endpoint,
74+
'GET')
75+
response = restClient.call_api(scripts_endpoint,
76+
'GET')
77+
# Checking for a successful response code.
78+
if (response.code != 200):
79+
print('Failed to retrieve custom action script with id ' +
80+
script_id)
81+
SampleUtilities.pretty_print_response(response)
82+
sys.exit(1)
83+
# Extracting script from response.
84+
response_body = json.loads(response.read().decode('utf-8'))
85+
received_id = response_body['id']
86+
print('Successfully retrieved custom action script with id ' +
87+
str(received_id))
88+
89+
else:
90+
print('No available scripts found to demonstrate'
91+
'the GET /scripts/{id} endpoint.')
92+
93+
if __name__ == "__main__":
94+
main()
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env python3
2+
# This sample demonstrates how to use the GET analytics/custom_actions/actions
3+
# endpoint in the REST API.
4+
5+
# For this scenario to work there must already be custom actions on the system
6+
# the sample is being run against. The scenario demonstrates the following
7+
# actions:
8+
# - How to get all custom actions.
9+
# - How to retrieve specific custom actions
10+
11+
# To view a list of the endpoints with the parameters they accept, you can view
12+
# the REST API interactive help page on your deployment at
13+
# https://<hostname>/api_doc. You can also retrieve a list of available
14+
# endpoints with the REST API itself at the /api/help/capabilities endpoint.
15+
16+
import sys
17+
import os
18+
import json
19+
20+
import importlib
21+
sys.path.append(os.path.realpath('../modules'))
22+
client_module = importlib.import_module('RestApiClient')
23+
SampleUtilities = importlib.import_module('SampleUtilities')
24+
25+
26+
def main():
27+
# Create our client.
28+
restClient = client_module.RestApiClient(version='5.0')
29+
# Endpoint used in this endpoint.
30+
actions_endpoint = 'analytics/custom_actions/actions'
31+
# Using the analytics/custom_actions/actions endpoint with GET request.
32+
SampleUtilities.pretty_print_request(restClient,
33+
actions_endpoint,
34+
'GET')
35+
response = restClient.call_api(actions_endpoint,
36+
'GET')
37+
38+
# Verify that the call was successful.
39+
if (response.code != 200):
40+
print('Failed to retrieve custom action list')
41+
SampleUtilities.pretty_print_response(response)
42+
sys.exit(1)
43+
44+
response_body = json.loads(response.read().decode('utf-8'))
45+
total_retrieved = len(response_body)
46+
47+
print(str(total_retrieved) + ' custom actions were retrieved')
48+
49+
action_id = None
50+
51+
if (total_retrieved > 0):
52+
53+
print("Received custom actions:")
54+
format_str = 'id=[{0}], name=[{1}], param count=[{2}]\n'
55+
for action in response_body:
56+
received_id = str(action['id'])
57+
received_name = action['name']
58+
param_count = str(len(action['parameters']))
59+
print(format_str.format(received_id, received_name, param_count))
60+
# Setting value for use later with /actions/{id} endpoint.
61+
action_id = received_id
62+
print()
63+
64+
# Demonstrating getting specific custom action using an id
65+
# retrieved from the previous call
66+
if (action_id is not None):
67+
actions_endpoint += '/' + action_id
68+
SampleUtilities.pretty_print_request(restClient,
69+
actions_endpoint,
70+
'GET')
71+
# Calling API endpoint to get specific custom action
72+
response = restClient.call_api(actions_endpoint,
73+
'GET')
74+
# Checking for a successful response code
75+
if (response.code != 200):
76+
print('Failed to retrieve custom action with id ' + action_id)
77+
SampleUtilities.pretty_print_response(response)
78+
sys.exit(1)
79+
80+
response_body = json.loads(response.read().decode('utf-8'))
81+
response_id = str(response_body['id'])
82+
print('Successfully retrieved custom action with id ' + response_id)
83+
84+
else:
85+
# No custom actions found to use with the GET /actions/{id} endpoint
86+
print('No available custom actions found to demonstrate'
87+
' /actions/{id} endpoint.')
88+
89+
if __name__ == "__main__":
90+
main()

0 commit comments

Comments
 (0)