-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f76a6d7
commit 6373f31
Showing
2 changed files
with
108 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters