Skip to content

Commit

Permalink
feat: add spaces config and check deletes
Browse files Browse the repository at this point in the history
  • Loading branch information
cowan-macady committed Jul 27, 2023
1 parent dc9e77a commit 96908c6
Show file tree
Hide file tree
Showing 58 changed files with 3,007 additions and 5,707 deletions.
208 changes: 104 additions & 104 deletions Pipfile.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ version: v1
managed:
enabled: true
plugins:
- remote: buf.build/protocolbuffers/plugins/python:v3.19.3-1
- plugin: buf.build/protocolbuffers/python:v23.4
out: indykite_sdk
- remote: buf.build/grpc/plugins/python
- plugin: buf.build/grpc/python:v1.56.2
out: indykite_sdk
# https://buf.build/protocolbuffers/plugins/python
# https://buf.build/grpc/plugins/python
136 changes: 128 additions & 8 deletions indykite_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from indykite_sdk.indykite.config.v1beta1.model_pb2 import (EmailServiceConfig, AuthFlowConfig, OAuth2ClientConfig,
WebAuthnProviderConfig, AuthorizationPolicyConfig,
ReadIDProviderConfig, KnowledgeGraphSchemaConfig )
from indykite_sdk.indykite.config.v1beta1.model_pb2 import OAuth2ProviderConfig, OAuth2ApplicationConfig
from indykite_sdk.indykite.config.v1beta1.model_pb2 import OAuth2ProviderConfig, OAuth2ApplicationConfig, \
UniquePropertyConstraint, UsernamePolicy
from indykite_sdk.indykite.identity.v1beta2.import_pb2 import ImportDigitalTwinsRequest, ImportDigitalTwin, \
ImportProperties, UserProvider, UserMetadata, CredentialReference
from indykite_sdk.indykite.identity.v1beta2.import_pb2 import PasswordCredential, PasswordHash, Bcrypt, SHA256
Expand Down Expand Up @@ -162,6 +163,16 @@ def main():
customer_name_parser = subparsers.add_parser("customer_name")
customer_name_parser.add_argument("customer_name", help="Customer name (not display name)")

# read_customer_config
read_customer_config_parser = subparsers.add_parser("read_customer_config")
read_customer_config_parser.add_argument("customer_id", help="Customer gid id")

# update_customer_config
update_customer_config_parser = subparsers.add_parser("update_customer_config")
update_customer_config_parser.add_argument("customer_id", help="Customer gid id")
update_customer_config_parser.add_argument("etag", help="Etag")
update_customer_config_parser.add_argument("default_auth_flow_id", help="Default auth flow gid id")

# service_account
service_account_parser = subparsers.add_parser("service_account")

Expand Down Expand Up @@ -198,6 +209,17 @@ def main():
delete_app_space_parser.add_argument("app_space_id", help="AppSpace Id (gid)")
delete_app_space_parser.add_argument("etag", nargs='?', help="Optional Etag")

# read_app_space_config
read_app_space_config_parser = subparsers.add_parser("read_app_space_config")
read_app_space_config_parser.add_argument("app_space_id", help="AppSpace gid id")

# update_app_space_config
update_app_space_config_parser = subparsers.add_parser("update_app_space_config")
update_app_space_config_parser.add_argument("app_space_id", help="AppSpace gid id")
update_app_space_config_parser.add_argument("etag", help="Etag")
update_app_space_config_parser.add_argument("tenant_id", help="Tenant default gid id")
update_app_space_config_parser.add_argument("default_auth_flow_id", help="Default auth flow gid id")

# tenant_id
tenant_id_parser = subparsers.add_parser("tenant_id")
tenant_id_parser.add_argument("tenant_id", help="Tenant id (gid)")
Expand Down Expand Up @@ -231,6 +253,16 @@ def main():
delete_tenant_parser.add_argument("tenant_id", help="Tenant Id")
delete_tenant_parser.add_argument("etag", nargs='?', help="Optional Etag")

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

# update_tenant_config
update_tenant_config_parser = subparsers.add_parser("update_tenant_config")
update_tenant_config_parser.add_argument("tenant_id", help="Tenant gid id")
update_tenant_config_parser.add_argument("etag", help="Etag")
update_tenant_config_parser.add_argument("default_auth_flow_id", help="Default auth flow gid id")

# application_id
application_id_parser = subparsers.add_parser("application_id")
application_id_parser.add_argument("application_id", help="Application id (gid)")
Expand Down Expand Up @@ -368,6 +400,11 @@ def main():
help="Service account credential id")
register_service_account_credential_pem_parser.add_argument("display_name", help="Display name")

# read_service_account_credential
read_service_account_credential_parser = subparsers.add_parser("read_service_account_credential")
read_service_account_credential_parser.add_argument("service_account_credential_id",
help="Service account credentials id (gid)")

# delete_service_account_credential
delete_service_account_credential_parser = subparsers.add_parser("delete_service_account_credential")
delete_service_account_credential_parser.add_argument("service_account_credential_id",
Expand Down Expand Up @@ -1234,6 +1271,28 @@ def main():
else:
print("Invalid customer id")

elif command == "read_customer_config":
# read_customer_config method: to get customer config info from customer gid id
bookmark = [] # or value returned by last write operation
customer_config = client_config.read_customer_config(args.customer_id, bookmark)
if customer_config:
api_helper.print_response(customer_config)
else:
print("None")

elif command == "update_customer_config":
customer_id = args.customer_id
etag = args.etag
default_auth_flow_id = args.default_auth_flow_id
bookmark = [] # or value returned by last write operation
customer_config = client_config.create_customer_config(default_auth_flow_id=default_auth_flow_id, default_email_service_id=None)
customer_config_response = client_config.update_customer_config(customer_id, etag, customer_config, bookmark)
if customer_config_response:
api_helper.print_response(customer_config_response)
else:
print("None")
return customer_config_response

elif command == "service_account":
# read_service_account method: to get service account info from service account gid id
# (extracted here from service account credentials)
Expand Down Expand Up @@ -1315,6 +1374,41 @@ def main():
print("Invalid delete_app_space_response response")
return delete_app_space_response

elif command == "read_app_space_config":
# read_app_space_config method: to get appSpace config info from appSpace gid id
bookmark = [] # or value returned by last write operation
app_space_config = client_config.read_app_space_config(args.app_space_id, bookmark)
if app_space_config:
api_helper.print_response(app_space_config)
else:
print("None")

elif command == "update_app_space_config":
app_space_id = args.app_space_id
etag = args.etag
tenant_id = args.tenant_id
default_auth_flow_id = args.default_auth_flow_id
bookmark = [] # or value returned by last write operation
app_space_config = client_config.create_app_space_config(
default_tenant_id=tenant_id,
default_auth_flow_id=default_auth_flow_id,
default_email_service_id=None,
unique_property_constraints={"constraint" : client_config.unique_property_constraints(
tenant_unique=True,
canonicalization=["unicode", "case-insensitive"])},
username_policy=client_config.username_policy(
allowed_username_formats=["email", "mobile", "username"],
valid_email=False,
verify_email=False
)
)
app_space_config_response = client_config.update_app_space_config(app_space_id, etag, app_space_config, bookmark)
if app_space_config_response:
api_helper.print_response(app_space_config_response)
else:
print("None")
return app_space_config_response

elif command == "tenant_id":
tenant_id = args.tenant_id
tenant = client_config.read_tenant_by_id(tenant_id)
Expand Down Expand Up @@ -1386,6 +1480,36 @@ def main():
print("Invalid delete_tenant_response response")
return delete_tenant_response

elif command == "read_tenant_config":
# read_tenant_config method: to get tenant config info from tenant gid id
bookmark = [] # or value returned by last write operation
tenant_config = client_config.read_tenant_config(args.tenant_id, bookmark)
if tenant_config:
api_helper.print_response(tenant_config)
else:
print("None")

elif command == "update_tenant_config":
tenant_id = args.tenant_id
etag = args.etag
default_auth_flow_id = args.default_auth_flow_id
bookmark = [] # or value returned by last write operation
tenant_config = client_config.create_tenant_config(
default_auth_flow_id=default_auth_flow_id,
default_email_service_id=None,
username_policy=client_config.username_policy(
allowed_username_formats=["email", "mobile", "username"],
valid_email=False,
verify_email=False
)
)
tenant_config_response = client_config.update_tenant_config(tenant_id, etag, tenant_config, bookmark)
if tenant_config_response:
api_helper.print_response(tenant_config_response)
else:
print("None")
return tenant_config_response

elif command == "application_id":
application_id = args.application_id
application = client_config.read_application_by_id(application_id)
Expand Down Expand Up @@ -1713,7 +1837,7 @@ def main():
print("Invalid delete_service_account response")
return delete_service_account_response

elif command == "service_account_credential":
elif command == "read_service_account_credential":
service_account_credential_id = args.service_account_credential_id
service_account_credential = client_config.read_service_account_credential(service_account_credential_id)
if service_account_credential:
Expand Down Expand Up @@ -1803,7 +1927,6 @@ def main():

email_service_config = EmailServiceConfig(
default_from_address=Email(address=default_from_address_address,name=default_from_address_name),
default=wrappers.BoolValue(value=True),
sendgrid=sendgrid,
authentication_message=EmailDefinition(
message=EmailMessage(
Expand Down Expand Up @@ -1866,7 +1989,6 @@ def main():
address=default_from_address_address,
name=default_from_address_name
),
default=wrappers.BoolValue(value=True),
sendgrid=sendgrid,
authentication_message=EmailDefinition(
message=EmailMessage(
Expand Down Expand Up @@ -1917,8 +2039,7 @@ def main():
# only bare JSON or YAML source_format is support as input
auth_flow_config = client_config.auth_flow_config(
source_format="FORMAT_BARE_JSON",
source=user_dict,
default=False
source=user_dict
)

create_auth_flow_config_node_response = client_config.create_auth_flow_config_node(
Expand Down Expand Up @@ -1949,8 +2070,7 @@ def main():
# only bare JSON or YAML source_format is support as input
auth_flow_config = client_config.auth_flow_config(
source_format="FORMAT_BARE_JSON",
source=user_dict,
default=False
source=user_dict
)

update_auth_flow_config_node_response = client_config.update_auth_flow_config_node(
Expand Down
15 changes: 9 additions & 6 deletions indykite_sdk/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ def __init__(self, local=False):
raise exception(...).with_traceback(tb)

# Imported methods
from .customer import read_customer_by_id, read_customer_by_name
from .customer import read_customer_by_id, read_customer_by_name, read_customer_config, update_customer_config, \
create_customer_config
from .service_account import read_service_account, read_service_account_by_name, create_service_account, \
update_service_account, delete_service_account
from .app_space import read_app_space_by_id, read_app_space_by_name, create_app_space, update_app_space, \
list_app_spaces, delete_app_space
from .tenant import read_tenant_by_id, read_tenant_by_name, create_tenant, update_tenant, list_tenants, delete_tenant
list_app_spaces, delete_app_space, read_app_space_config, update_app_space_config, create_app_space_config, \
unique_property_constraints
from .tenant import read_tenant_by_id, read_tenant_by_name, create_tenant, update_tenant, list_tenants, \
delete_tenant, create_tenant_config, update_tenant_config, read_tenant_config
from .application import read_application_by_id, read_application_by_name, create_application, update_application, \
list_applications, delete_application
from .application_agent import read_application_agent_by_id, read_application_agent_by_name, \
Expand All @@ -68,7 +71,8 @@ def __init__(self, local=False):
from .service_account_credential import read_service_account_credential, register_service_account_credential_jwk, \
register_service_account_credential_pem, delete_service_account_credential
from .config_node import create_email_service_config_node, read_config_node, \
update_email_service_config_node, delete_config_node, create_auth_flow_config_node, update_auth_flow_config_node, \
update_email_service_config_node, delete_config_node, create_auth_flow_config_node, \
update_auth_flow_config_node, \
create_oauth2_client_config_node, update_oauth2_client_config_node, \
create_webauthn_provider_config_node, update_webauthn_provider_config_node, \
create_authorization_policy_config_node, update_authorization_policy_config_node, \
Expand All @@ -84,5 +88,4 @@ def __init__(self, local=False):
delete_oauth2_application
from .create_application_with_agent_credentials import create_application_with_agent_credentials
from .get_schema import get_schema_helpers


from .username_policy import username_policy
104 changes: 104 additions & 0 deletions indykite_sdk/config/app_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
from indykite_sdk.indykite.config.v1beta1.model_pb2 import google_dot_protobuf_dot_wrappers__pb2 as wrappers
from indykite_sdk.model.create_app_space import CreateApplicationSpace
from indykite_sdk.model.update_app_space import UpdateApplicationSpace
from indykite_sdk.model.read_app_space_config import ReadApplicationSpaceConfig
from indykite_sdk.model.update_app_space_config import UpdateApplicationSpaceConfig
from indykite_sdk.indykite.config.v1beta1.model_pb2 import ApplicationSpaceConfig, UniquePropertyConstraint, \
UsernamePolicy
import sys
import indykite_sdk.utils.logger as logger

Expand Down Expand Up @@ -180,3 +184,103 @@ def delete_app_space(self, app_space_id, etag, bookmarks):
return None

return response


def read_app_space_config(self, app_space_id, bookmarks=[]):
"""
get ApplicationSpaceConfig object from appSpace id
:param self:
:param app_space_id: string gid id
:param bookmarks: list of strings with pattern: ^[a-zA-Z0-9_-]{40,}$
:return: deserialized ReadApplicationSpaceResponse object
"""
sys.excepthook = logger.handle_excepthook
try:
response = self.stub.ReadApplicationSpaceConfig(
pb2.ReadApplicationSpaceConfigRequest(
id=str(app_space_id),
bookmarks=bookmarks
)
)
except Exception as exception:
return logger.logger_error(exception)

if not response:
return None

return ReadApplicationSpaceConfig.deserialize(response)


def update_app_space_config(self, app_space_id, etag, app_space_config, bookmarks=[]):
"""
get ApplicationSpaceConfig object from app_space_id
:param self:
:param app_space_id: string gid id
:param etag: string
:param app_space_config: ApplicationSpaceConfig
:param bookmarks: list of strings with pattern: ^[a-zA-Z0-9_-]{40,}$
:return: deserialized UpdateApplicationSpaceConfigResponse object
"""
sys.excepthook = logger.handle_excepthook
try:
response = self.stub.UpdateApplicationSpaceConfig(
pb2.UpdateApplicationSpaceConfigRequest(
id=str(app_space_id),
etag=wrappers.StringValue(value=etag),
config=app_space_config,
bookmarks=bookmarks
)
)
except Exception as exception:
return logger.logger_error(exception)

if not response:
return None
return UpdateApplicationSpaceConfig.deserialize(response)


def create_app_space_config(
self,
default_tenant_id=None,
default_auth_flow_id=None,
default_email_service_id=None,
unique_property_constraints={},
username_policy=None
):
"""
get ApplicationSpaceConfig object from default_auth_flow_id or default_email_service_id
:param self:
:param default_tenant_id: string gid id
:param default_auth_flow_id: string gid id
:param default_email_service_id: string gid id
:param unique_property_constraints: map<string, UniquePropertyConstraint>
:param username_policy: UsernamePolicy
:return: ApplicationSpaceConfig
"""
sys.excepthook = logger.handle_excepthook
try:
response = ApplicationSpaceConfig(
default_tenant_id=default_tenant_id,
default_auth_flow_id=default_auth_flow_id,
default_email_service_id=default_email_service_id,
unique_property_constraints=unique_property_constraints,
username_policy=username_policy
)
return response
except Exception as exception:
return logger.logger_error(exception)


def unique_property_constraints(self, tenant_unique, canonicalization):
"""
create UniquePropertyConstraint
:param self:
:param tenant_unique: bool -> if true the value will be unique only in Tenant and not across multiple tenants
:param canonicalization: [] in ["unicode", "case-insensitive"]
:return: UniquePropertyConstraint object
"""
property = UniquePropertyConstraint(
tenant_unique=bool(tenant_unique),
canonicalization=canonicalization
)
return property

0 comments on commit 96908c6

Please sign in to comment.