Skip to content

Commit

Permalink
feat: add config methods appspaces tenants
Browse files Browse the repository at this point in the history
  • Loading branch information
gg authored and oceane-sailorin committed Oct 24, 2022
1 parent 82b7505 commit 92b6c14
Show file tree
Hide file tree
Showing 18 changed files with 1,447 additions and 46 deletions.
176 changes: 175 additions & 1 deletion jarvis_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def main():

# customer_id
customer_id_parser = subparsers.add_parser("customer_id")
#customer_parser.add_argument("access_token", help="JWT bearer token")
# customer_parser.add_argument("access_token", help="JWT bearer token")

# customer_name
customer_name_parser = subparsers.add_parser("customer_name")
Expand All @@ -129,6 +129,63 @@ def main():
app_space_name_parser.add_argument("app_space_name", help="App Space name (not display name)")
app_space_name_parser.add_argument("customer_id", help="Customer Id (gid)")

# create_app_space
create_app_space_parser = subparsers.add_parser("create_app_space")
create_app_space_parser.add_argument("customer_id", help="Customer Id (gid)")
create_app_space_parser.add_argument("app_space_name", help="App Space name (not display name)")
create_app_space_parser.add_argument("display_name", help="Display Name")

# update_app_space
update_app_space_parser = subparsers.add_parser("update_app_space")
update_app_space_parser.add_argument("app_space_id", help="AppSpace Id (gid)")
update_app_space_parser.add_argument("etag", help="Etag")
update_app_space_parser.add_argument("display_name", help="Display Name")

# list_app_spaces
list_app_spaces_parser = subparsers.add_parser("list_app_spaces")
list_app_spaces_parser.add_argument("customer_id", help="Customer Id (gid)")
list_app_spaces_parser.add_argument("match_list", help="Matching names separated by ,",
type=lambda s: [str(item) for item in s.split(',')])
list_app_spaces_parser.add_argument("bookmark", nargs='*', help="Optional list of bookmarks separated by space")

# delete_app_space
delete_app_space_parser = subparsers.add_parser("delete_app_space")
delete_app_space_parser.add_argument("app_space_id", help="AppSpace Id (gid)")
delete_app_space_parser.add_argument("etag", nargs='?', help="Optional Etag")

# tenant_id
tenant_id_parser = subparsers.add_parser("tenant_id")
tenant_id_parser.add_argument("tenant_id", help="Tenant id (gid)")

# tenant_name
tenant_name_parser = subparsers.add_parser("tenant_name")
tenant_name_parser.add_argument("tenant_name", help="Tenant name (not display name)")
tenant_name_parser.add_argument("app_space_id", help="AppSpace Id (gid)")

# create_tenant
create_tenant_parser = subparsers.add_parser("create_tenant")
create_tenant_parser.add_argument("issuer_id", help="Issuer Id (gid)")
create_tenant_parser.add_argument("tenant_name", help="Tenant name (not display name)")
create_tenant_parser.add_argument("display_name", help="Display Name")

# update_tenant
update_tenant_parser = subparsers.add_parser("update_tenant")
update_tenant_parser.add_argument("tenant_id", help="Tenant Id")
update_tenant_parser.add_argument("etag", help="Etag")
update_tenant_parser.add_argument("display_name", help="Display Name")

# list_tenants
list_tenants_parser = subparsers.add_parser("list_tenants")
list_tenants_parser.add_argument("app_space_id", help="AppSpace Id (gid)")
list_tenants_parser.add_argument("match_list", help="Matching names separated by ,",
type=lambda s: [str(item) for item in s.split(',')])
list_tenants_parser.add_argument("bookmark", nargs='*', help="Optional list of bookmarks separated by space")

# delete_tenant
delete_tenant_parser = subparsers.add_parser("delete_tenant")
delete_tenant_parser.add_argument("tenant_id", help="Tenant Id")
delete_tenant_parser.add_argument("etag", nargs='?', help="Optional Etag")

args = parser.parse_args()

local = args.local
Expand Down Expand Up @@ -309,6 +366,123 @@ def main():
else:
print("Invalid app_space name")

elif command == "create_app_space":
app_space_name = args.app_space_name
customer_id = args.customer_id
display_name = args.display_name
app_space_response = client_config.create_app_space(customer_id, app_space_name, display_name,"description", [])
if app_space_response:
print_response(app_space_response)
else:
print("Invalid app_space response")
return app_space_response

elif command == "update_app_space":
app_space_id = args.app_space_id
etag = args.etag
display_name = args.display_name
app_space_response = client_config.update_app_space(app_space_id, etag, display_name,"description update", [])
if app_space_response:
print_response(app_space_response)
else:
print("Invalid app_space response")
return app_space_response

elif command == "list_app_spaces":
customer_id = args.customer_id
match_list = args.match_list
if args.bookmark:
bookmark = args.bookmark
else:
bookmark = []
list_app_spaces_response = client_config.list_app_spaces(customer_id, match_list, bookmark)
if list_app_spaces_response:
print(list_app_spaces_response)
else:
print("Invalid list_app_spaces response")
return list_app_spaces_response

elif command == "delete_app_space":
app_space_id = args.app_space_id
if args.etag:
etag = args.etag
else:
etag = None

delete_app_space_response = client_config.delete_app_space(app_space_id, etag, [])
if delete_app_space_response:
print(delete_app_space_response)
else:
print("Invalid delete_app_space_response response")
return delete_app_space_response

elif command == "tenant_id":
tenant_id = args.tenant_id
tenant = client_config.get_tenant_by_id(tenant_id)
if tenant:
print_response(tenant)
else:
print("Invalid tenant id")

elif command == "tenant_name":
tenant_name = args.tenant_name
app_space_id = args.app_space_id
tenant = client_config.get_tenant_by_name(app_space_id, tenant_name)
if tenant:
print_response(tenant)
else:
print("Invalid tenant name")

elif command == "create_tenant":
tenant_name = args.tenant_name
issuer_id = args.issuer_id
display_name = args.display_name
tenant_response = client_config.create_tenant(issuer_id, tenant_name, display_name,"description", [])
if tenant_response:
print_response(tenant_response)
else:
print("Invalid tenant response")
return tenant_response

elif command == "update_tenant":
tenant_id = args.tenant_id
etag = args.etag
display_name = args.display_name
tenant_response = client_config.update_tenant(tenant_id, etag, display_name,"description update", [])
if tenant_response:
print_response(tenant_response)
else:
print("Invalid tenant response")
return tenant_response

elif command == "list_tenants":
app_space_id = args.app_space_id
match_list = args.match_list
if args.bookmark:
bookmark = args.bookmark
else:
bookmark = []
list_tenants_response = client_config.list_tenants(app_space_id, match_list, bookmark)
if list_tenants_response:
print(list_tenants_response)
else:
print("Invalid list_tenants response")
return list_tenants_response

elif command == "delete_tenant":
tenant_id = args.tenant_id
if args.etag:
etag = args.etag
else:
etag = None

delete_tenant_response = client_config.delete_tenant(tenant_id, etag, [])
if delete_tenant_response:
print(delete_tenant_response)
else:
print("Invalid delete_tenant_response response")
return delete_tenant_response


def print_verify_info(digital_twin_info): # pragma: no cover
print("Digital twin info")
Expand Down
3 changes: 2 additions & 1 deletion jarvis_sdk/cmdconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(self, local=False):
# Imported methods
from ._customer import get_customer_by_id, get_customer_by_name
from ._service_account import get_service_account
from ._app_space import get_app_space_by_id, get_app_space_by_name
from ._app_space import get_app_space_by_id, get_app_space_by_name, create_app_space, update_app_space, list_app_spaces, delete_app_space
from ._tenant import get_tenant_by_id, get_tenant_by_name, create_tenant, update_tenant, list_tenants, delete_tenant


88 changes: 86 additions & 2 deletions jarvis_sdk/cmdconfig/_app_space.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import uuid

from jarvis_sdk.cmdconfig import helper
from jarvis_sdk.indykite.config.v1beta1 import config_management_api_pb2 as pb2
from jarvis_sdk.indykite.config.v1beta1 import model_pb2 as model
from jarvis_sdk.model.app_space import ApplicationSpace
from jarvis_sdk.indykite.config.v1beta1.model_pb2 import UniqueNameIdentifier
from jarvis_sdk.indykite.config.v1beta1.model_pb2 import google_dot_protobuf_dot_wrappers__pb2 as wrappers
from jarvis_sdk.model.create_app_space import CreateApplicationSpace
from jarvis_sdk.model.update_app_space import UpdateApplicationSpace


def get_app_space_by_id(self, app_space_id):
Expand Down Expand Up @@ -42,3 +43,86 @@ def get_app_space_by_name(self, customer_id, app_space_name):
return ApplicationSpace.deserialize(response.app_space)


def create_app_space(self, customer_id, name, display_name, description="", bookmarks=[]):

try:
response = self.stub.CreateApplicationSpace(
pb2.CreateApplicationSpaceRequest(
customer_id=customer_id,name=name, display_name=wrappers.StringValue(value=display_name),
description=wrappers.StringValue(value=description), bookmarks=bookmarks
)
)
except Exception as exception:
print(exception)
return None

if not response:
return None

return CreateApplicationSpace.deserialize(response)


def update_app_space(self, app_space_id, etag, display_name, description="", bookmarks=[]):

try:
response = self.stub.UpdateApplicationSpace(
pb2.UpdateApplicationSpaceRequest(
id=app_space_id,etag=wrappers.StringValue(value=etag),
display_name=wrappers.StringValue(value=display_name),
description=wrappers.StringValue(value=description), bookmarks=bookmarks
)
)
except Exception as exception:
print(exception)
return None

if not response:
return None

return UpdateApplicationSpace.deserialize(response)


def list_app_spaces(self, customer_id, match=[], bookmarks=[]):

try:
streams = self.stub.ListApplicationSpaces(
pb2.ListApplicationSpacesRequest(
customer_id=customer_id,match=match,
bookmarks=bookmarks
)
)
except Exception as exception:
print(exception)
return None

if not streams:
return None

responses = []
try:
for response in streams:
responses.append(response)
except Exception as exception:
print(exception)
return None

return responses


def delete_app_space(self, app_space_id, etag, bookmarks):

try:
response = self.stub.DeleteApplicationSpace(
pb2.DeleteApplicationSpaceRequest(
id=app_space_id, etag=wrappers.StringValue(value=etag),
bookmarks=bookmarks
)
)
except Exception as exception:
print(exception)
return None

if not response:
return None

return response

0 comments on commit 92b6c14

Please sign in to comment.