Skip to content

Commit

Permalink
v0.16.33 (#178)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dheiman and oliverpriebe authored Sep 9, 2022
1 parent 3037656 commit 50a3e2a
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 6 deletions.
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Change Log for FISSFC: the (Fi)recloud (S)ervice (S)elector
=======================================================================
Terms used below: HL = high level interface, LL = low level interface

v0.16.33 - HL: added space_size, space_cost; hotfixes: fixed Python 2 compatibility;
blocked google-auth versions with restrictive clock-skew and enabled
later versions with modifiable clock-skew, increasing clock-skew
when appropriate.

v0.16.32 - Changed Dockerfile base image to python 3.10; fixed Python 3.10
incompatibility issues; pylint set to minimum version 2.0.0; LL: new
new functions: delete_entities_of_type, rename_entity,
Expand Down
2 changes: 1 addition & 1 deletion firecloud/__about__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Package version
__version__ = "0.16.32"
__version__ = "0.16.33"
13 changes: 10 additions & 3 deletions firecloud/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from firecloud.errors import FireCloudServerError
from firecloud.fccore import __fcconfig as fcconfig
from firecloud.fccore import release_tuple_from_version_string
from firecloud.__about__ import __version__

FISS_USER_AGENT = "FISS/" + __version__
Expand All @@ -52,8 +53,14 @@ def _set_session():
__SESSION = AuthorizedSession(google.auth.default(['https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email'])[0])
health()
__USER_ID = id_token.verify_oauth2_token(__SESSION.credentials.id_token,
Request(session=__SESSION))['email']
# google.auth 2.1.0 introduced a restrictive clock skew that was unmodifiable until 2.3.2
if release_tuple_from_version_string(google.auth.__version__) >= (2,3,2):
__USER_ID = id_token.verify_oauth2_token(__SESSION.credentials.id_token,
Request(session=__SESSION),
clock_skew_in_seconds=10)['email']
else:
__USER_ID = id_token.verify_oauth2_token(__SESSION.credentials.id_token,
Request(session=__SESSION))['email']
except AttributeError:
__USER_ID = __SESSION.credentials.service_account_email
except (DefaultCredentialsError, RefreshError) as gae:
Expand Down Expand Up @@ -1364,7 +1371,7 @@ def get_storage_cost(namespace, workspace):
namespace (str): project to which workspace belongs
workspace (str): Workspace name
Swagger:
https://api.firecloud.org/#!/Workspaces/storageCostEstimate
https://api.firecloud.org/#/Workspaces/getStorageCostEstimate
"""
uri = "workspaces/{0}/{1}/storageCostEstimate".format(namespace, workspace)
return __get(uri)
Expand Down
43 changes: 43 additions & 0 deletions firecloud/fccore.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import tempfile
import shutil
import subprocess
import re
from io import IOBase
from firecloud import __about__
from google.auth import environment_vars
Expand Down Expand Up @@ -219,4 +220,46 @@ def edit_file(name, backup=None):
current_tolm = os.stat(name).st_mtime
return current_tolm != previous_tolm


# From PEP-440:
# https://peps.python.org/pep-0440/#appendix-b-parsing-version-strings-with-regular-expressions
VERSION_PATTERN = r"""
v?
(?:
(?:(?P<epoch>[0-9]+)!)? # epoch
(?P<release>[0-9]+(?:\.[0-9]+)*) # release segment
(?P<pre> # pre-release
[-_\.]?
(?P<pre_l>(a|b|c|rc|alpha|beta|pre|preview))
[-_\.]?
(?P<pre_n>[0-9]+)?
)?
(?P<post> # post release
(?:-(?P<post_n1>[0-9]+))
|
(?:
[-_\.]?
(?P<post_l>post|rev|r)
[-_\.]?
(?P<post_n2>[0-9]+)?
)
)?
(?P<dev> # dev release
[-_\.]?
(?P<dev_l>dev)
[-_\.]?
(?P<dev_n>[0-9]+)?
)?
)
(?:\+(?P<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))? # local version
"""

version_regex = re.compile(
r"^\s*" + VERSION_PATTERN + r"\s*$",
re.VERBOSE | re.IGNORECASE,
)

def release_tuple_from_version_string(version_string):
return tuple(int(val) for val in version_regex.match(version_string).group('release').split('.'))

# }}}
27 changes: 26 additions & 1 deletion firecloud/fiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ def space_info(args):
fapi._check_response_code(r, 200)
return r.text

@fiss_cmd
def space_size(args):
""" Get storage size of a workspace. """
r = fapi.get_bucket_usage(args.project, args.workspace)
fapi._check_response_code(r, 200)
return r.text

@fiss_cmd
def space_cost(args):
""" Get average monthly storage cost of a workspace. """
r = fapi.get_storage_cost(args.project, args.workspace)
fapi._check_response_code(r, 200)
return r.text

@fiss_cmd
def space_delete(args):
""" Delete a workspace. """
Expand Down Expand Up @@ -1320,7 +1334,7 @@ def update_referenced_files(referenced_files, attrs, bucket_prefix):
bucket_prefix)

## Now list files present in the bucket
def list_blob_gen(bucket_name: str):
def list_blob_gen(bucket_name):
"""Generate the list of blobs in the bucket and size of each blob
Args:
Expand Down Expand Up @@ -2281,6 +2295,17 @@ def main(argv=None):
description='Show workspace information')
subp.set_defaults(func=space_info)

# Get workspace size
subp = subparsers.add_parser('space_size', parents=[workspace_parent],
description='Show workspace bucket usage')
subp.set_defaults(func=space_size)

# Get workspace monthly cost
subp = subparsers.add_parser('space_cost', parents=[workspace_parent],
description='Show workspace average monthly' +
' cost')
subp.set_defaults(func=space_cost)

# List workspaces
subp = subparsers.add_parser('space_list',
description='List available workspaces in projects (namespaces) ' +
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def get_outputs(self):
},
test_suite = 'nose.collector',
install_requires = [
'google-auth>=1.6.3',
'google-auth>=1.6.3,!=2.1.*,!=2.2.*,!=2.3.0,!=2.3.1',
'google-cloud-storage>=1.36.1',
'pydot',
'requests[security]',
Expand Down

0 comments on commit 50a3e2a

Please sign in to comment.