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
3 changes: 0 additions & 3 deletions .github/actions/setup-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ description: "Setup toolchain and run smoke test"
runs:
using: composite
steps:
- name: ⬇️ Import Outscale API description
run: make init
shell: bash
- name: ⬇️ Install uv
uses: astral-sh/setup-uv@v6
- name: ⬇️ Setup Python
Expand Down
7 changes: 2 additions & 5 deletions .github/scripts/release-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ branch_name="autobuild-$new_sdk_version"
git branch -m $branch_name

# Update osc-api version
cd "$root/osc_sdk_python/osc-api"
git reset --hard $osc_api_version
cd ..
git add osc-api
cd "$root"
curl --retry 10 -o "${root}/osc_sdk_python/resources/outscale.yaml" "https://raw.githubusercontent.com/outscale/osc-api/refs/tags/${osc_api_version}/outscale.yaml"
git add "${root}/osc_sdk_python/resources/outscale.yaml"

# Setup new SDK version
for f in "$root/README.md" "$root/osc_sdk_python/VERSION"; do
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

15 changes: 2 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,17 @@ test-lint:
@uv tool run ruff check

.PHONY: test-int
test-int: init
test-int:
@uv run pytest -s

.PHONY: package
package: init
package:
@uv build

.PHONY: upload-package
upload-package: package
@uv publish --trusted-publishing=always

.PHONY: osc-api-update
osc-api-update:
cd osc_sdk_python/osc-api/; git fetch; git checkout origin/master; cd ..; git add osc-api

.PHONY: init
init: osc_sdk_python/osc-api/outscale.yaml
@echo Initialization: OK

osc_sdk_python/osc-api/outscale.yaml:
git submodule update --init .

.PHONY: clean
clean:
@echo cleaning...
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ Example:
```python
from osc_sdk_python import Gateway

gw = Gateway(email="your@email.com", password="yourAccountPassword")
keys = gw.ReadAccessKeys()
with Gateway(email="your@email.com", password="yourAccountPassword") as gw:
keys = gw.ReadAccessKeys()
```

### Retry Options
Expand Down
70 changes: 33 additions & 37 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ Basic usage with the default profile:
```python
from osc_sdk_python import Gateway

gw = Gateway()

# Example: list VMs
vms = gw.ReadVms()
print(vms)
with Gateway() as gw:
# Example: list VMs
vms = gw.ReadVms()
print(vms)
```

Using a specific profile:
Expand All @@ -30,21 +29,20 @@ Example:
```python
from osc_sdk_python import Gateway

gw = Gateway(profile="profile_1")
with Gateway(profile="profile_1") as gw:
# Calls with API action as method
result = gw.ReadSecurityGroups(Filters={"SecurityGroupNames": ["default"]})
result = gw.CreateVms(ImageId="ami-3e158364", VmType="tinav4.c2r4")

# Calls with API action as method
result = gw.ReadSecurityGroups(Filters={"SecurityGroupNames": ["default"]})
result = gw.CreateVms(ImageId="ami-3e158364", VmType="tinav4.c2r4")

# Or raw calls:
result = gw.raw("ReadVms")
result = gw.raw(
"CreateVms",
ImageId="ami-xx",
BlockDeviceMappings=[{"/dev/sda1": {"Size": 10}}],
SecurityGroupIds=["sg-aaa", "sg-bbb"],
Wrong="wrong",
)
# Or raw calls:
result = gw.raw("ReadVms")
result = gw.raw(
"CreateVms",
ImageId="ami-xx",
BlockDeviceMappings=[{"/dev/sda1": {"Size": 10}}],
SecurityGroupIds=["sg-aaa", "sg-bbb"],
Wrong="wrong",
)
```

---
Expand All @@ -57,15 +55,14 @@ result = gw.raw(
from osc_sdk_python import Gateway

if __name__ == "__main__":
gw = Gateway()

print("Your virtual machines:")
for vm in gw.ReadVms()["Vms"]:
print(vm["VmId"])

print("\nYour volumes:")
for volume in gw.ReadVolumes()["Volumes"]:
print(volume["VolumeId"])
with Gateway() as gw:
print("Your virtual machines:")
for vm in gw.ReadVms()["Vms"]:
print(vm["VmId"])

print("\nYour volumes:")
for volume in gw.ReadVolumes()["Volumes"]:
print(volume["VolumeId"])
```

### Enabling logs
Expand All @@ -74,16 +71,15 @@ if __name__ == "__main__":
from osc_sdk_python import *

if __name__ == "__main__":
gw = Gateway(profile="profile_1")

# 'what' can be LOG_KEEP_ONLY_LAST_REQ or LOG_ALL
# Here we print logs in memory, standard output and standard error
gw.log.config(type=LOG_MEMORY | LOG_STDIO | LOG_STDERR, what=LOG_KEEP_ONLY_LAST_REQ)
with Gateway(profile="profile_1") as gw:
# 'what' can be LOG_KEEP_ONLY_LAST_REQ or LOG_ALL
# Here we print logs in memory, standard output and standard error
gw.log.config(type=LOG_MEMORY | LOG_STDIO | LOG_STDERR, what=LOG_KEEP_ONLY_LAST_REQ)

result = gw.raw("ReadVms")
result = gw.raw("ReadVms")

last_request = gw.log.str()
print(last_request)
last_request = gw.log.str()
print(last_request)
```

Usage examples can be combined with the official [Outscale API documentation](https://docs.outscale.com/en/userguide/Home.html).
Usage examples can be combined with the official [Outscale API documentation](https://docs.outscale.com/en/userguide/Home.html).
2 changes: 1 addition & 1 deletion local-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export OSC_TEST_PASSWORD=ashita wa dochida
export OSC_TEST_LOGIN=joe
export OSC_SECRET_KEY=0000001111112222223333334444445555555666
export OSC_ACCESS_KEY=11112211111110000000
export OSC_ENDPOINT_API=http://127.0.0.1:3000
export OSC_ENDPOINT_API=http://127.0.0.1:3000/api/v1
export OSC_IS_RICOCHET=true

if [ "$#" -eq 0 ]; then
Expand Down
3 changes: 3 additions & 0 deletions osc_sdk_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .outscale_gateway import LOG_STDIO
from .outscale_gateway import LOG_MEMORY
from .version import get_version
from .problem import Problem, ProblemDecoder

# what to Log
from .outscale_gateway import LOG_ALL
Expand All @@ -21,4 +22,6 @@
"LOG_MEMORY",
"LOG_ALL",
"LOG_KEEP_ONLY_LAST_REQ",
"Problem",
"ProblemDecoder"
]
12 changes: 6 additions & 6 deletions osc_sdk_python/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
import base64

from .version import get_version
VERSION = get_version()
from .credentials import Profile
VERSION: str = get_version()
DEFAULT_USER_AGENT = "osc-sdk-python/" + VERSION

class Authentication:
def __init__(self, credentials, host,
def __init__(self, credentials: Profile, host: str,
method='POST', service='api',
content_type='application/json; charset=utf-8',
algorithm='OSC4-HMAC-SHA256',
signed_headers = 'content-type;host;x-osc-date',
user_agent = DEFAULT_USER_AGENT):
self.access_key = credentials.access_key
self.secret_key = credentials.secret_key
self.email = credentials.email
self.login = credentials.login
self.password = credentials.password
self.host = host
self.region = credentials.region
Expand All @@ -26,7 +27,6 @@ def __init__(self, credentials, host,
self.algorithm = algorithm
self.signed_headers = signed_headers
self.user_agent = user_agent
self.proxy = credentials.proxy
self.x509_client_cert = credentials.x509_client_cert

def forge_headers_signed(self, uri, request_data):
Expand Down Expand Up @@ -121,12 +121,12 @@ def build_authorization_header(self, credential_scope, signature):
+ 'Signature=' + signature

def is_basic_auth_configured(self):
return self.email is not None and self.password is not None
return self.login is not None and self.password is not None

def get_basic_auth_header(self):
if not self.is_basic_auth_configured():
raise Exception("email or password not set")
creds = self.email + ":" + self.password
creds = self.login + ":" + self.password
b64_creds = str(base64.b64encode(creds.encode("utf-8")), "utf-8")
date_iso, _ = self.build_dates()
return {
Expand Down
Loading