This repository has been archived by the owner on Sep 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #744 from zhxu73/argo_deploy
Using Argo Workflow to Deploy Instance
- Loading branch information
Showing
16 changed files
with
1,665 additions
and
11 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
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
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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"default": { | ||
"type": "string", | ||
"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" | ||
} | ||
}, | ||
"patternProperties": { | ||
"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$": { | ||
"$ref": "#/definitions/provider" | ||
} | ||
}, | ||
"definitions" : { | ||
"provider": { | ||
"properties": { | ||
"api_host": {"type": "string"}, | ||
"api_port": { | ||
"type": "integer", | ||
"minimum": 0, | ||
"maximum": 65535 | ||
}, | ||
"token": {"type": "string"}, | ||
"namespace": {"type": "string"}, | ||
"workflow_base_dir": {"type": "string"}, | ||
"zoneinfo": {"type": "string"}, | ||
"ssl_verify": {"type": "boolean"} | ||
}, | ||
"required": ["api_host", "api_port", "token", "namespace", "workflow_base_dir", "zoneinfo", "ssl_verify"] | ||
} | ||
}, | ||
"required": ["default"], | ||
"additionalProperties": false | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#!/usr/bin/env python | ||
""" | ||
Create access token for users | ||
Usage: | ||
python scripts/batch_create_access_token.py --token-name workshop_token --users name1,name2,name3 | ||
""" | ||
import django | ||
|
||
django.setup() | ||
|
||
import argparse | ||
from core.models import AccessToken | ||
from core.models.user import AtmosphereUser | ||
from core.models.access_token import create_access_token | ||
|
||
|
||
def parse_arg(): | ||
""" | ||
Parse command line arguments. | ||
Returns: | ||
argparse.Namespace: result | ||
""" | ||
parser = argparse.ArgumentParser( | ||
description="create or fetch tokens for users" | ||
) | ||
parser.add_argument( | ||
"--users", | ||
dest="users", | ||
type=str, | ||
required=True, | ||
help="usernames, comma separated if more than 1(no space)" | ||
) | ||
parser.add_argument( | ||
"--token-name", | ||
dest="token_name", | ||
type=str, | ||
required=True, | ||
help="name of the token" | ||
) | ||
|
||
args = parser.parse_args() | ||
args.users = args.users.split(',') | ||
return args | ||
|
||
|
||
def fetch_user_by_username(username): | ||
""" | ||
Fetch user by username | ||
Args: | ||
username (str): username of the user | ||
Returns: | ||
Optional[AtmosphereUser]: user | ||
""" | ||
try: | ||
return AtmosphereUser.objects.get(username=username) | ||
except Exception as exc: | ||
print("unable to fetch user {}".format(username)) | ||
print(exc) | ||
return None | ||
|
||
|
||
def create_or_fetch_token_for_user(user, token_name): | ||
""" | ||
Fetch token with given name for user, create a token if none exists with the same name | ||
Args: | ||
user (AtmosphereUser): user | ||
token_name (str): name of the token | ||
Returns: | ||
str: token | ||
""" | ||
# check if there is any existing token by the same name | ||
existing_tokens = AccessToken.objects.filter(token__user=user) | ||
for token in existing_tokens: | ||
if token.name == token_name: | ||
# return token if same name | ||
return token.token_id | ||
# create new token if none with the same name exists | ||
new_token = create_access_token( | ||
user, token_name, issuer="Personal-Access-Token" | ||
) | ||
print("new token created for user {}".format(user.username)) | ||
return new_token.token_id | ||
|
||
|
||
def main(): | ||
""" | ||
Entrypoint | ||
""" | ||
args = parse_arg() | ||
for username in args.users: | ||
user = fetch_user_by_username(username) | ||
token = create_or_fetch_token_for_user(user, args.token_name) | ||
print("{}, {}".format(username, token)) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Empty file.
Oops, something went wrong.