Skip to content

Commit 50a3e2a

Browse files
v0.16.33 (#178)
fccore.py: * Added function to extract release tuple from a standard version string (based on PEP 440) api.py: * parameter added to allow for clock skew in Oauth call * added version check of google.auth to determine availability of clock skew parameter fiss.py: * added space_size() * added space_cost() * removed Python 3 syntax that broke Python 2 compatibility setup.py: * blocked versions of google.auth with restrictive clock skew defaults and no way to modify them (2.1.0-2.3.1) Co-authored-by: Oliver Priebe <40225301+oliverpriebe@users.noreply.github.com>
1 parent 3037656 commit 50a3e2a

File tree

6 files changed

+86
-6
lines changed

6 files changed

+86
-6
lines changed

changelog.txt

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ Change Log for FISSFC: the (Fi)recloud (S)ervice (S)elector
33
=======================================================================
44
Terms used below: HL = high level interface, LL = low level interface
55

6+
v0.16.33 - HL: added space_size, space_cost; hotfixes: fixed Python 2 compatibility;
7+
blocked google-auth versions with restrictive clock-skew and enabled
8+
later versions with modifiable clock-skew, increasing clock-skew
9+
when appropriate.
10+
611
v0.16.32 - Changed Dockerfile base image to python 3.10; fixed Python 3.10
712
incompatibility issues; pylint set to minimum version 2.0.0; LL: new
813
new functions: delete_entities_of_type, rename_entity,

firecloud/__about__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Package version
2-
__version__ = "0.16.32"
2+
__version__ = "0.16.33"

firecloud/api.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
from firecloud.errors import FireCloudServerError
3030
from firecloud.fccore import __fcconfig as fcconfig
31+
from firecloud.fccore import release_tuple_from_version_string
3132
from firecloud.__about__ import __version__
3233

3334
FISS_USER_AGENT = "FISS/" + __version__
@@ -52,8 +53,14 @@ def _set_session():
5253
__SESSION = AuthorizedSession(google.auth.default(['https://www.googleapis.com/auth/userinfo.profile',
5354
'https://www.googleapis.com/auth/userinfo.email'])[0])
5455
health()
55-
__USER_ID = id_token.verify_oauth2_token(__SESSION.credentials.id_token,
56-
Request(session=__SESSION))['email']
56+
# google.auth 2.1.0 introduced a restrictive clock skew that was unmodifiable until 2.3.2
57+
if release_tuple_from_version_string(google.auth.__version__) >= (2,3,2):
58+
__USER_ID = id_token.verify_oauth2_token(__SESSION.credentials.id_token,
59+
Request(session=__SESSION),
60+
clock_skew_in_seconds=10)['email']
61+
else:
62+
__USER_ID = id_token.verify_oauth2_token(__SESSION.credentials.id_token,
63+
Request(session=__SESSION))['email']
5764
except AttributeError:
5865
__USER_ID = __SESSION.credentials.service_account_email
5966
except (DefaultCredentialsError, RefreshError) as gae:
@@ -1364,7 +1371,7 @@ def get_storage_cost(namespace, workspace):
13641371
namespace (str): project to which workspace belongs
13651372
workspace (str): Workspace name
13661373
Swagger:
1367-
https://api.firecloud.org/#!/Workspaces/storageCostEstimate
1374+
https://api.firecloud.org/#/Workspaces/getStorageCostEstimate
13681375
"""
13691376
uri = "workspaces/{0}/{1}/storageCostEstimate".format(namespace, workspace)
13701377
return __get(uri)

firecloud/fccore.py

+43
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import tempfile
2222
import shutil
2323
import subprocess
24+
import re
2425
from io import IOBase
2526
from firecloud import __about__
2627
from google.auth import environment_vars
@@ -219,4 +220,46 @@ def edit_file(name, backup=None):
219220
current_tolm = os.stat(name).st_mtime
220221
return current_tolm != previous_tolm
221222

223+
224+
# From PEP-440:
225+
# https://peps.python.org/pep-0440/#appendix-b-parsing-version-strings-with-regular-expressions
226+
VERSION_PATTERN = r"""
227+
v?
228+
(?:
229+
(?:(?P<epoch>[0-9]+)!)? # epoch
230+
(?P<release>[0-9]+(?:\.[0-9]+)*) # release segment
231+
(?P<pre> # pre-release
232+
[-_\.]?
233+
(?P<pre_l>(a|b|c|rc|alpha|beta|pre|preview))
234+
[-_\.]?
235+
(?P<pre_n>[0-9]+)?
236+
)?
237+
(?P<post> # post release
238+
(?:-(?P<post_n1>[0-9]+))
239+
|
240+
(?:
241+
[-_\.]?
242+
(?P<post_l>post|rev|r)
243+
[-_\.]?
244+
(?P<post_n2>[0-9]+)?
245+
)
246+
)?
247+
(?P<dev> # dev release
248+
[-_\.]?
249+
(?P<dev_l>dev)
250+
[-_\.]?
251+
(?P<dev_n>[0-9]+)?
252+
)?
253+
)
254+
(?:\+(?P<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))? # local version
255+
"""
256+
257+
version_regex = re.compile(
258+
r"^\s*" + VERSION_PATTERN + r"\s*$",
259+
re.VERBOSE | re.IGNORECASE,
260+
)
261+
262+
def release_tuple_from_version_string(version_string):
263+
return tuple(int(val) for val in version_regex.match(version_string).group('release').split('.'))
264+
222265
# }}}

firecloud/fiss.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@ def space_info(args):
119119
fapi._check_response_code(r, 200)
120120
return r.text
121121

122+
@fiss_cmd
123+
def space_size(args):
124+
""" Get storage size of a workspace. """
125+
r = fapi.get_bucket_usage(args.project, args.workspace)
126+
fapi._check_response_code(r, 200)
127+
return r.text
128+
129+
@fiss_cmd
130+
def space_cost(args):
131+
""" Get average monthly storage cost of a workspace. """
132+
r = fapi.get_storage_cost(args.project, args.workspace)
133+
fapi._check_response_code(r, 200)
134+
return r.text
135+
122136
@fiss_cmd
123137
def space_delete(args):
124138
""" Delete a workspace. """
@@ -1320,7 +1334,7 @@ def update_referenced_files(referenced_files, attrs, bucket_prefix):
13201334
bucket_prefix)
13211335

13221336
## Now list files present in the bucket
1323-
def list_blob_gen(bucket_name: str):
1337+
def list_blob_gen(bucket_name):
13241338
"""Generate the list of blobs in the bucket and size of each blob
13251339
13261340
Args:
@@ -2281,6 +2295,17 @@ def main(argv=None):
22812295
description='Show workspace information')
22822296
subp.set_defaults(func=space_info)
22832297

2298+
# Get workspace size
2299+
subp = subparsers.add_parser('space_size', parents=[workspace_parent],
2300+
description='Show workspace bucket usage')
2301+
subp.set_defaults(func=space_size)
2302+
2303+
# Get workspace monthly cost
2304+
subp = subparsers.add_parser('space_cost', parents=[workspace_parent],
2305+
description='Show workspace average monthly' +
2306+
' cost')
2307+
subp.set_defaults(func=space_cost)
2308+
22842309
# List workspaces
22852310
subp = subparsers.add_parser('space_list',
22862311
description='List available workspaces in projects (namespaces) ' +

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def get_outputs(self):
142142
},
143143
test_suite = 'nose.collector',
144144
install_requires = [
145-
'google-auth>=1.6.3',
145+
'google-auth>=1.6.3,!=2.1.*,!=2.2.*,!=2.3.0,!=2.3.1',
146146
'google-cloud-storage>=1.36.1',
147147
'pydot',
148148
'requests[security]',

0 commit comments

Comments
 (0)