Skip to content

Commit

Permalink
Updated gam info|print|show policies to make additional API calls f…
Browse files Browse the repository at this point in the history
…or `settings/workspace_marketplace.apps_allowlist`
  • Loading branch information
taers232c committed Oct 27, 2024
1 parent 4d8c8c1 commit b269c2b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/winget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: vedantmgoyal2009/winget-releaser@v2
with:
identifier: taers232c.GAMADV-XTD3
release-tag: v7.00.30
release-tag: v7.00.31
max-versions-to-keep: 1 # keep only latest versions
installers-regex: '\.msi$'
token: ${{ secrets.WINGET_TOKEN }}
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ script:

before_deploy:
# Comment out for Linux Xenial and Trusty
#- yes | gem update --system --force
#- gem install bundler
#- gem install uri
#- gem install logger
- yes | gem update --system --force
- gem install bundler
- gem install uri
- gem install logger
- export TRAVIS_TAG="preview"
- unset LD_LIBRARY_PATH

Expand All @@ -111,10 +111,10 @@ deploy:
skip_cleanup: true
draft: true
# Linux 64-Bit Bionic and Linux ARM64 Focal and Linux ARM64 Bionic and Linux ARM64 Xenial
# edge: true
edge: true
# Linux Xenial and Trusty
edge:
branch: v2.0.3-beta.4
# edge:
# branch: v2.0.3-beta.4
# branch: v2.0.5-beta.1
on:
repo: taers232c/GAMADV-XTD3
Expand Down
6 changes: 3 additions & 3 deletions src/GamCommands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4076,14 +4076,14 @@ gam update deviceuserstate <DeviceUserEntity> [clientid <String>]
# Cloud Identity Policies

gam info policies <CIPolicyNameEntity>
[nowarnings]
[nowarnings] [noappnames]
[formatjson]

gam print policies [todrive <ToDriveAttribute>*]
[filter <String>] [nowarnings]
[filter <String>] [nowarnings] [noappnames]
[formatjson [quotechar <Character>]]
gam show policies
[filter <String>] [nowarnings]
[filter <String>] [nowarnings] [noappnames]
[formatjson]

# Inbound SSO
Expand Down
5 changes: 5 additions & 0 deletions src/GamUpdate.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
7.00.31

Updated `gam info|print|show policies` to make additional API calls for `settings/workspace_marketplace.apps_allowlist`
to get the application name for the application ID. Use option `noappnames` to suppress these calls.

7.00.30

Added command to display selected Cloud Identity policies.
Expand Down
45 changes: 37 additions & 8 deletions src/gam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"""

__author__ = 'Ross Scroggs <ross.scroggs@gmail.com>'
__version__ = '7.00.30'
__version__ = '7.00.31'
__license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'

#pylint: disable=wrong-import-position
Expand Down Expand Up @@ -35097,10 +35097,32 @@ def updateFieldsForCIGroupMatchPatterns(matchPatterns, fieldsList, csvPF=None):
}
}

def _cleanPolicy(policy, add_warnings, cd, groups_ci):
def _getPolicyAppNameFromId(httpObj, app):
app['applicationName'] = UNKNOWN
appId = app['applicationId']
url = f'https://workspace.google.com/marketplace/app/_/{appId}'
try:
resp, content = httpObj.request(url, 'GET')
except:
return
if resp.status != 200:
return
if isinstance(content, bytes):
content = content.decode()
pattern = f'https://workspace.google.com/marketplace/app/(.+?)/{appId}'
a = re.search(pattern, content)
if a:
app['applicationName'] = a.group(1)

def _cleanPolicy(policy, add_warnings, no_appnames, cd, groups_ci):
# convert any wordlists into spaced strings to reduce output complexity
if policy['setting']['type'] == 'settings/detector.word_list':
policy['setting']['value']['wordList'] = ' '.join(policy['setting']['value']['wordList']['words'])
# get application name for application id
if policy['setting']['type'] == 'settings/workspace_marketplace.apps_allowlist' and not no_appnames:
httpObj = getHttpObj(timeout=10)
for app in policy['setting']['value'].get('apps', []):
_getPolicyAppNameFromId(httpObj, app)
# add any warnings to applicable policies
if add_warnings and policy['setting']['type'] in CIPOLICY_ADDITIONAL_WARNINGS:
policy['warning'] = CIPOLICY_ADDITIONAL_WARNINGS[policy['setting']['type']]
Expand All @@ -35125,18 +35147,22 @@ def _showPolicy(policy, FJQC, i=0, count=0):
Ind.Decrement()

# gam info policies <CIPolicyNameEntity>
# [nowarnings] [formatjson]
# [nowarnings] [noappnames]
# [formatjson]
def doInfoCIPolicies():
groups_ci = buildGAPIObject(API.CLOUDIDENTITY_GROUPS)
ci = buildGAPIObject(API.CLOUDIDENTITY_POLICY)
cd = buildGAPIObject(API.DIRECTORY)
entityList = getEntityList(Cmd.OB_CIPOLICY_NAME_ENTITY)
FJQC = FormatJSONQuoteChar()
add_warnings = True
no_appnames = False
while Cmd.ArgumentsRemaining():
myarg = getArgument()
if myarg == 'nowarnings':
add_warnings = False
elif myarg == 'noappnames':
no_appnames=True
else:
FJQC.GetFormatJSON(myarg)
i = 0
Expand All @@ -35151,17 +35177,17 @@ def doInfoCIPolicies():
throwReasons=[GAPI.INVALID, GAPI.INVALID_ARGUMENT, GAPI.PERMISSION_DENIED, GAPI.INTERNAL_ERROR],
name=pname,
fields='name,policyQuery(group,orgUnit,sortOrder),type,setting')
_cleanPolicy(policy, add_warnings, cd, groups_ci)
_cleanPolicy(policy, add_warnings, no_appnames, cd, groups_ci)
_showPolicy(policy, FJQC, i, count)
except (GAPI.invalid, GAPI.invalidArgument, GAPI.permissionDenied, GAPI.internalError) as e:
entityActionFailedWarning([Ent.POLICY, pname], str(e), i, count)
continue

# gam print policies [todrive <ToDriveAttribute>*]
# [filter <String>] [nowarnings]
# [filter <String>] [nowarnings] [noappnames]
# [formatjson [quotechar <Character>]]
# gam show policies
# [filter <String>] [nowarnings]
# [filter <String>] [nowarnings] [noappnames]
# [formatjson]
def doPrintShowCIPolicies():

Expand All @@ -35182,6 +35208,7 @@ def _printPolicy(policy):
FJQC = FormatJSONQuoteChar(csvPF)
ifilter = None
add_warnings = True
no_appnames = False
while Cmd.ArgumentsRemaining():
myarg = getArgument()
if csvPF and myarg == 'todrive':
Expand All @@ -35190,6 +35217,8 @@ def _printPolicy(policy):
ifilter = getString(Cmd.OB_STRING)
elif myarg == 'nowarnings':
add_warnings = False
elif myarg == 'noappnames':
no_appnames=True
else:
FJQC.GetFormatJSONQuoteChar(myarg, True)
printGettingAllAccountEntities(Ent.POLICY, ifilter)
Expand All @@ -35212,12 +35241,12 @@ def _printPolicy(policy):
i = 0
for policy in policies:
i += 1
_cleanPolicy(policy, add_warnings, cd, groups_ci)
_cleanPolicy(policy, add_warnings, no_appnames, cd, groups_ci)
_showPolicy(policy, FJQC, i, count)
Ind.Decrement()
else:
for policy in policies:
_cleanPolicy(policy, add_warnings, cd, groups_ci)
_cleanPolicy(policy, add_warnings, no_appnames, cd, groups_ci)
_printPolicy(policy)
if csvPF:
csvPF.writeCSVfile('Policies')
Expand Down

0 comments on commit b269c2b

Please sign in to comment.