mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-04 21:01:36 +00:00
Cleanup (#1066)
* Cleanup gam,py: In show sakays, only mark USER-MANAGED keys as current: true/false gapi/__init__.py: pylint cleanup: import order, indentation gapi/errors.py: pylint cleanup: import order, unused import, indentation Recognize 502 Bad Gateway/Gateway Timeout: treat as retryable errors This last change does not directly handle the refresh problem in Issue #1063 but in my version this seems to be the right solution to the 502 gateways errors * In show sakeys, indicate whcij key was used to authenticate * Show all sakeys by default * Include unused import * Remove unused import, fix unit tests
This commit is contained in:
@@ -7840,7 +7840,7 @@ def _formatOAuth2ServiceData(private_key, private_key_id):
|
|||||||
|
|
||||||
def doShowServiceAccountKeys():
|
def doShowServiceAccountKeys():
|
||||||
iam = buildGAPIServiceObject('iam', None)
|
iam = buildGAPIServiceObject('iam', None)
|
||||||
keyTypes = 'USER_MANAGED'
|
keyTypes = None
|
||||||
i = 3
|
i = 3
|
||||||
while i < len(sys.argv):
|
while i < len(sys.argv):
|
||||||
myarg = sys.argv[i].lower().replace('_', '')
|
myarg = sys.argv[i].lower().replace('_', '')
|
||||||
@@ -7867,7 +7867,8 @@ def doShowServiceAccountKeys():
|
|||||||
print('{0}: {1}'.format(parts[i][:-1], parts[i+1]))
|
print('{0}: {1}'.format(parts[i][:-1], parts[i+1]))
|
||||||
for key in keys:
|
for key in keys:
|
||||||
key['name'] = key['name'].rsplit('/', 1)[-1]
|
key['name'] = key['name'].rsplit('/', 1)[-1]
|
||||||
key['current'] = key['name'] == currentPrivateKeyId
|
if key['name'] == currentPrivateKeyId:
|
||||||
|
key['usedToAuthenticateThisRequest'] = True
|
||||||
print_json(None, keys)
|
print_json(None, keys)
|
||||||
|
|
||||||
def doRotateServiceAccountKeys():
|
def doRotateServiceAccountKeys():
|
||||||
|
|||||||
@@ -2,17 +2,18 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import googleapiclient.errors
|
||||||
|
import google.auth.exceptions
|
||||||
|
import httplib2
|
||||||
|
|
||||||
import controlflow
|
import controlflow
|
||||||
import display
|
import display
|
||||||
from gapi import errors
|
from gapi import errors
|
||||||
import googleapiclient.errors
|
|
||||||
import httplib2
|
|
||||||
from var import (GC_CA_FILE, GC_Values, GC_TLS_MIN_VERSION, GC_TLS_MAX_VERSION,
|
from var import (GC_CA_FILE, GC_Values, GC_TLS_MIN_VERSION, GC_TLS_MAX_VERSION,
|
||||||
GM_Globals, GM_CURRENT_API_SCOPES, GM_CURRENT_API_USER,
|
GM_Globals, GM_CURRENT_API_SCOPES, GM_CURRENT_API_USER,
|
||||||
GM_EXTRA_ARGS_DICT, GM_OAUTH2SERVICE_ACCOUNT_CLIENT_ID,
|
GM_EXTRA_ARGS_DICT, GM_OAUTH2SERVICE_ACCOUNT_CLIENT_ID,
|
||||||
MAX_RESULTS_API_EXCEPTIONS, MESSAGE_API_ACCESS_CONFIG,
|
MAX_RESULTS_API_EXCEPTIONS, MESSAGE_API_ACCESS_CONFIG,
|
||||||
MESSAGE_API_ACCESS_DENIED, MESSAGE_SERVICE_NOT_APPLICABLE)
|
MESSAGE_API_ACCESS_DENIED, MESSAGE_SERVICE_NOT_APPLICABLE)
|
||||||
import google.auth.exceptions
|
|
||||||
|
|
||||||
|
|
||||||
def create_http(cache=None,
|
def create_http(cache=None,
|
||||||
@@ -101,7 +102,6 @@ def call(service,
|
|||||||
if errors.ErrorReason(reason) in errors.ERROR_REASON_TO_EXCEPTION:
|
if errors.ErrorReason(reason) in errors.ERROR_REASON_TO_EXCEPTION:
|
||||||
raise errors.ERROR_REASON_TO_EXCEPTION[errors.ErrorReason(reason)](
|
raise errors.ERROR_REASON_TO_EXCEPTION[errors.ErrorReason(reason)](
|
||||||
message)
|
message)
|
||||||
else:
|
|
||||||
raise e
|
raise e
|
||||||
if (n != retries) and (is_known_error_reason and errors.ErrorReason(
|
if (n != retries) and (is_known_error_reason and errors.ErrorReason(
|
||||||
reason) in errors.DEFAULT_RETRY_REASONS + retry_reasons):
|
reason) in errors.DEFAULT_RETRY_REASONS + retry_reasons):
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
"""GAPI and OAuth Token related errors methods."""
|
"""GAPI and OAuth Token related errors methods."""
|
||||||
|
|
||||||
|
from enum import Enum
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import controlflow
|
import controlflow
|
||||||
from enum import Enum
|
|
||||||
import googleapiclient.errors
|
|
||||||
from var import UTF8
|
|
||||||
import display # TODO: Change to relative import when gam is setup as a package
|
import display # TODO: Change to relative import when gam is setup as a package
|
||||||
|
from var import UTF8
|
||||||
|
|
||||||
|
|
||||||
class GapiAbortedError(Exception):
|
class GapiAbortedError(Exception):
|
||||||
@@ -17,6 +16,10 @@ class GapiAuthErrorError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class GapiBadGatewayError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class GapiBadRequestError(Exception):
|
class GapiBadRequestError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -49,6 +52,10 @@ class GapiForbiddenError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class GapiGatewayTimeoutError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class GapiGroupNotFoundError(Exception):
|
class GapiGroupNotFoundError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -99,6 +106,7 @@ class ErrorReason(Enum):
|
|||||||
ABORTED = 'aborted'
|
ABORTED = 'aborted'
|
||||||
AUTH_ERROR = 'authError'
|
AUTH_ERROR = 'authError'
|
||||||
BACKEND_ERROR = 'backendError'
|
BACKEND_ERROR = 'backendError'
|
||||||
|
BAD_GATEWAY = 'badGateway'
|
||||||
BAD_REQUEST = 'badRequest'
|
BAD_REQUEST = 'badRequest'
|
||||||
CONDITION_NOT_MET = 'conditionNotMet'
|
CONDITION_NOT_MET = 'conditionNotMet'
|
||||||
CYCLIC_MEMBERSHIPS_NOT_ALLOWED = 'cyclicMembershipsNotAllowed'
|
CYCLIC_MEMBERSHIPS_NOT_ALLOWED = 'cyclicMembershipsNotAllowed'
|
||||||
@@ -107,6 +115,7 @@ class ErrorReason(Enum):
|
|||||||
DUPLICATE = 'duplicate'
|
DUPLICATE = 'duplicate'
|
||||||
FAILED_PRECONDITION = 'failedPrecondition'
|
FAILED_PRECONDITION = 'failedPrecondition'
|
||||||
FORBIDDEN = 'forbidden'
|
FORBIDDEN = 'forbidden'
|
||||||
|
GATEWAY_TIMEOUT = 'gatewayTimeout'
|
||||||
GROUP_NOT_FOUND = 'groupNotFound'
|
GROUP_NOT_FOUND = 'groupNotFound'
|
||||||
INTERNAL_ERROR = 'internalError'
|
INTERNAL_ERROR = 'internalError'
|
||||||
INVALID = 'invalid'
|
INVALID = 'invalid'
|
||||||
@@ -132,6 +141,7 @@ class ErrorReason(Enum):
|
|||||||
DEFAULT_RETRY_REASONS = [
|
DEFAULT_RETRY_REASONS = [
|
||||||
ErrorReason.QUOTA_EXCEEDED, ErrorReason.RATE_LIMIT_EXCEEDED,
|
ErrorReason.QUOTA_EXCEEDED, ErrorReason.RATE_LIMIT_EXCEEDED,
|
||||||
ErrorReason.USER_RATE_LIMIT_EXCEEDED, ErrorReason.BACKEND_ERROR,
|
ErrorReason.USER_RATE_LIMIT_EXCEEDED, ErrorReason.BACKEND_ERROR,
|
||||||
|
ErrorReason.BAD_GATEWAY, ErrorReason.GATEWAY_TIMEOUT,
|
||||||
ErrorReason.INTERNAL_ERROR
|
ErrorReason.INTERNAL_ERROR
|
||||||
]
|
]
|
||||||
GMAIL_THROW_REASONS = [ErrorReason.SERVICE_NOT_AVAILABLE]
|
GMAIL_THROW_REASONS = [ErrorReason.SERVICE_NOT_AVAILABLE]
|
||||||
@@ -154,6 +164,8 @@ ERROR_REASON_TO_EXCEPTION = {
|
|||||||
GapiAbortedError,
|
GapiAbortedError,
|
||||||
ErrorReason.AUTH_ERROR:
|
ErrorReason.AUTH_ERROR:
|
||||||
GapiAuthErrorError,
|
GapiAuthErrorError,
|
||||||
|
ErrorReason.BAD_GATEWAY:
|
||||||
|
GapiBadGatewayError,
|
||||||
ErrorReason.BAD_REQUEST:
|
ErrorReason.BAD_REQUEST:
|
||||||
GapiBadRequestError,
|
GapiBadRequestError,
|
||||||
ErrorReason.CONDITION_NOT_MET:
|
ErrorReason.CONDITION_NOT_MET:
|
||||||
@@ -170,6 +182,8 @@ ERROR_REASON_TO_EXCEPTION = {
|
|||||||
GapiFailedPreconditionError,
|
GapiFailedPreconditionError,
|
||||||
ErrorReason.FORBIDDEN:
|
ErrorReason.FORBIDDEN:
|
||||||
GapiForbiddenError,
|
GapiForbiddenError,
|
||||||
|
ErrorReason.GATEWAY_TIMEOUT:
|
||||||
|
GapiGatewayTimeoutError,
|
||||||
ErrorReason.GROUP_NOT_FOUND:
|
ErrorReason.GROUP_NOT_FOUND:
|
||||||
GapiGroupNotFoundError,
|
GapiGroupNotFoundError,
|
||||||
ErrorReason.INVALID:
|
ErrorReason.INVALID:
|
||||||
@@ -268,6 +282,10 @@ def get_gapi_error_detail(e,
|
|||||||
if (e.resp['status'] == '403') and (
|
if (e.resp['status'] == '403') and (
|
||||||
error_content.startswith('Request rate higher than configured')):
|
error_content.startswith('Request rate higher than configured')):
|
||||||
return (e.resp['status'], ErrorReason.QUOTA_EXCEEDED.value, error_content)
|
return (e.resp['status'], ErrorReason.QUOTA_EXCEEDED.value, error_content)
|
||||||
|
if (e.resp['status'] == '502') and ('Bad Gateway' in error_content):
|
||||||
|
return (e.resp['status'], ErrorReason.BAD_GATEWAY.value, error_content)
|
||||||
|
if (e.resp['status'] == '504') and ('Gateway Timeout' in error_content):
|
||||||
|
return (e.resp['status'], ErrorReason.GATEWAY_TIMEOUT.value, error_content)
|
||||||
if (e.resp['status'] == '403') and ('Invalid domain.' in error_content):
|
if (e.resp['status'] == '403') and ('Invalid domain.' in error_content):
|
||||||
error = _create_http_error_dict(403, ErrorReason.NOT_FOUND.value,
|
error = _create_http_error_dict(403, ErrorReason.NOT_FOUND.value,
|
||||||
'Domain not found')
|
'Domain not found')
|
||||||
|
|||||||
Reference in New Issue
Block a user