mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-04 21:01:36 +00:00
Phase 4a - remove boilerplate from cmds
This commit is contained in:
@@ -101,9 +101,7 @@ from cryptography.hazmat.primitives import hashes, serialization
|
|||||||
from cryptography.hazmat.primitives.asymmetric import rsa
|
from cryptography.hazmat.primitives.asymmetric import rsa
|
||||||
from cryptography.x509.oid import NameOID
|
from cryptography.x509.oid import NameOID
|
||||||
|
|
||||||
# 10/2024 - I don't recall why we did this but PyInstaller
|
# Add package directory to sys.path for source installs (not needed for frozen/PyInstaller builds)
|
||||||
# 6.10.0+ does not like it. Only run this when we're not
|
|
||||||
# Frozen.
|
|
||||||
if not getattr(sys, 'frozen', False):
|
if not getattr(sys, 'frozen', False):
|
||||||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
|
||||||
@@ -983,97 +981,6 @@ from gam.cmd.vault import (
|
|||||||
from gam.cmd.yubikey import doResetYubiKeyPIV
|
from gam.cmd.yubikey import doResetYubiKeyPIV
|
||||||
|
|
||||||
|
|
||||||
# gam.cmd.alerts
|
|
||||||
|
|
||||||
# gam.cmd.aliases
|
|
||||||
|
|
||||||
# gam.cmd.analytics
|
|
||||||
|
|
||||||
# gam.cmd.audit
|
|
||||||
|
|
||||||
# gam.cmd.browsers
|
|
||||||
|
|
||||||
# gam.cmd.caa
|
|
||||||
|
|
||||||
# gam.cmd.calendar
|
|
||||||
|
|
||||||
# gam.cmd.chat
|
|
||||||
|
|
||||||
# gam.cmd.chromeapps
|
|
||||||
|
|
||||||
# gam.cmd.chromepolicies
|
|
||||||
|
|
||||||
# gam.cmd.cidevices
|
|
||||||
|
|
||||||
# gam.cmd.cigroups
|
|
||||||
|
|
||||||
# gam.cmd.ciuserinvitations
|
|
||||||
|
|
||||||
# gam.cmd.cloudstorage
|
|
||||||
|
|
||||||
# gam.cmd.contacts
|
|
||||||
|
|
||||||
# gam.cmd.courses
|
|
||||||
|
|
||||||
# gam.cmd.cros
|
|
||||||
|
|
||||||
# gam.cmd.customer
|
|
||||||
|
|
||||||
# gam.cmd.datatransfer
|
|
||||||
|
|
||||||
# gam.cmd.delegates
|
|
||||||
|
|
||||||
# gam.cmd.domains
|
|
||||||
|
|
||||||
# gam.cmd.drive
|
|
||||||
|
|
||||||
# gam.cmd.gmail
|
|
||||||
|
|
||||||
# gam.cmd.groups
|
|
||||||
|
|
||||||
# gam.cmd.licenses
|
|
||||||
|
|
||||||
# gam.cmd.meet
|
|
||||||
|
|
||||||
# gam.cmd.mobile
|
|
||||||
|
|
||||||
# gam.cmd.notes
|
|
||||||
|
|
||||||
# gam.cmd.oauth
|
|
||||||
|
|
||||||
# gam.cmd.orgunits
|
|
||||||
|
|
||||||
# gam.cmd.people
|
|
||||||
|
|
||||||
# gam.cmd.printers
|
|
||||||
|
|
||||||
# gam.cmd.project
|
|
||||||
|
|
||||||
# gam.cmd.reports
|
|
||||||
|
|
||||||
# gam.cmd.reseller
|
|
||||||
|
|
||||||
# gam.cmd.resources
|
|
||||||
|
|
||||||
# gam.cmd.schemas
|
|
||||||
|
|
||||||
# gam.cmd.send_email
|
|
||||||
|
|
||||||
# gam.cmd.sites
|
|
||||||
|
|
||||||
# gam.cmd.sso
|
|
||||||
|
|
||||||
# gam.cmd.tasks
|
|
||||||
|
|
||||||
# gam.cmd.userop
|
|
||||||
|
|
||||||
# gam.cmd.users
|
|
||||||
|
|
||||||
# gam.cmd.userservices
|
|
||||||
|
|
||||||
# gam.cmd.vault
|
|
||||||
|
|
||||||
|
|
||||||
class LazyLoader(types.ModuleType):
|
class LazyLoader(types.ModuleType):
|
||||||
"""Lazily import a module, mainly to avoid pulling in large dependencies.
|
"""Lazily import a module, mainly to avoid pulling in large dependencies.
|
||||||
|
|
||||||
@@ -1891,14 +1798,12 @@ MAIN_COMMANDS_OBJ_ALIASES = {
|
|||||||
Cmd.ARG_VERIFICATION: Cmd.ARG_VERIFY,
|
Cmd.ARG_VERIFICATION: Cmd.ARG_VERIFY,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Audit command sub-commands with objects
|
|
||||||
|
|
||||||
from gam.cmd.audit import processAuditCommands
|
from gam.cmd.audit import processAuditCommands
|
||||||
from gam.cmd.oauth import processOauthCommands
|
from gam.cmd.oauth import processOauthCommands
|
||||||
from gam.cmd.calendar import processCalendarsCommands, processResourceCommands, processResourcesCommands
|
from gam.cmd.calendar import processCalendarsCommands, processResourceCommands, processResourcesCommands
|
||||||
from gam.cmd.courses.participants import processCourseCommands, processCoursesCommands
|
from gam.cmd.courses.participants import processCourseCommands, processCoursesCommands
|
||||||
|
|
||||||
# Commands
|
# Multi-step commands (audit, oauth, calendars, courses, resources)
|
||||||
COMMANDS_MAP = {
|
COMMANDS_MAP = {
|
||||||
'oauth': processOauthCommands,
|
'oauth': processOauthCommands,
|
||||||
'audit': processAuditCommands,
|
'audit': processAuditCommands,
|
||||||
@@ -1909,7 +1814,7 @@ COMMANDS_MAP = {
|
|||||||
'resources': processResourcesCommands,
|
'resources': processResourcesCommands,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Commands aliases
|
# Command name aliases
|
||||||
COMMANDS_ALIASES = {
|
COMMANDS_ALIASES = {
|
||||||
'oauth2': 'oauth',
|
'oauth2': 'oauth',
|
||||||
'calendar': 'calendars',
|
'calendar': 'calendars',
|
||||||
@@ -1969,7 +1874,6 @@ USER_COMMANDS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# User commands with objects
|
# User commands with objects
|
||||||
#
|
|
||||||
USER_ADD_CREATE_FUNCTIONS = {
|
USER_ADD_CREATE_FUNCTIONS = {
|
||||||
Cmd.ARG_CALENDAR: addCreateCalendars,
|
Cmd.ARG_CALENDAR: addCreateCalendars,
|
||||||
Cmd.ARG_GROUP: addUserToGroups,
|
Cmd.ARG_GROUP: addUserToGroups,
|
||||||
@@ -2860,7 +2764,7 @@ def ProcessGAMCommand(args, processGamCfg=True, inLoop=False, closeSTD=True):
|
|||||||
closeGAMCommandLog(GM.Globals)
|
closeGAMCommandLog(GM.Globals)
|
||||||
return GM.Globals[GM.SYSEXITRC]
|
return GM.Globals[GM.SYSEXITRC]
|
||||||
|
|
||||||
# Process GAM command
|
# Call GAM command (used by batch/loop to invoke sub-commands)
|
||||||
def CallGAMCommand(args, processGamCfg=True, inLoop=False, closeSTD=False):
|
def CallGAMCommand(args, processGamCfg=True, inLoop=False, closeSTD=False):
|
||||||
return ProcessGAMCommand(args, processGamCfg=processGamCfg, inLoop=inLoop, closeSTD=closeSTD)
|
return ProcessGAMCommand(args, processGamCfg=processGamCfg, inLoop=inLoop, closeSTD=closeSTD)
|
||||||
|
|
||||||
|
|||||||
@@ -13,16 +13,12 @@ import platform
|
|||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from gamlib import glaction
|
|
||||||
from gamlib import glapi as API
|
from gamlib import glapi as API
|
||||||
from gamlib import glcfg as GC
|
from gamlib import glcfg as GC
|
||||||
from gamlib import glclargs
|
|
||||||
from gamlib import glentity
|
|
||||||
from gamlib import glgapi as GAPI
|
from gamlib import glgapi as GAPI
|
||||||
from gamlib import glglobals as GM
|
from gamlib import glglobals as GM
|
||||||
from gamlib import glindent
|
|
||||||
from gamlib import glmsgs as Msg
|
from gamlib import glmsgs as Msg
|
||||||
from gam.util.api import buildGAPIObject, buildGAPIServiceObject, callGAPI, callGAPIpages, getHttpObj
|
from gam.util.api import buildGAPIServiceObject, callGAPI, callGAPIpages, getHttpObj
|
||||||
from gam.util.args import (
|
from gam.util.args import (
|
||||||
LANGUAGE_CODES_MAP,
|
LANGUAGE_CODES_MAP,
|
||||||
checkArgumentPresent,
|
checkArgumentPresent,
|
||||||
@@ -66,10 +62,7 @@ from gam.util.fileio import FILE_ERROR_RC, fileErrorMessage, setFilePath
|
|||||||
from gam.util.output import setSysExitRC, stderrWarningMsg, systemErrorExit
|
from gam.util.output import setSysExitRC, stderrWarningMsg, systemErrorExit
|
||||||
from gam.constants import ANY_NON_TRASHED_FOLDER_NAME, MY_NON_TRASHED_FOLDER_NAME, NO_ENTITIES_FOUND_RC, TEAM_DRIVE
|
from gam.constants import ANY_NON_TRASHED_FOLDER_NAME, MY_NON_TRASHED_FOLDER_NAME, NO_ENTITIES_FOUND_RC, TEAM_DRIVE
|
||||||
|
|
||||||
Act = glaction.GamAction()
|
from gam.var import Act, Cmd, Ent, Ind
|
||||||
Ent = glentity.GamEntity()
|
|
||||||
Ind = glindent.GamIndent()
|
|
||||||
Cmd = glclargs.GamCLArgs()
|
|
||||||
|
|
||||||
APPLICATION_VND_GOOGLE_APPS = 'application/vnd.google-apps.'
|
APPLICATION_VND_GOOGLE_APPS = 'application/vnd.google-apps.'
|
||||||
MIMETYPE_GA_DOCUMENT = f'{APPLICATION_VND_GOOGLE_APPS}document'
|
MIMETYPE_GA_DOCUMENT = f'{APPLICATION_VND_GOOGLE_APPS}document'
|
||||||
@@ -99,7 +92,6 @@ ORPHANS = 'Orphans'
|
|||||||
SHARED_WITHME = 'SharedWithMe'
|
SHARED_WITHME = 'SharedWithMe'
|
||||||
SHARED_DRIVES = 'SharedDrives'
|
SHARED_DRIVES = 'SharedDrives'
|
||||||
|
|
||||||
|
|
||||||
ROOTID = 'rootid'
|
ROOTID = 'rootid'
|
||||||
|
|
||||||
def doDriveSearch(drive, user, i, count, query=None, parentQuery=False, emptyQueryOK=False, orderBy=None, sharedDriveOnly=False, **kwargs):
|
def doDriveSearch(drive, user, i, count, query=None, parentQuery=False, emptyQueryOK=False, orderBy=None, sharedDriveOnly=False, **kwargs):
|
||||||
@@ -561,7 +553,7 @@ def _validateUserGetFileIDs(user, i, count, fileIdEntity, drive=None, entityType
|
|||||||
if not drive:
|
if not drive:
|
||||||
return (user, None, 0)
|
return (user, None, 0)
|
||||||
else:
|
else:
|
||||||
user = convertUIDtoEmailAddress(user, buildGAPIObject(API.DIRECTORY))
|
user = convertUIDtoEmailAddress(user)
|
||||||
if fileIdEntity['list'] and _simpleFileIdEntityList(fileIdEntity['list']):
|
if fileIdEntity['list'] and _simpleFileIdEntityList(fileIdEntity['list']):
|
||||||
l = len(fileIdEntity['list'])
|
l = len(fileIdEntity['list'])
|
||||||
if ROOT in fileIdEntity['list'] and fileIdEntity[ROOT]:
|
if ROOT in fileIdEntity['list'] and fileIdEntity[ROOT]:
|
||||||
@@ -760,7 +752,7 @@ def _validateUserGetSharedDriveFileIDs(user, i, count, fileIdEntity, drive=None,
|
|||||||
if not drive:
|
if not drive:
|
||||||
return (user, None, 0)
|
return (user, None, 0)
|
||||||
else:
|
else:
|
||||||
user = convertUIDtoEmailAddress(user, buildGAPIObject(API.DIRECTORY))
|
user = convertUIDtoEmailAddress(user)
|
||||||
if fileIdEntity.get('shareddrivename') and not _convertSharedDriveNameToId(drive, user, i, count, fileIdEntity):
|
if fileIdEntity.get('shareddrivename') and not _convertSharedDriveNameToId(drive, user, i, count, fileIdEntity):
|
||||||
return (user, None, 0)
|
return (user, None, 0)
|
||||||
if fileIdEntity['shareddrivefilequery']:
|
if fileIdEntity['shareddrivefilequery']:
|
||||||
|
|||||||
Reference in New Issue
Block a user