mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-04 12:51:36 +00:00
Fix check service account and short URLs
This commit is contained in:
@@ -17,6 +17,7 @@ import transport
|
|||||||
from var import GAM_INFO
|
from var import GAM_INFO
|
||||||
from var import GM_Globals
|
from var import GM_Globals
|
||||||
from var import GM_WINDOWS
|
from var import GM_WINDOWS
|
||||||
|
import utils
|
||||||
|
|
||||||
MESSAGE_CONSOLE_AUTHORIZATION_PROMPT = ('\nGo to the following link in your '
|
MESSAGE_CONSOLE_AUTHORIZATION_PROMPT = ('\nGo to the following link in your '
|
||||||
'browser:\n\n\t{url}\n')
|
'browser:\n\n\t{url}\n')
|
||||||
@@ -512,29 +513,8 @@ class _ShortURLFlow(google_auth_oauthlib.flow.InstalledAppFlow):
|
|||||||
def authorization_url(self, http=None, **kwargs):
|
def authorization_url(self, http=None, **kwargs):
|
||||||
"""Gets a shortened authorization URL."""
|
"""Gets a shortened authorization URL."""
|
||||||
long_url, state = super(_ShortURLFlow, self).authorization_url(**kwargs)
|
long_url, state = super(_ShortURLFlow, self).authorization_url(**kwargs)
|
||||||
if not http:
|
short_url = utils.shorten_url(long_url)
|
||||||
http = transport.create_http(timeout=10)
|
return short_url, state
|
||||||
headers = {'Content-Type': 'application/json', 'User-Agent': GAM_INFO}
|
|
||||||
try:
|
|
||||||
payload = json.dumps({'long_url': long_url})
|
|
||||||
resp, content = http.request(
|
|
||||||
_ShortURLFlow.URL_SHORTENER_ENDPOINT,
|
|
||||||
'POST',
|
|
||||||
payload,
|
|
||||||
headers=headers)
|
|
||||||
except:
|
|
||||||
return long_url, state
|
|
||||||
|
|
||||||
if resp.status != 200:
|
|
||||||
return long_url, state
|
|
||||||
|
|
||||||
try:
|
|
||||||
if isinstance(content, bytes):
|
|
||||||
content = content.decode()
|
|
||||||
return json.loads(content).get('short_url', long_url), state
|
|
||||||
except:
|
|
||||||
return long_url, state
|
|
||||||
|
|
||||||
|
|
||||||
class _FileLikeThreadLock(object):
|
class _FileLikeThreadLock(object):
|
||||||
"""A threading.lock which has the same interface as filelock.Filelock."""
|
"""A threading.lock which has the same interface as filelock.Filelock."""
|
||||||
|
|||||||
@@ -1021,7 +1021,7 @@ def doCheckServiceAccount(users):
|
|||||||
long_url = (f'https://admin.google.com/{user_domain}/ManageOauthClients'
|
long_url = (f'https://admin.google.com/{user_domain}/ManageOauthClients'
|
||||||
f'?clientScopeToAdd={",".join(check_scopes)}'
|
f'?clientScopeToAdd={",".join(check_scopes)}'
|
||||||
f'&clientNameToAdd={service_account}')
|
f'&clientNameToAdd={service_account}')
|
||||||
short_url = shorten_url(long_url)
|
short_url = utils.shorten_url(long_url)
|
||||||
scopes_failed = f'''Some scopes failed! To authorize them, please go to:
|
scopes_failed = f'''Some scopes failed! To authorize them, please go to:
|
||||||
|
|
||||||
{short_url}
|
{short_url}
|
||||||
@@ -10104,7 +10104,7 @@ def doRequestOAuth(login_hint=None):
|
|||||||
try:
|
try:
|
||||||
creds = auth.oauth.Credentials.from_client_secrets_file(
|
creds = auth.oauth.Credentials.from_client_secrets_file(
|
||||||
client_secrets_file=client_secrets_file,
|
client_secrets_file=client_secrets_file,
|
||||||
scopes=list(scopes),
|
scopes=scopes,
|
||||||
access_type='offline',
|
access_type='offline',
|
||||||
login_hint=login_hint,
|
login_hint=login_hint,
|
||||||
credentials_file=GC_Values[GC_OAUTH2_TXT],
|
credentials_file=GC_Values[GC_OAUTH2_TXT],
|
||||||
@@ -10421,7 +10421,7 @@ class ScopeSelectionMenu():
|
|||||||
"""Returns the aggregate set of oauth scopes currently selected."""
|
"""Returns the aggregate set of oauth scopes currently selected."""
|
||||||
selected_scopes = [scope for option in self.get_selected_options()
|
selected_scopes = [scope for option in self.get_selected_options()
|
||||||
for scope in option.get_effective_scopes()]
|
for scope in option.get_effective_scopes()]
|
||||||
return set(selected_scopes)
|
return list(set(selected_scopes))
|
||||||
|
|
||||||
MENU_CHOICE = {
|
MENU_CHOICE = {
|
||||||
'SELECT_ALL_SCOPES': 's',
|
'SELECT_ALL_SCOPES': 's',
|
||||||
|
|||||||
27
src/utils.py
27
src/utils.py
@@ -4,10 +4,11 @@ import sys
|
|||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
from html.entities import name2codepoint
|
from html.entities import name2codepoint
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
|
import json
|
||||||
|
|
||||||
from var import *
|
from var import *
|
||||||
import fileutils
|
import fileutils
|
||||||
|
import transport
|
||||||
|
|
||||||
class _DeHTMLParser(HTMLParser):
|
class _DeHTMLParser(HTMLParser):
|
||||||
|
|
||||||
@@ -252,3 +253,27 @@ def md5_matches_file(local_file, expected_md5, exitOnError):
|
|||||||
if exitOnError and actual_hash != expected_md5:
|
if exitOnError and actual_hash != expected_md5:
|
||||||
controlflow.system_error_exit(6, f'actual hash was {actual_hash}. Exiting on corrupt file.')
|
controlflow.system_error_exit(6, f'actual hash was {actual_hash}. Exiting on corrupt file.')
|
||||||
return actual_hash == expected_md5
|
return actual_hash == expected_md5
|
||||||
|
|
||||||
|
URL_SHORTENER_ENDPOINT = 'https://gam-shortn.appspot.com/create'
|
||||||
|
|
||||||
|
def shorten_url(long_url, httpc=None):
|
||||||
|
if not httpc:
|
||||||
|
httpc = transport.create_http(timeout=10)
|
||||||
|
headers = {'Content-Type': 'application/json', 'User-Agent': GAM_INFO}
|
||||||
|
try:
|
||||||
|
payload = json.dumps({'long_url': long_url})
|
||||||
|
resp, content = httpc.request(
|
||||||
|
URL_SHORTENER_ENDPOINT,
|
||||||
|
'POST',
|
||||||
|
payload,
|
||||||
|
headers=headers)
|
||||||
|
except:
|
||||||
|
return long_url
|
||||||
|
if resp.status != 200:
|
||||||
|
return long_url
|
||||||
|
try:
|
||||||
|
if isinstance(content, bytes):
|
||||||
|
content = content.decode()
|
||||||
|
return json.loads(content).get('short_url', long_url)
|
||||||
|
except:
|
||||||
|
return long_url
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import platform
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
gam_author = 'Jay Lee <jay0lee@gmail.com>'
|
gam_author = 'Jay Lee <jay0lee@gmail.com>'
|
||||||
gam_version = '5.01'
|
gam_version = '5.02'
|
||||||
gam_license = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
|
gam_license = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
|
||||||
|
|
||||||
GAM_URL = 'https://git.io/gam'
|
GAM_URL = 'https://git.io/gam'
|
||||||
|
|||||||
Reference in New Issue
Block a user