Skip to content

Commit

Permalink
feat: change options and add tags
Browse files Browse the repository at this point in the history
  • Loading branch information
cowan-macady committed Apr 27, 2023
1 parent 73c8a4a commit 8b42995
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 190 deletions.
57 changes: 40 additions & 17 deletions indykite_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1978,8 +1978,14 @@ def main():
actions = ["ACTION1", "ACTION2"]
resources = [IsAuthorizedResource("resourceID", "TypeName", actions),
IsAuthorizedResource("resource2ID", "TypeName", actions)]
options = {"age": "21"}
is_authorized = client_authorization.is_authorized_digital_twin(digital_twin_id, tenant_id, resources, options)
input_params = {"age": "21"}
policy_tags = ["Car", "Rental", "Sharing"]
is_authorized = client_authorization.is_authorized_digital_twin(
digital_twin_id,
tenant_id,
resources,
input_params,
policy_tags)

if is_authorized:
print_response(is_authorized)
Expand All @@ -1992,8 +1998,8 @@ def main():
actions = ["ACTION1", "ACTION2"]
resources = [IsAuthorizedResource("resourceID", "TypeName", actions),
IsAuthorizedResource("resource2ID", "TypeName", actions)]
options = {}
is_authorized = client_authorization.is_authorized_token(access_token, resources, options)
input_params = {}
is_authorized = client_authorization.is_authorized_token(access_token, resources, input_params, [])
if is_authorized:
print_response(is_authorized)
else:
Expand All @@ -2006,9 +2012,13 @@ def main():
actions = ["ACTION1", "ACTION2"]
resources = [IsAuthorizedResource("resourceID", "TypeName", actions),
IsAuthorizedResource("resource2ID", "TypeName", actions)]
options = {"age":"21"}
is_authorized = client_authorization.is_authorized_property_filter(property_type, property_value,
resources=resources, options=options)
input_params = {"age":"21"}
is_authorized = client_authorization.is_authorized_property_filter(
property_type,
property_value,
resources,
input_params,
[])
if is_authorized:
print_response(is_authorized)
else:
Expand All @@ -2021,8 +2031,14 @@ def main():
actions = ["ACTION1", "ACTION2"]
resource_types = [WhatAuthorizedResourceTypes("TypeName", actions),
WhatAuthorizedResourceTypes("TypeNameSecond", actions)]
options = {"age": "21"}
what_authorized = client_authorization.what_authorized_digital_twin(digital_twin_id, tenant_id, resource_types, options)
input_params = {"age": "21"}
policy_tags = ["Car", "Rental", "Sharing"]
what_authorized = client_authorization.what_authorized_digital_twin(
digital_twin_id,
tenant_id,
resource_types,
input_params,
policy_tags)

if what_authorized:
print_response(what_authorized)
Expand All @@ -2035,8 +2051,8 @@ def main():
actions = ["ACTION1", "ACTION2"]
resource_types = [WhatAuthorizedResourceTypes("TypeName", actions),
WhatAuthorizedResourceTypes("TypeNameSecond", actions)]
options = {}
what_authorized = client_authorization.what_authorized_token(access_token, resource_types, options)
input_params = {}
what_authorized = client_authorization.what_authorized_token(access_token, resource_types, input_params, [])
if what_authorized:
print_response(what_authorized)
else:
Expand All @@ -2049,10 +2065,13 @@ def main():
actions = ["ACTION1", "ACTION2"]
resource_types = [WhatAuthorizedResourceTypes("TypeName", actions),
WhatAuthorizedResourceTypes("TypeNameSecond", actions)]
options = {"age":"21"}
what_authorized = client_authorization.what_authorized_property_filter(property_type, property_value,
resource_types=resource_types,
options=options)
input_params = {"age":"21"}
what_authorized = client_authorization.what_authorized_property_filter(
property_type,
property_value,
resource_types,
input_params,
[])
if what_authorized:
print_response(what_authorized)
else:
Expand All @@ -2063,8 +2082,12 @@ def main():
actions = ["ACTION1", "ACTION2"]
resources = [WhoAuthorizedResource("resourceID", "TypeName", actions),
WhoAuthorizedResource("resource2ID", "TypeName", actions)]
options = {"age": "21"}
who_authorized = client_authorization.who_authorized(resources, options)
input_params = {"age": "21"}
policy_tags = ["Car", "Rental", "Sharing"]
who_authorized = client_authorization.who_authorized(
resources,
input_params,
policy_tags)

if who_authorized:
print_response(who_authorized)
Expand Down
25 changes: 14 additions & 11 deletions indykite_sdk/authorization/is_authorized.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import indykite_sdk.utils.logger as logger


def is_authorized_digital_twin(self, digital_twin_id, tenant_id, resources=[], options={}):
def is_authorized_digital_twin(self, digital_twin_id, tenant_id, resources=[], input_params={}, policy_tags=[]):
sys.excepthook = logger.handle_excepthook
try:
response = self.stub.IsAuthorized(
Expand All @@ -22,7 +22,8 @@ def is_authorized_digital_twin(self, digital_twin_id, tenant_id, resources=[], o
)
),
resources=request_resource(resources),
options=request_options(options)
input_params=request_input_params(input_params),
policy_tags=policy_tags
)
)
except Exception as exception:
Expand All @@ -34,7 +35,7 @@ def is_authorized_digital_twin(self, digital_twin_id, tenant_id, resources=[], o
return IsAuthorizedResponse.deserialize(response)


def is_authorized_token(self, access_token, resources=[], options={}):
def is_authorized_token(self, access_token, resources=[], input_params={}, policy_tags=[]):
sys.excepthook = logger.handle_excepthook
try:
response = self.stub.IsAuthorized(
Expand All @@ -45,7 +46,8 @@ def is_authorized_token(self, access_token, resources=[], options={}):
)
),
resources=request_resource(resources),
options=request_options(options)
input_params=request_input_params(input_params),
policy_tags=policy_tags
)
)
except Exception as exception:
Expand All @@ -57,7 +59,7 @@ def is_authorized_token(self, access_token, resources=[], options={}):
return IsAuthorizedResponse.deserialize(response)


def is_authorized_property_filter(self, type_filter, value, resources=[], options={}):
def is_authorized_property_filter(self, type_filter, value, resources=[], input_params={}, policy_tags=[]):
sys.excepthook = logger.handle_excepthook
try:
response = self.stub.IsAuthorized(
Expand All @@ -71,7 +73,8 @@ def is_authorized_property_filter(self, type_filter, value, resources=[], option
)
),
resources=request_resource(resources),
options=request_options(options)
input_params=request_input_params(input_params),
policy_tags=policy_tags
)
)
except Exception as exception:
Expand All @@ -90,10 +93,10 @@ def request_resource(resources):
]


def request_options(options):
options_dict = {
k: pb2_model.Option(string_value=str(v))
for k, v in options.items()
def request_input_params(input_params):
input_params_dict = {
k: pb2_model.InputParam(string_value=str(v))
for k, v in input_params.items()
}
return options_dict
return input_params_dict

25 changes: 14 additions & 11 deletions indykite_sdk/authorization/what_authorized.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import indykite_sdk.utils.logger as logger


def what_authorized_digital_twin(self, digital_twin_id, tenant_id, resource_types=[], options={}):
def what_authorized_digital_twin(self, digital_twin_id, tenant_id, resource_types=[], input_params={}, policy_tags=[]):
sys.excepthook = logger.handle_excepthook
try:
response = self.stub.WhatAuthorized(
Expand All @@ -22,7 +22,8 @@ def what_authorized_digital_twin(self, digital_twin_id, tenant_id, resource_type
)
),
resource_types=request_resource_type(resource_types),
options=request_options(options)
input_params=request_input_params(input_params),
policy_tags=policy_tags
)
)
if not response:
Expand All @@ -32,7 +33,7 @@ def what_authorized_digital_twin(self, digital_twin_id, tenant_id, resource_type
return logger.logger_error(exception)


def what_authorized_token(self, access_token, resource_types=[], options={}):
def what_authorized_token(self, access_token, resource_types=[], input_params={}, policy_tags=[]):
sys.excepthook = logger.handle_excepthook
try:
response = self.stub.WhatAuthorized(
Expand All @@ -43,7 +44,8 @@ def what_authorized_token(self, access_token, resource_types=[], options={}):
)
),
resource_types=request_resource_type(resource_types),
options=request_options(options)
input_params=request_input_params(input_params),
policy_tags=policy_tags
)
)
if not response:
Expand All @@ -53,7 +55,7 @@ def what_authorized_token(self, access_token, resource_types=[], options={}):
return logger.logger_error(exception)


def what_authorized_property_filter(self, type_filter, value, resource_types=[], options={}):
def what_authorized_property_filter(self, type_filter, value, resource_types=[], input_params={}, policy_tags=[]):
sys.excepthook = logger.handle_excepthook
try:
response = self.stub.WhatAuthorized(
Expand All @@ -67,7 +69,8 @@ def what_authorized_property_filter(self, type_filter, value, resource_types=[],
)
),
resource_types=request_resource_type(resource_types),
options=request_options(options)
input_params=request_input_params(input_params),
policy_tags=policy_tags
)
)
if not response:
Expand All @@ -84,9 +87,9 @@ def request_resource_type(resource_types):
]


def request_options(options):
options_dict = {
k: pb2_model.Option(string_value=str(v))
for k, v in options.items()
def request_input_params(input_params):
input_params_dict = {
k: pb2_model.InputParam(string_value=str(v))
for k, v in input_params.items()
}
return options_dict
return input_params_dict
15 changes: 8 additions & 7 deletions indykite_sdk/authorization/who_authorized.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import indykite_sdk.utils.logger as logger


def who_authorized(self, resources=[], options={}):
def who_authorized(self, resources=[], input_params={}, policy_tags=[]):
sys.excepthook = logger.handle_excepthook
try:
response = self.stub.WhoAuthorized(
pb2.WhoAuthorizedRequest(
resources=request_resource(resources),
options=request_options(options)
input_params=request_input_params(input_params),
policy_tags=policy_tags
)
)
except Exception as exception:
Expand All @@ -30,9 +31,9 @@ def request_resource(resources):
]


def request_options(options):
options_dict = {
k: pb2_model.Option(string_value=str(v))
for k, v in options.items()
def request_input_params(input_params):
input_params_dict = {
k: pb2_model.InputParam(string_value=str(v))
for k, v in input_params.items()
}
return options_dict
return input_params_dict
2 changes: 1 addition & 1 deletion indykite_sdk/config/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def change_display_to_name(display):
if s[i] == ' ':
s.replace(s[i], '-')
s = re.sub(r"[^a-z0-9-]+", "-", s)
return s
return s[:62]


def remove_accent_chars_regex(x: str):
Expand Down

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions indykite_sdk/indykite/authorization/v1beta1/model_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8b42995

Please sign in to comment.