mirror of
https://github.com/GAM-team/GAM.git
synced 2025-07-09 14:13:35 +00:00
Update policies and user invitations (#1339)
* Update policies and user invitations Show chrome policy schemas in sorted order Change create userintervention to send userintervention to be consistent with API Add state and orderby option to print userinvitations * Sort polices in show chromepolicies
This commit is contained in:
@ -1337,11 +1337,13 @@ gam print group-members|groups-members [todrive]
|
||||
[roles <GroupRoleList>] [membernames] [fields <MembersFieldNameList>]
|
||||
[includederivedmembership]
|
||||
|
||||
gam create userinvitation <EmailAddress>
|
||||
gam send userinvitation <EmailAddress>
|
||||
gam cancel userinvitation <EmailAddress>
|
||||
gam check userinvitation|isinvitable <EmailAddress>
|
||||
gam info userinvitation <EmailAddress>
|
||||
gam print userinvitations [todrive] [filter <String>]
|
||||
gam print userinvitations [todrive]
|
||||
[state notyetsent|invited|accepted|declined]]
|
||||
[orderby email|updatetime [ascending|descending]]
|
||||
gam <UserTypeEntity> check isinvitable [todrive]
|
||||
|
||||
gam print licenses [todrive] [(products|product <ProductIDList>)|(skus|sku <SKUIDList>)|allskus|gsuite] [countsonly]
|
||||
|
@ -11186,8 +11186,6 @@ def ProcessGAMCommand(args):
|
||||
gapi_directory_roles.create()
|
||||
elif argument in ['browsertoken', 'browsertokens']:
|
||||
gapi_cbcm.createtoken()
|
||||
elif argument in ['userinvitation', 'userinvitations']:
|
||||
gapi_cloudidentity_userinvitations.send()
|
||||
elif argument in ['printer']:
|
||||
gapi_directory_printers.create()
|
||||
else:
|
||||
@ -11498,6 +11496,13 @@ def ProcessGAMCommand(args):
|
||||
else:
|
||||
controlflow.invalid_argument_exit(argument, 'gam print')
|
||||
sys.exit(0)
|
||||
elif command == 'send':
|
||||
argument = sys.argv[2].lower()
|
||||
if argument in ['userinvitation', 'userinvitations']:
|
||||
gapi_cloudidentity_userinvitations.send()
|
||||
else:
|
||||
controlflow.invalid_argument_exit(argument, 'gam send')
|
||||
sys.exit(0)
|
||||
elif command == 'show':
|
||||
argument = sys.argv[2].lower()
|
||||
if argument in ['schema', 'schemas']:
|
||||
@ -11512,9 +11517,9 @@ def ProcessGAMCommand(args):
|
||||
doShowServiceAccountKeys()
|
||||
elif argument in ['browsertoken', 'browsertokens']:
|
||||
gapi_cbcm.printshowtokens(False)
|
||||
elif argument == 'chromeschema':
|
||||
elif argument in ['chromeschema', 'chromeschemas']:
|
||||
gapi_chromepolicy.printshow_schemas()
|
||||
elif argument == 'chromepolicy':
|
||||
elif argument in ['chromepolicy', 'chromepolicies']:
|
||||
gapi_chromepolicy.printshow_policies()
|
||||
else:
|
||||
controlflow.invalid_argument_exit(argument, 'gam show')
|
||||
|
@ -86,7 +86,7 @@ def printshow_policies():
|
||||
body=body)
|
||||
except googleapiclient.errors.HttpError:
|
||||
policies = []
|
||||
for policy in policies:
|
||||
for policy in sorted(policies, key=lambda k: k.get('value', {}).get('policySchema', '')):
|
||||
name = policy.get('value', {}).get('policySchema', '')
|
||||
print(name)
|
||||
values = policy.get('value', {}).get('value', {})
|
||||
@ -169,7 +169,7 @@ def printshow_schemas():
|
||||
msg = f'{myarg} is not a valid argument to "gam print chromeschema"'
|
||||
controlflow.system_error_exit(3, msg)
|
||||
schemas = build_schemas(svc, sfilter)
|
||||
for value in schemas.values():
|
||||
for _, value in sorted(iter(schemas.items())):
|
||||
print(f'{value.get("name")}: {value.get("description")}')
|
||||
for val in value['settings'].values():
|
||||
vtype = val.get('type')
|
||||
|
@ -4,7 +4,8 @@ from urllib.parse import quote_plus
|
||||
|
||||
import googleapiclient
|
||||
|
||||
from gam.var import GC_CUSTOMER_ID, GC_Values, MY_CUSTOMER
|
||||
import gam
|
||||
from gam.var import GC_CUSTOMER_ID, GC_Values, MY_CUSTOMER, SORTORDER_CHOICES_MAP
|
||||
from gam import controlflow
|
||||
from gam import display
|
||||
from gam import gapi
|
||||
@ -114,31 +115,77 @@ def send():
|
||||
_generic_action('send')
|
||||
|
||||
|
||||
USERINVITATION_ORDERBY_CHOICES_MAP = {
|
||||
'email': 'email',
|
||||
'updatetime': 'update_time',
|
||||
}
|
||||
|
||||
USERINVITATION_STATE_CHOICES_MAP = {
|
||||
'accepted': 'ACCEPTED',
|
||||
'declined': 'DECLINED',
|
||||
'invited': 'INVITED',
|
||||
'notyetsent': 'NOT_YET_SENT',
|
||||
}
|
||||
|
||||
def print_():
|
||||
'''gam print userinvitations'''
|
||||
svc = gapi_cloudidentity.build('cloudidentity_beta')
|
||||
customer = _get_customerid()
|
||||
todrive = False
|
||||
titles = []
|
||||
titles = ['name', 'state', 'updateTime']
|
||||
rows = []
|
||||
filter_ = None
|
||||
orderByList = []
|
||||
i = 3
|
||||
while i < len(sys.argv):
|
||||
myarg = sys.argv[i].lower().replace('_', '')
|
||||
if myarg == 'filter':
|
||||
filter_ = sys.argv[i+1]
|
||||
if myarg == 'state':
|
||||
state = sys.argv[i + 1].lower().replace('_', '')
|
||||
if state in USERINVITATION_STATE_CHOICES_MAP:
|
||||
filter_ = f"state=='{USERINVITATION_STATE_CHOICES_MAP[state]}'"
|
||||
else:
|
||||
controlflow.expected_argument_exit('state',
|
||||
', '.join(USERINVITATION_STATE_CHOICES_MAP),
|
||||
state)
|
||||
i += 2
|
||||
elif myarg == 'orderby':
|
||||
fieldName = sys.argv[i + 1].lower()
|
||||
i += 2
|
||||
if fieldName in USERINVITATION_ORDERBY_CHOICES_MAP:
|
||||
fieldName = USERINVITATION_ORDERBY_CHOICES_MAP[fieldName]
|
||||
orderBy = ''
|
||||
if i < len(sys.argv):
|
||||
orderBy = sys.argv[i].lower()
|
||||
if orderBy in SORTORDER_CHOICES_MAP:
|
||||
orderBy = SORTORDER_CHOICES_MAP[orderBy]
|
||||
i += 1
|
||||
if orderBy != 'DESCENDING':
|
||||
orderByList.append(fieldName)
|
||||
else:
|
||||
orderByList.append(f'{fieldName} desc')
|
||||
else:
|
||||
controlflow.expected_argument_exit(
|
||||
'orderby', ', '.join(sorted(USERINVITATION_ORDERBY_CHOICES_MAP)),
|
||||
fieldName)
|
||||
elif myarg == 'todrive':
|
||||
todrive = True
|
||||
i += 1
|
||||
else:
|
||||
controlflow.invalid_argument_exit(sys.argv[i],
|
||||
'gam print userinvitations')
|
||||
if orderByList:
|
||||
orderBy = ' '.join(orderByList)
|
||||
else:
|
||||
orderBy = None
|
||||
gam.printGettingAllItems('User Invitations', filter_)
|
||||
page_message = gapi.got_total_items_msg('User Invitations', '...\n')
|
||||
invitations = gapi.get_all_pages(svc.customers().userinvitations(),
|
||||
'list',
|
||||
'userInvitations',
|
||||
page_message=page_message,
|
||||
parent=customer,
|
||||
filter=filter_)
|
||||
filter=filter_,
|
||||
orderBy=orderBy)
|
||||
for invitation in invitations:
|
||||
invitation['name'] = _reduce_name(invitation['name'])
|
||||
row = {}
|
||||
|
Reference in New Issue
Block a user