Skip to content

Commit c5bb5b6

Browse files
committed
minor Mod 21 updates
1 parent a3aa6b5 commit c5bb5b6

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

mod21a-idenplat/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Module 21 - Migrate from App Engine `users` to Cloud Identity Platform
22

33
This repo folder is the corresponding Python 2 code to the _forthcoming_ Module 21 codelab. The tutorial STARTs with the Python 2 code in the [Module 20 repo folder](/mod20-gaeusers) and leads developers through a migration to Cloud Identity Platform, culminating in the code in this (`mod21a-idenplat`) folder. Also included is a migration from App Engine `ndb` to Google Cloud NDB, mirroring the content covered in [Module 2](http://g.co/codelabs/pae-migrate-cloudndb). There is also a Python 3 version of the app in the [Module 21b](/mod21b-idenplat) folder.
4+
5+
NOTE: While we generally recommend using [Google Cloud client libraries](https://cloud.google.com/apis/docs/cloud-client-libraries) for GCP API access, we have an exception here because the [final Python 2 version](https://googleapis.dev/python/cloudresourcemanager/0.30.2) of the [Cloud Resource Manager client library](https://github.com/googleapis/python-resource-manager) (before the 2.x support was deprecated) did not have an implemented [get IAM policy](https://cloud.google.com/python/docs/reference/cloudresourcemanager/latest/google.cloud.resourcemanager_v3.services.projects.ProjectsClient#google_cloud_resourcemanager_v3_services_projects_ProjectsClient_get_iam_policy) feature, hence the need to use the [lower-level Google APIs client library](https://developers.google.com/api-client-library) to access this functionality from the API. See the [Python 3 `main.py`](/mod21b-idenplat/main.py) which uses latest Resource Manager client library.

mod21a-idenplat/main.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525

2626
def _get_gae_admins():
2727
'return set of App Engine admins'
28-
# setup constants for calling Cloud IAM Resource Manager API
28+
# setup constants for calling Cloud Resource Manager API
2929
CREDS, PROJ_ID = default( # Application Default Credentials and project ID
30-
['https://www.googleapis.com/auth/cloud-platform'])
30+
['https://www.googleapis.com/auth/cloudplatformprojects.readonly'])
3131
rm_client = discovery.build('cloudresourcemanager', 'v1', credentials=CREDS)
3232
_TARGETS = frozenset(( # App Engine admin roles
3333
'roles/viewer',
@@ -36,7 +36,7 @@ def _get_gae_admins():
3636
'roles/appengine.appAdmin',
3737
))
3838

39-
# collate all users who are members of at least one GAE admin role (_TARGETS)
39+
# collate users who are members of at least one GAE admin role (_TARGETS)
4040
admins = set() # set of all App Engine admins
4141
allow_policy = rm_client.projects().getIamPolicy(resource=PROJ_ID).execute()
4242
for b in allow_policy['bindings']: # bindings in IAM allow policy

mod21b-idenplat/main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
def _get_gae_admins():
2626
'return set of App Engine admins'
27-
# setup constants for calling Cloud IAM Resource Manager API
27+
# setup constants for calling Cloud Resource Manager API
2828
_, PROJ_ID = default( # Application Default Credentials and project ID
2929
['https://www.googleapis.com/auth/cloudplatformprojects.readonly'])
3030
rm_client = resourcemanager.ProjectsClient()
@@ -35,7 +35,7 @@ def _get_gae_admins():
3535
'roles/appengine.appAdmin',
3636
))
3737

38-
# collate all users who are members of at least one GAE admin role (_TARGETS)
38+
# collate users who are members of at least one GAE admin role (_TARGETS)
3939
admins = set() # set of all App Engine admins
4040
allow_policy = rm_client.get_iam_policy(resource='projects/%s' % PROJ_ID)
4141
for b in allow_policy.bindings: # bindings in IAM allow policy

0 commit comments

Comments
 (0)