Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion osc_sdk_python/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.21.0
0.21.1
48 changes: 26 additions & 22 deletions osc_sdk_python/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,20 +29,18 @@ 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:
self.region = DEFAULT_REGION

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()

Expand All @@ -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'
20 changes: 20 additions & 0 deletions tests/test_manual_aksk.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions tests/test_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down