-
-
Notifications
You must be signed in to change notification settings - Fork 10
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 #151 from tdviet/devel
Initial version of fedcloud.client module
- Loading branch information
Showing
7 changed files
with
122 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
""" | ||
Decorators for command-line parameters | ||
""" | ||
|
||
from functools import wraps | ||
|
||
import click | ||
|
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,82 @@ | ||
""" | ||
Implementation of "fedcloud secret" commands for accessing secret management service | ||
""" | ||
|
||
import click | ||
import hvac | ||
|
||
from tabulate import tabulate | ||
|
||
from fedcloudclient.checkin import get_checkin_id | ||
from fedcloudclient.decorators import oidc_params | ||
|
||
VAULT_ADDR = "https://vault.services.fedcloud.eu:8200" | ||
VAULT_ROLE = "demo" | ||
VAULT_MOUNT_POINT = "/secrets" | ||
|
||
|
||
def secret_client(access_token, command, path, data): | ||
""" | ||
Client function for accessing secrets | ||
:param path: path to secret | ||
:param access_token: access token for authentication | ||
:param command: the command to perform | ||
:param data: input data | ||
:return: Output data from the service | ||
""" | ||
|
||
client = hvac.Client(url=VAULT_ADDR) | ||
client.auth.jwt.jwt_login(role=VAULT_ROLE, jwt=access_token) | ||
checkin_id = get_checkin_id(access_token) | ||
full_path = checkin_id + "/" + path | ||
function_list = { | ||
"list_secrets": client.secrets.kv.v1.list_secrets, | ||
"read_secret": client.secrets.kv.v1.read_secret, | ||
"delete_secret": client.secrets.kv.v1.read_secret, | ||
} | ||
if command == "set": | ||
response = client.secrets.kv.v1.create_or_update_secret( | ||
path=full_path, | ||
mount_point=VAULT_MOUNT_POINT, | ||
secret=data, | ||
) | ||
else: | ||
response = function_list[command](path=full_path, mount_point=VAULT_MOUNT_POINT) | ||
return response | ||
|
||
|
||
@click.group() | ||
def secret(): | ||
""" | ||
Commands for accessing secrets | ||
""" | ||
|
||
|
||
@secret.command() | ||
@oidc_params | ||
@click.argument("short_path") | ||
def get( | ||
access_token, | ||
short_path, | ||
): | ||
""" | ||
Get a secret from the path | ||
""" | ||
|
||
data = secret_client(access_token, "read_secret", short_path, None) | ||
print(tabulate(data["data"].items(), headers=["key", "value"])) | ||
|
||
|
||
@secret.command("list") | ||
@oidc_params | ||
@click.argument("short_path", required=False, default="") | ||
def list_( | ||
access_token, | ||
short_path, | ||
): | ||
""" | ||
List secrets in the path | ||
""" | ||
|
||
data = secret_client(access_token, "list_secrets", short_path, None) | ||
print("\n".join(map(str, data["data"]["keys"]))) |
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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
click>=8.0.1 | ||
click==8.1.3 | ||
click_option_group>=0.5.3 | ||
tabulate | ||
requests | ||
defusedxml | ||
pyjwt>=2.0.1 | ||
python-openstackclient | ||
liboidcagent | ||
tabulate~=0.8.9 | ||
requests==2.28.0 | ||
defusedxml==0.7.1 | ||
pyjwt==2.4.0 | ||
python-openstackclient==5.8.0 | ||
liboidcagent==0.4.0 | ||
jsonpath-ng==1.5.3 | ||
PyYAML>=5.4.1 | ||
setuptools | ||
jsonschema | ||
psutil | ||
PyYAML==6.0 | ||
setuptools==62.6.0 | ||
jsonschema==4.6.0 | ||
psutil==5.9.1 | ||
hvac~=0.11.2 |