Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: load token from env in examples scripts #302

Merged
merged 1 commit into from
Sep 25, 2023
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
11 changes: 9 additions & 2 deletions examples/create_server.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from __future__ import annotations

from os import environ

from hcloud import Client
from hcloud.images import Image
from hcloud.server_types import ServerType

# Please paste your API token here between the quotes
client = Client(token="{YOUR_API_TOKEN}")
assert (
"HCLOUD_TOKEN" in environ
), "Please export your API token in the HCLOUD_TOKEN environment variable"
token = environ["HCLOUD_TOKEN"]

client = Client(token=token)

response = client.servers.create(
name="my-server",
server_type=ServerType("cx11"),
Expand Down
11 changes: 8 additions & 3 deletions examples/list_servers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from __future__ import annotations

from os import environ

from hcloud import Client

client = Client(
token="{YOUR_API_TOKEN}"
) # Please paste your API token here between the quotes
assert (
"HCLOUD_TOKEN" in environ
), "Please export your API token in the HCLOUD_TOKEN environment variable"
token = environ["HCLOUD_TOKEN"]

client = Client(token=token)
servers = client.servers.get_all()
print(servers)
9 changes: 8 additions & 1 deletion examples/usage_oop.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from __future__ import annotations

from os import environ

from hcloud import Client
from hcloud.images import Image
from hcloud.server_types import ServerType

assert (
"HCLOUD_TOKEN" in environ
), "Please export your API token in the HCLOUD_TOKEN environment variable"
token = environ["HCLOUD_TOKEN"]

# Create a client
client = Client(token="project-token")
client = Client(token=token)

# Create 2 servers
# Create 2 servers
Expand Down
9 changes: 8 additions & 1 deletion examples/usage_procedurale.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
from __future__ import annotations

from os import environ

from hcloud import Client
from hcloud.images import Image
from hcloud.server_types import ServerType
from hcloud.servers import Server
from hcloud.volumes import Volume

client = Client(token="project-token")
assert (
"HCLOUD_TOKEN" in environ
), "Please export your API token in the HCLOUD_TOKEN environment variable"
token = environ["HCLOUD_TOKEN"]

client = Client(token=token)

# Create 2 servers
response1 = client.servers.create(
Expand Down