|
| 1 | +# Copyright 2024 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +"""Google Cloud Anti Money Laundering AI sample for listing the Cloud locations |
| 16 | + of the API. |
| 17 | +Example usage: |
| 18 | + python list_locations.py --project_id <project-id> |
| 19 | +""" |
| 20 | + |
| 21 | +# [START antimoneylaunderingai_list_locations] |
| 22 | + |
| 23 | +import argparse |
| 24 | +import os |
| 25 | + |
| 26 | +import google.auth |
| 27 | +from google.auth.transport import requests |
| 28 | + |
| 29 | + |
| 30 | +def list_locations( |
| 31 | + project_id: str, |
| 32 | +) -> google.auth.transport.Response: |
| 33 | + """Lists the AML AI locations using the REST API.""" |
| 34 | + |
| 35 | + # TODO(developer): Uncomment these lines and replace with your values. |
| 36 | + # project_id = 'my-project' # The Google Cloud project ID. |
| 37 | + |
| 38 | + # Gets credentials from the environment. google.auth.default() returns credentials and the |
| 39 | + # associated project ID, but in this sample, the project ID is passed in manually. |
| 40 | + credentials, _ = google.auth.default( |
| 41 | + scopes=[ |
| 42 | + "https://www.googleapis.com/auth/cloud-platform", |
| 43 | + ] |
| 44 | + ) |
| 45 | + authed_session = requests.AuthorizedSession(credentials) |
| 46 | + |
| 47 | + # URL to the AML AI API endpoint and version |
| 48 | + base_url = "https://financialservices.googleapis.com/v1" |
| 49 | + url = f"{base_url}/projects/{project_id}/locations/" |
| 50 | + # Sets required "application/json" header on the request |
| 51 | + headers = {"Content-Type": "application/json; charset=utf-8"} |
| 52 | + |
| 53 | + response = authed_session.get(url, headers=headers) |
| 54 | + response.raise_for_status() |
| 55 | + print(response.text) |
| 56 | + return response |
| 57 | + |
| 58 | + |
| 59 | +# [END antimoneylaunderingai_list_locations] |
| 60 | + |
| 61 | +if __name__ == "__main__": |
| 62 | + parser = argparse.ArgumentParser() |
| 63 | + parser.add_argument( |
| 64 | + "--project_id", |
| 65 | + default=(os.environ.get("GOOGLE_CLOUD_PROJECT")), |
| 66 | + help="Google Cloud project name", |
| 67 | + ) |
| 68 | + args = parser.parse_args() |
| 69 | + |
| 70 | + list_locations( |
| 71 | + args.project_id, |
| 72 | + ) |
0 commit comments