Skip to content

Commit

Permalink
Fix indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
stefannica committed Feb 7, 2025
1 parent f76a6d7 commit 6373f31
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 118 deletions.
206 changes: 100 additions & 106 deletions docs/book/getting-started/zenml-pro/self-hosted.md
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ The above are infrastructure requirements for ZenML Pro. If, in addition to ZenM
### Set up Credentials
If your Kubernetes cluster is not set to be authenticated to the container registry where the ZenML Pro container images are hosted, you will need to create a secret to allow the ZenML Pro server to pull the images. The following is an example of how to do this if you're received a private access key for the ZenML GCP Artifact Registry, but you can use the same approach for your own private container registry:
If your Kubernetes cluster is not set to be authenticated to the container registry where the ZenML Pro container images are hosted, you will need to create a secret to allow the ZenML Pro server to pull the images. The following is an example of how to do this if you've received a private access key for the ZenML GCP Artifact Registry from ZenML, but you can use the same approach for your own private container registry:

```
kubectl create ns zenml-pro
Expand Down Expand Up @@ -811,120 +811,114 @@ However, this feature is currently supported with helper Python scripts, as desc
{% endhint %}

1. The deployed ZenML Pro service will come with a pre-installed default administrator account. This admin account serves the purpose of creating and recovering other users. First you will need to get the admin password following the instructions at the previous step.
```bash
kubectl get secret --namespace zenml-pro zenml-pro -o jsonpath="{.data.ZENML_CLOUD_ADMIN_PASSWORD}" | base64 --decode; echo
```
2. Create a `users.yml` file that contains a list of all the users that you want to create for ZenML. Also set a default password. The users will be asked to change this password on their first login.
```yaml
users:
- email: [email protected]
password: tu3]4_Xz{5$9
```
3. Run the `create_users.py` script below. This will create all of the users.
**[file: create_users.py]**
```python
import getpass
from typing import Optional
import requests
import yaml
import sys
# Configuration
LOGIN_ENDPOINT = "/api/v1/auth/login"
USERS_ENDPOINT = "/api/v1/users"
def login(base_url: str, username: str, password: str):
"""Log in and return the authentication token."""
# Define the headers
headers = {
'accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
}
# Define the data payload
data = {
'grant_type': '',
'username': username,
'password': password,
'client_id': '',
'client_secret': '',
'device_code': '',
'audience': ''
}
login_url = f"{base_url}{LOGIN_ENDPOINT}"
response = requests.post(login_url, headers=headers, data=data)
```bash
kubectl get secret --namespace zenml-pro zenml-pro -o jsonpath="{.data.ZENML_CLOUD_ADMIN_PASSWORD}" | base64 --decode; echo
```

1. Create a `users.yml` file that contains a list of all the users that you want to create for ZenML. Also set a default password. The users will be asked to change this password on their first login.

```yaml
users:
- email: [email protected]
password: tu3]4_Xz{5$9
```

1. Run the `create_users.py` script below. This will create all of the users.

**[file: create_users.py]**

```python
import getpass
from typing import Optional
import requests
import yaml
import sys
# Configuration
LOGIN_ENDPOINT = "/api/v1/auth/login"
USERS_ENDPOINT = "/api/v1/users"
def login(base_url: str, username: str, password: str):
"""Log in and return the authentication token."""
# Define the headers
headers = {
'accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
}
# Define the data payload
data = {
'grant_type': '',
'username': username,
'password': password,
'client_id': '',
'client_secret': '',
'device_code': '',
'audience': ''
}
login_url = f"{base_url}{LOGIN_ENDPOINT}"
response = requests.post(login_url, headers=headers, data=data)
if response.status_code == 200:
return response.json().get("token")
else:
print(f"Login failed. Status code: {response.status_code}")
print(f"Response: {response.text}")
sys.exit(1)
def create_user(token: str, base_url: str, email: str, password: Optional[str]):
"""Create a user with the given email."""
users_url = f"{base_url}{USERS_ENDPOINT}"
params = {
'email': email,
'password': password
}
# Define the headers
headers = {
'accept': 'application/json',
"Authorization": f"Bearer {token}"
}
if response.status_code == 200:
return response.json().get("token")
else:
print(f"Login failed. Status code: {response.status_code}")
print(f"Response: {response.text}")
sys.exit(1)
# Make the POST request
response = requests.post(users_url, params=params, headers=headers, data='')
def create_user(token: str, base_url: str, email: str, password: Optional[str]):
"""Create a user with the given email."""
users_url = f"{base_url}{USERS_ENDPOINT}"
params = {
'email': email,
'password': password
}
if response.status_code == 200:
print(f"User created successfully: {email}")
else:
print(f"Failed to create user: {email}")
print(f"Status code: {response.status_code}")
print(f"Response: {response.text}")
# Define the headers
headers = {
'accept': 'application/json',
"Authorization": f"Bearer {token}"
}
def main():
# Get login credentials
base_url = input("ZenML URL: ")
username = input("Enter username: ")
password = getpass.getpass("Enter password: ")
# Get the YAML file path
yaml_file = input("Enter the path to the YAML file containing email addresses: ")
# Make the POST request
response = requests.post(users_url, params=params, headers=headers, data='')
# Login and get token
token = login(base_url, username, password)
print("Login successful.")
if response.status_code == 200:
print(f"User created successfully: {email}")
else:
print(f"Failed to create user: {email}")
print(f"Status code: {response.status_code}")
print(f"Response: {response.text}")
# Read users from YAML file
try:
with open(yaml_file, 'r') as file:
data = yaml.safe_load(file)
except Exception as e:
print(f"Error reading YAML file: {e}")
sys.exit(1)
def main():
# Get login credentials
base_url = input("ZenML URL: ")
username = input("Enter username: ")
password = getpass.getpass("Enter password: ")
# Get the YAML file path
yaml_file = input("Enter the path to the YAML file containing email addresses: ")
# Login and get token
token = login(base_url, username, password)
print("Login successful.")
# Read users from YAML file
try:
with open(yaml_file, 'r') as file:
data = yaml.safe_load(file)
except Exception as e:
print(f"Error reading YAML file: {e}")
sys.exit(1)
users = data['users']
users = data['users']
# Create users
if isinstance(users, list):
for user in users:
create_user(token, base_url, user["email"], user["password"])
else:
print("Invalid YAML format. Expected a list of email addresses.")
# Create users
if isinstance(users, list):
for user in users:
create_user(token, base_url, user["email"], user["password"])
else:
print("Invalid YAML format. Expected a list of email addresses.")
if __name__ == "__main__":
main()
```
if __name__ == "__main__":
main()
```
The script will prompt you for the URL of your deployment, the admin account email and admin account password and finally the location of your `users.yml` file.
Expand Down
20 changes: 8 additions & 12 deletions docs/book/reference/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,14 @@ You can generate a short-lived (1 hour) API token from your ZenML dashboard. Thi
1. Generate a short-lived API token through the API Tokens page under your ZenML dashboard server settings, as documented in the [Using an API token](../how-to/manage-zenml-server/connecting-to-zenml/connect-with-an-api-token.md) guide.

2. Use the API token as the bearer token in your HTTP requests. For example, you can use the following command to check your current user:

* using curl:

```bash
curl -H "Authorization: Bearer YOUR_API_TOKEN" https://your-zenml-server/api/v1/current-user
```

* using wget:

```bash
wget -qO- --header="Authorization: Bearer YOUR_API_TOKEN" https://your-zenml-server/api/v1/current-user
```
* using curl:
```bash
curl -H "Authorization: Bearer YOUR_API_TOKEN" https://your-zenml-server/api/v1/current-user
```
* using wget:
```bash
wget -qO- --header="Authorization: Bearer YOUR_API_TOKEN" https://your-zenml-server/api/v1/current-user
```

{% hint style="info" %}
**Important Notes**
Expand Down

0 comments on commit 6373f31

Please sign in to comment.