Skip to content

Commit 5e958b5

Browse files
danieldeleoandrewsg
authored andcommitted
Adding ability to make reqeusts of all method types: GET, POST, PUT etc (GoogleCloudPlatform#1481)
1 parent 87af05c commit 5e958b5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

iap/make_iap_request.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@
3030
OAUTH_TOKEN_URI = 'https://www.googleapis.com/oauth2/v4/token'
3131

3232

33-
def make_iap_request(url, client_id):
33+
def make_iap_request(url, client_id, method='GET', **kwargs):
3434
"""Makes a request to an application protected by Identity-Aware Proxy.
3535
3636
Args:
3737
url: The Identity-Aware Proxy-protected URL to fetch.
3838
client_id: The client ID used by Identity-Aware Proxy.
39+
method: The request method to use
40+
('GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE')
41+
**kwargs: Any of the parameters defined for the request function:
42+
https://github.com/requests/requests/blob/master/requests/api.py
3943
4044
Returns:
4145
The page body, or raises an exception if the page couldn't be retrieved.
@@ -94,10 +98,10 @@ def make_iap_request(url, client_id):
9498
# Fetch the Identity-Aware Proxy-protected URL, including an
9599
# Authorization header containing "Bearer " followed by a
96100
# Google-issued OpenID Connect token for the service account.
97-
resp = requests.get(
98-
url,
101+
resp = requests.request(
102+
method, url,
99103
headers={'Authorization': 'Bearer {}'.format(
100-
google_open_id_connect_token)})
104+
google_open_id_connect_token)}, **kwargs)
101105
if resp.status_code == 403:
102106
raise Exception('Service account {} does not have permission to '
103107
'access the IAP-protected application.'.format(

0 commit comments

Comments
 (0)