Skip to content

Commit ab8cb1d

Browse files
APM-2488-Updated the test cases-print access token
1 parent 05397fc commit ab8cb1d

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

scripts/trigger_pipelines.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ def __init__(self):
1515
self.client_secret = os.environ["AZ_CLIENT_SECRET"]
1616
self.client_tenant = os.environ["AZ_CLIENT_TENANT"]
1717
self.access_token = self._get_access_token()
18-
self.token = self.access_token
19-
self.auth = requests.auth.HTTPBasicAuth("", self.token)
2018
self.notify_commit_sha = os.environ["NOTIFY_COMMIT_SHA"]
2119
self.utils_pr_number = os.environ["UTILS_PR_NUMBER"]
2220
self.notify_github_repo = "NHSDigital/api-management-utils"
@@ -46,7 +44,6 @@ def run_pipeline(self,
4644
method='post',
4745
)
4846
self.print_response(response, f"Initial request to {run_url}")
49-
print("Response Check In Pipeline Run", response.status_code)
5047

5148
result = "failed"
5249
if response.status_code == 200:
@@ -79,20 +76,6 @@ def _build_request_body(self, pipeline_branch: str):
7976
},
8077
"self": {"refName": f"{pipeline_branch}"},
8178
}
82-
},
83-
"variables": {
84-
"NOTIFY_GITHUB_REPOSITORY": {
85-
"isSecret ": False,
86-
"value": f"{self.notify_github_repo}",
87-
},
88-
"NOTIFY_COMMIT_SHA": {
89-
"isSecret ": False,
90-
"value": f"{self.notify_commit_sha}"
91-
},
92-
"UTILS_PR_NUMBER": {
93-
"isSecret ": False,
94-
"value": f"{self.utils_pr_number}",
95-
}
9679
}
9780
}
9881

@@ -107,6 +90,7 @@ def _get_access_token(self):
10790
headers = {"Content-Type": "application/x-www-form-urlencoded"}
10891
res = requests.post(url=url, data=data, headers=headers)
10992
res.raise_for_status()
93+
11094
return res.json()["access_token"]
11195

11296
def api_request(
@@ -121,11 +105,14 @@ def api_request(
121105
):
122106
def get_headers():
123107

124-
_headers = {"Accept": "application/json", "Authorization": f"Bearer {self.token}"}
108+
_headers = {"Accept": "application/json", "Authorization": f"Bearer {self.access_token}"}
125109
_headers.update(headers or {})
126110
return _headers
127111

128112
_params = {"api-version": api_version}
113+
_params = {"NOTIFY_GITHUB_REPOSITORY": self.notify_github_repo}
114+
_params = {"NOTIFY_COMMIT_SHA": self.notify_commit_sha}
115+
_params = {"UTILS_PR_NUMBER": self.utils_pr_number}
129116
_params.update(params or {})
130117
action = getattr(requests, method)
131118

@@ -139,7 +126,7 @@ def get_headers():
139126

140127
if result.status_code in (203, 401):
141128
print("REFRESHING ACCESS TOKEN...")
142-
self.token = self._get_access_token()
129+
self.access_token = self._get_access_token()
143130

144131
time.sleep(0.5 * tries)
145132
result = action(uri, params=_params, headers=get_headers(), **kwargs)

0 commit comments

Comments
 (0)