diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 520efb0..2750cc5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,15 +29,12 @@ Make sure to run tests/run.sh before each PR. ## How to release -- Make sure you have update osc_api submodule by running `make osc-api-update` -- Have `OSC_ACCESS_KEY` and `OSC_SECRET_KEY` environment variables set for `eu-west-2` region -- Run all tests with `make test` - Update version in: - [osc_sdk_python/VERSION](osc_sdk_python/VERSION) - [README.md](README.md) -- Push PR, validate changes and merge into `master` branch -- Push corresponding tag -- Tag and push branch -- Create release -- Add `dist/osc_sdk_python-x.x.x-py3-none-any.whl` and `osc_sdk_python-x.x.x.tar.gz` files to release. -- Github action should have pushed packages on pip. If not: setup PIP_TOKEN and run `make upload-package` +- Commit, PR, merge +- Create release in Github +- Github action should have generated artifacts. If not: + - `make package` + - Add `dist/osc_sdk_python-x.x.x-py3-none-any.whl` and `osc_sdk_python-x.x.x.tar.gz` files to release. + - Setup PIP_TOKEN and run `make upload-package` diff --git a/README.md b/README.md index ba56f35..8d6fdc7 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ $ make package You can then install it with: ```bash -$ pip install dist/osc_sdk_python-0.21.0-py3-none-any.whl +$ pip install dist/osc_sdk_python-0.21.1-py3-none-any.whl ``` # Configuration & Credentials diff --git a/osc_sdk_python/VERSION b/osc_sdk_python/VERSION index 8854156..a67ceba 100644 --- a/osc_sdk_python/VERSION +++ b/osc_sdk_python/VERSION @@ -1 +1 @@ -0.21.0 +0.21.1 diff --git a/osc_sdk_python/credentials.py b/osc_sdk_python/credentials.py index 7c23500..5e996ed 100644 --- a/osc_sdk_python/credentials.py +++ b/osc_sdk_python/credentials.py @@ -9,10 +9,14 @@ class Credentials: def __init__(self, region, profile, access_key, secret_key, email, password): self.region = None + self.access_key = access_key + self.secret_key = secret_key + self.email = email + self.password = password if profile is None: profile = os.environ.get('OSC_PROFILE') - if profile != None: + else: # Overide with environmental configuration if available self.load_credentials_from_env() # Overide with old configuration if available @@ -25,7 +29,7 @@ def __init__(self, region, profile, access_key, secret_key, email, password): self.load_credentials_from_env() # Set defaults - if region != None: + if region is not None: self.region = region if self.region is None: @@ -33,12 +37,10 @@ def __init__(self, region, profile, access_key, secret_key, email, password): self.profile = profile # Overide with app parameters if provided - if access_key != None: + if access_key is not None: self.access_key = access_key - if secret_key != None: + if secret_key is not None: self.secret_key = secret_key - self.email = email - self.password = password self.check_options() @@ -47,42 +49,44 @@ def load_credentials_from_file(self, profile, file_path): with open(file_path) as f: config = json.load(f) profile = config.get(profile) - if profile == None: + if profile is None: return ak = profile.get("access_key") - if ak != None: + if ak is not None: self.access_key = ak sk = profile.get("secret_key") - if sk != None: + if sk is not None: self.secret_key = sk region = profile.get("region") - if region != None: + if region is not None: self.region = region except IOError: pass def load_credentials_from_env(self): ak = os.environ.get('OSC_ACCESS_KEY') - if ak != None: + if ak is not None: self.access_key = ak sk = os.environ.get('OSC_SECRET_KEY') - if sk != None: + if sk is not None: self.secret_key = sk region = os.environ.get('OSC_REGION') - if region != None: + if region is not None: self.region = region def check_options(self): - if self.access_key == None or len(self.access_key) == 0: - raise Exception("Invalid Outscale access key") - if self.secret_key == None or len(self.secret_key) == 0: - raise Exception("Invalid Outscale secret key") - if self.region == None or len(self.region) == 0: + if self.access_key is not None or self.secret_key is not None: + if self.access_key is None or len(self.access_key) == 0: + raise Exception("Invalid Outscale access key") + if self.secret_key is None or len(self.secret_key) == 0: + raise Exception("Invalid Outscale secret key") + elif self.email is not None or self.password is not None: + if self.email is None or len(self.email) == 0: + raise Exception("Invalid email option") + if self.password is None and self.password == 0: + raise Exception("Invalid password option") + if self.region is None or len(self.region) == 0: raise Exception("Invalid Outscale region") - if self.email is None and self.password is not None: - raise Exception("Missing email option with password option") - if self.email is not None and self.password is None: - raise Exception("Missing password option with email option") def get_url_extension(self): return 'hk' if 'cn' in self.region else 'com' diff --git a/osc_sdk_python/osc-api b/osc_sdk_python/osc-api index 8d8ed08..49cd2da 160000 --- a/osc_sdk_python/osc-api +++ b/osc_sdk_python/osc-api @@ -1 +1 @@ -Subproject commit 8d8ed08551bf8474c41480c499d1136d3aef3083 +Subproject commit 49cd2da047e0d02c04e3d954f889c46cde1122e8 diff --git a/tests/test_manual_aksk.py b/tests/test_manual_aksk.py new file mode 100644 index 0000000..428e887 --- /dev/null +++ b/tests/test_manual_aksk.py @@ -0,0 +1,20 @@ +import unittest +import sys +import os +sys.path.append("..") +from osc_sdk_python import Gateway + +class TestLoginManualAkSk(unittest.TestCase): + + def test_manual_ak_sk(self): + ak = os.environ.pop("OSC_ACCESS_KEY", None) + sk = os.environ.pop("OSC_SECRET_KEY", None) + self.assertNotEqual(ak, None) + self.assertNotEqual(sk, None) + gw = Gateway(access_key=ak, secret_key=sk) + volumes = gw.ReadVolumes() + self.assertEqual(type(volumes), dict) + self.assertEqual(type(volumes.get("Volumes")), list) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_password.py b/tests/test_password.py index e262061..00a5ae9 100644 --- a/tests/test_password.py +++ b/tests/test_password.py @@ -7,6 +7,8 @@ class TestLoginPassword(unittest.TestCase): def test_login(self): + os.environ.pop("OSC_ACCESS_KEY", None) + os.environ.pop("OSC_SECRET_KEY", None) email = os.getenv('OSC_TEST_LOGIN') password = os.getenv('OSC_TEST_PASSWORD') self.assertNotEqual(email, None)