gam7 7.18.0__py3-none-any.whl → 7.18.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of gam7 might be problematic. Click here for more details.

gam/__init__.py CHANGED
@@ -25,7 +25,7 @@ https://github.com/GAM-team/GAM/wiki
25
25
  """
26
26
 
27
27
  __author__ = 'GAM Team <google-apps-manager@googlegroups.com>'
28
- __version__ = '7.18.00'
28
+ __version__ = '7.18.01'
29
29
  __license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
30
30
 
31
31
  #pylint: disable=wrong-import-position
@@ -16621,10 +16621,14 @@ def getRoleId():
16621
16621
  invalidChoiceExit(role, GM.Globals[GM.MAP_ROLE_NAME_TO_ID], True)
16622
16622
  return (role, roleId)
16623
16623
 
16624
+ PRINT_ADMIN_ROLES_FIELDS = ['roleId', 'roleName', 'roleDescription', 'isSuperAdminRole', 'isSystemRole']
16625
+
16624
16626
  # gam create adminrole <String> [description <String>]
16625
- # privileges all|all_ou|<PrivilegesList>|(select <FileSelector>|<CSVFileSelector>)
16627
+ # privileges all|all_ou|<PrivilegeList>|(select <FileSelector>|<CSVFileSelector>)|<JSONData>
16628
+ # [csv [todrive <ToDriveAttribute>*] [formatjson [quotechar <Character>]] (addcsvdata <FieldName> <String>)*]
16626
16629
  # gam update adminrole <RoleItem> [name <String>] [description <String>]
16627
- # [privileges all|all_ou|<PrivilegesList>|(select <FileSelector>|<CSVFileSelector>)]
16630
+ # [privileges all|all_ou|<PrivilegeList>|(select <FileSelector>|<CSVFileSelector>)|<JSONData>]
16631
+ # [csv [todrive <ToDriveAttribute>*] [formatjson [quotechar <Character>]] (addcsvdata <FieldName> <String>)*]
16628
16632
  def doCreateUpdateAdminRoles():
16629
16633
  def expandChildPrivileges(privilege):
16630
16634
  for childPrivilege in privilege.get('childPrivileges', []):
@@ -16641,6 +16645,9 @@ def doCreateUpdateAdminRoles():
16641
16645
  allPrivileges = {}
16642
16646
  ouPrivileges = {}
16643
16647
  childPrivileges = {}
16648
+ csvPF = None
16649
+ FJQC = FormatJSONQuoteChar(None)
16650
+ addCSVData = {}
16644
16651
  for privilege in _listPrivileges(cd):
16645
16652
  allPrivileges[privilege['privilegeName']] = privilege['serviceId']
16646
16653
  if privilege['isOuScopable']:
@@ -16654,6 +16661,8 @@ def doCreateUpdateAdminRoles():
16654
16661
  body['rolePrivileges'] = [{'privilegeName': p, 'serviceId': v} for p, v in allPrivileges.items()]
16655
16662
  elif privs == 'ALL_OU':
16656
16663
  body['rolePrivileges'] = [{'privilegeName': p, 'serviceId': v} for p, v in ouPrivileges.items()]
16664
+ elif privs == 'JSON':
16665
+ body['rolePrivileges'] = getJSON(['roleId', 'roleName', 'isAdminRole', 'isSystemRole']).get('rolePrivileges', [])
16657
16666
  else:
16658
16667
  if privs == 'SELECT':
16659
16668
  privsList = [p.upper() for p in getEntityList(Cmd.OB_PRIVILEGE_LIST)]
@@ -16675,25 +16684,59 @@ def doCreateUpdateAdminRoles():
16675
16684
  else:
16676
16685
  invalidChoiceExit(p, list(allPrivileges.keys())+list(ouPrivileges.keys())+list(childPrivileges.keys()), True)
16677
16686
  elif myarg == 'description':
16678
- body['roleDescription'] = getString(Cmd.OB_STRING)
16687
+ body['roleDescription'] = getString(Cmd.OB_STRING, minLen=0)
16679
16688
  elif myarg == 'name':
16680
16689
  body['roleName'] = getString(Cmd.OB_STRING)
16690
+ elif myarg == 'csv':
16691
+ csvPF = CSVPrintFile(PRINT_ADMIN_ROLES_FIELDS)
16692
+ FJQC.SetCsvPF(csvPF)
16693
+ elif csvPF and myarg == 'todrive':
16694
+ csvPF.GetTodriveParameters()
16695
+ elif csvPF and myarg == 'addcsvdata':
16696
+ k = getString(Cmd.OB_STRING)
16697
+ addCSVData[k] = getString(Cmd.OB_STRING, minLen=0)
16681
16698
  else:
16682
- unknownArgumentExit()
16699
+ FJQC.GetFormatJSONQuoteChar(myarg, True)
16683
16700
  if not updateCmd and not body.get('rolePrivileges'):
16684
16701
  missingArgumentExit('privileges')
16702
+ if csvPF:
16703
+ if addCSVData:
16704
+ csvPF.AddTitles(sorted(addCSVData.keys()))
16705
+ if not FJQC.formatJSON:
16706
+ csvPF.AddTitles('rolePrivileges')
16707
+ else:
16708
+ csvPF.AddJSONTitles(sorted(addCSVData.keys()))
16709
+ csvPF.MoveJSONTitlesToEnd(['JSON'])
16710
+ fieldsList = ','.join(PRINT_ADMIN_ROLES_FIELDS+['rolePrivileges'])
16711
+ else:
16712
+ fieldsList = 'roleId,roleName'
16685
16713
  try:
16686
16714
  if not updateCmd:
16687
16715
  result = callGAPI(cd.roles(), 'insert',
16688
16716
  throwReasons=[GAPI.BAD_REQUEST, GAPI.CUSTOMER_NOT_FOUND,
16689
16717
  GAPI.FORBIDDEN, GAPI.PERMISSION_DENIED]+[GAPI.DUPLICATE],
16690
- customer=GC.Values[GC.CUSTOMER_ID], body=body, fields='roleId,roleName')
16718
+ customer=GC.Values[GC.CUSTOMER_ID], body=body, fields=fieldsList)
16691
16719
  else:
16692
16720
  result = callGAPI(cd.roles(), 'patch',
16693
16721
  throwReasons=[GAPI.BAD_REQUEST, GAPI.CUSTOMER_NOT_FOUND,
16694
16722
  GAPI.FORBIDDEN, GAPI.PERMISSION_DENIED]+[GAPI.NOT_FOUND, GAPI.FAILED_PRECONDITION, GAPI.CONFLICT],
16695
- customer=GC.Values[GC.CUSTOMER_ID], roleId=roleId, body=body, fields='roleId,roleName')
16696
- entityActionPerformed([Ent.ADMIN_ROLE, f"{result['roleName']}({result['roleId']})"])
16723
+ customer=GC.Values[GC.CUSTOMER_ID], roleId=roleId, body=body, fields=fieldsList)
16724
+ if not csvPF:
16725
+ entityActionPerformed([Ent.ADMIN_ROLE, f"{result['roleName']}({result['roleId']})"])
16726
+ else:
16727
+ if not FJQC.formatJSON:
16728
+ if addCSVData:
16729
+ result.update(addCSVData)
16730
+ csvPF.WriteRowNoFilter(result)
16731
+ else:
16732
+ row = {}
16733
+ for field in PRINT_ADMIN_ROLES_FIELDS:
16734
+ if field in result:
16735
+ row[field] = result[field]
16736
+ if addCSVData:
16737
+ row.update(addCSVData)
16738
+ row['JSON'] = json.dumps(cleanJSON(result), ensure_ascii=False, sort_keys=True)
16739
+ csvPF.WriteRowNoFilter(row)
16697
16740
  except GAPI.duplicate as e:
16698
16741
  entityActionFailedWarning([Ent.ADMIN_ROLE, f"{body['roleName']}"], str(e))
16699
16742
  except (GAPI.notFound, GAPI.failedPrecondition, GAPI.conflict) as e:
@@ -16702,6 +16745,8 @@ def doCreateUpdateAdminRoles():
16702
16745
  accessErrorExit(cd)
16703
16746
  except (GAPI.forbidden, GAPI.permissionDenied) as e:
16704
16747
  ClientAPIAccessDeniedExit(str(e))
16748
+ if csvPF:
16749
+ csvPF.writeCSVfile('Admin Roles')
16705
16750
 
16706
16751
  # gam delete adminrole <RoleItem>
16707
16752
  def doDeleteAdminRole():
@@ -16721,9 +16766,10 @@ def doDeleteAdminRole():
16721
16766
  except (GAPI.forbidden, GAPI.permissionDenied) as e:
16722
16767
  ClientAPIAccessDeniedExit(str(e))
16723
16768
 
16724
- PRINT_ADMIN_ROLES_FIELDS = ['roleId', 'roleName', 'roleDescription', 'isSuperAdminRole', 'isSystemRole']
16725
-
16726
- def _showAdminRole(role, i=0, count=0):
16769
+ def _showAdminRole(role, FJQC, i=0, count=0):
16770
+ if FJQC.formatJSON:
16771
+ printLine(json.dumps(cleanJSON(role), ensure_ascii=False, sort_keys=True))
16772
+ return
16727
16773
  printEntity([Ent.ADMIN_ROLE, role['roleName']], i, count)
16728
16774
  Ind.Increment()
16729
16775
  for field in PRINT_ADMIN_ROLES_FIELDS:
@@ -16744,15 +16790,21 @@ def _showAdminRole(role, i=0, count=0):
16744
16790
  Ind.Decrement()
16745
16791
 
16746
16792
  # gam info adminrole <RoleItem> [privileges]
16793
+ # [formatjson]
16747
16794
  # gam print adminroles|roles [todrive <ToDriveAttribute>*]
16748
16795
  # [role <RoleItem>] [privileges] [oneitemperrow]
16796
+ # [nosystemroles]
16797
+ # [formatjson [quotechar <Character>]]
16749
16798
  # gam show adminroles|roles
16750
16799
  # [role <RoleItem>] [privileges]
16800
+ # [nosystemroles]
16801
+ # [formatjson]
16751
16802
  def doInfoPrintShowAdminRoles():
16752
16803
  cd = buildGAPIObject(API.DIRECTORY)
16753
16804
  fieldsList = PRINT_ADMIN_ROLES_FIELDS[:]
16754
16805
  csvPF = CSVPrintFile(fieldsList, PRINT_ADMIN_ROLES_FIELDS) if Act.csvFormat() else None
16755
- oneItemPerRow = False
16806
+ FJQC = FormatJSONQuoteChar(csvPF)
16807
+ noSystemRoles = oneItemPerRow = False
16756
16808
  if Act.Get() != Act.INFO:
16757
16809
  roleId = None
16758
16810
  else:
@@ -16767,13 +16819,17 @@ def doInfoPrintShowAdminRoles():
16767
16819
  fieldsList.append('rolePrivileges')
16768
16820
  elif myarg == 'oneitemperrow':
16769
16821
  oneItemPerRow = True
16822
+ elif myarg == 'nosystemroles':
16823
+ noSystemRoles = True
16770
16824
  else:
16771
- unknownArgumentExit()
16772
- if csvPF and 'rolePrivileges' in fieldsList:
16773
- if not oneItemPerRow:
16774
- csvPF.AddTitles(['rolePrivileges'])
16775
- else:
16776
- csvPF.AddTitles(['privilegeName', 'serviceId'])
16825
+ FJQC.GetFormatJSONQuoteChar(myarg, True)
16826
+ if csvPF:
16827
+ if 'rolePrivileges' in fieldsList:
16828
+ if not oneItemPerRow:
16829
+ if not FJQC.formatJSON:
16830
+ csvPF.AddTitles(['rolePrivileges'])
16831
+ else:
16832
+ csvPF.AddTitles(['privilegeName', 'serviceId'])
16777
16833
  try:
16778
16834
  if roleId is None:
16779
16835
  fields = getItemFieldsFromFieldsList('items', fieldsList)
@@ -16783,6 +16839,8 @@ def doInfoPrintShowAdminRoles():
16783
16839
  throwReasons=[GAPI.BAD_REQUEST, GAPI.CUSTOMER_NOT_FOUND,
16784
16840
  GAPI.FORBIDDEN, GAPI.PERMISSION_DENIED],
16785
16841
  customer=GC.Values[GC.CUSTOMER_ID], fields=fields)
16842
+ if noSystemRoles:
16843
+ roles = [role for role in roles if not role.get('isSystemRole', False)]
16786
16844
  else:
16787
16845
  fields = getFieldsFromFieldsList(fieldsList)
16788
16846
  roles = [callGAPI(cd.roles(), 'get',
@@ -16801,23 +16859,38 @@ def doInfoPrintShowAdminRoles():
16801
16859
  role.setdefault('isSystemRole', False)
16802
16860
  if not csvPF:
16803
16861
  count = len(roles)
16804
- performActionNumItems(count, Ent.ADMIN_ROLE)
16862
+ if not FJQC.formatJSON:
16863
+ performActionNumItems(count, Ent.ADMIN_ROLE)
16805
16864
  Ind.Increment()
16806
16865
  i = 0
16807
16866
  for role in roles:
16808
16867
  i += 1
16809
- _showAdminRole(role, i, count)
16868
+ _showAdminRole(role, FJQC, i, count)
16810
16869
  Ind.Decrement()
16811
16870
  else:
16812
16871
  for role in roles:
16813
16872
  if not oneItemPerRow or 'rolePrivileges' not in role:
16814
- csvPF.WriteRowTitles(flattenJSON(role))
16873
+ row = flattenJSON(role)
16874
+ if not FJQC.formatJSON:
16875
+ csvPF.WriteRowTitles(row)
16876
+ elif csvPF.CheckRowTitles(row):
16877
+ row = {}
16878
+ for field in PRINT_ADMIN_ROLES_FIELDS:
16879
+ if field in role:
16880
+ row[field] = role[field]
16881
+ row['JSON'] = json.dumps(cleanJSON(role), ensure_ascii=False, sort_keys=True)
16882
+ csvPF.WriteRowNoFilter(row)
16815
16883
  else:
16816
16884
  privileges = role.pop('rolePrivileges')
16817
16885
  baserow = flattenJSON(role)
16818
16886
  for privilege in privileges:
16819
16887
  row = flattenJSON(privilege, flattened=baserow.copy())
16820
- csvPF.WriteRowTitles(row)
16888
+ if not FJQC.formatJSON:
16889
+ csvPF.WriteRowTitles(row)
16890
+ elif csvPF.CheckRowTitles(row):
16891
+ row = baserow.copy()
16892
+ row['JSON'] = json.dumps(cleanJSON(privilege), ensure_ascii=False, sort_keys=True)
16893
+ csvPF.WriteRowNoFilter(row)
16821
16894
  if csvPF:
16822
16895
  csvPF.writeCSVfile('Admin Roles')
16823
16896
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gam7
3
- Version: 7.18.0
3
+ Version: 7.18.1
4
4
  Summary: CLI tool to manage Google Workspace
5
5
  Project-URL: Homepage, https://github.com/GAM-team/GAM
6
6
  Project-URL: Issues, https://github.com/GAM-team/GAM/issues
@@ -1,4 +1,4 @@
1
- gam/__init__.py,sha256=DMC0tmRDq8JqQ7Kc2CK5ymMsHWOgZng1cCK7YdmqDos,3571907
1
+ gam/__init__.py,sha256=LLcHrGsoakwCpuZYjaorAZYoRB8twyEGao6HIQA-gQg,3574736
2
2
  gam/__main__.py,sha256=amz0-959ph6zkZKqjaar4n60yho-T37w6qWI36qx0CA,1049
3
3
  gam/cacerts.pem,sha256=82Ak7btW_2XvocLUvAwPmpx8Chi0oqtZUG1gseLK_t4,50235
4
4
  gam/cbcm-v1.1beta1.json,sha256=xO5XloCQQULmPbFBx5bckdqmbLFQ7sJ2TImhE1ysDIY,19439
@@ -65,8 +65,8 @@ gam/googleapiclient/discovery_cache/base.py,sha256=yCDPtxnbNN-p5_9fzBacC6P3wcUPl
65
65
  gam/googleapiclient/discovery_cache/file_cache.py,sha256=sim3Mg4HgRYo3vX75jvcKy_aV568EvIrtBfvfbw-044,4774
66
66
  gam/iso8601/__init__.py,sha256=Z2PsYbXgAH5a5xzUvgczCboPzqWpm65kRcIngCnhViU,1218
67
67
  gam/iso8601/iso8601.py,sha256=Li2FHZ4sBTWuthuQhyCvmvj0j6At8JbGzkSv2fc2RHU,4384
68
- gam7-7.18.0.dist-info/METADATA,sha256=u2F6l-eY5Cb3JSoGvcvwRMx96Ca9_eImZ-bAhUdmJSk,2940
69
- gam7-7.18.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
70
- gam7-7.18.0.dist-info/entry_points.txt,sha256=HVUM5J7dA8YwvJfG30jiLefR19ExMs387TWugWd9sf4,42
71
- gam7-7.18.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
72
- gam7-7.18.0.dist-info/RECORD,,
68
+ gam7-7.18.1.dist-info/METADATA,sha256=nKF2U5OFqxRrUcplrUrgwTDQgDuGQNDKq-NiF35fUmU,2940
69
+ gam7-7.18.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
70
+ gam7-7.18.1.dist-info/entry_points.txt,sha256=HVUM5J7dA8YwvJfG30jiLefR19ExMs387TWugWd9sf4,42
71
+ gam7-7.18.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
72
+ gam7-7.18.1.dist-info/RECORD,,
File without changes