Skip to content

Commit

Permalink
Release (#24)
Browse files Browse the repository at this point in the history
* Fix develop dockerfile

* Change keycloak urls

* Fix develop workflow tag

* Fix production workflow

* Change log message

* Change config

* Add health check

* Fix health check

* Add ready health endpoint

* Fix issue

* Change workflow filenames

* Eoepca 910 um keycloak develop an identity api based on keycloak api (#17)

* feat: policies endpoints added, not completely

* feat: working on update policies

* feat: all remaining added, still policy update not working, create and update scope based permission not working

* feat: last resource permissions endpoints added and working

* fix: changed pyyaml version from 5.4.1 to 5.3.1

* feat: endpoints changed

* Update README

* Update config

* Update config

* Update config

* Api testing (#18)

* feat: added client_id as param to enpoints and other fixes

* added changes for permissions endpoints

* Update ci

* Update ci

* Release v1.0.0

* Fix ci

* Fix requirements

* Fix ci

* Upgrade flask version

* Update requirements

* feat: added error handling (#23)

---------

Co-authored-by: flaviorosadme <82375986+flaviorosadme@users.noreply.github.com>
  • Loading branch information
daniel-pimenta-DME and flaviorosadme authored Oct 16, 2023
1 parent 1e6ab6f commit 13b1ab6
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 23 deletions.
52 changes: 46 additions & 6 deletions src/blueprints/permissions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import Blueprint, request
from keycloak import KeycloakGetError, KeycloakPostError, KeycloakPutError


def construct_blueprint(keycloak_client):
Expand All @@ -7,15 +8,33 @@ def construct_blueprint(keycloak_client):

@permissions.route("/<client_id>/permissions", methods=["GET"])
def get_client_authz_permissions(client_id: str):
return keycloak_client.get_client_authz_permissions(client_id)
try:
response = keycloak_client.get_client_authz_permissions(client_id)
return response
except KeycloakGetError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

@permissions.route("/<client_id>/permissions/management", methods=["GET"])
def get_client_management_permissions(client_id: str):
return keycloak_client.get_client_management_permissions(client_id)
try:
response = keycloak_client.get_client_management_permissions(client_id)
return response
except KeycloakGetError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

@permissions.route("/<client_id>/permissions/resources", methods=["GET"])
def get_client_resource_permissions(client_id: str):
return keycloak_client.get_client_resource_permissions(client_id)
try:
response = keycloak_client.get_client_resource_permissions(client_id)
return response
except KeycloakGetError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

#@permissions.route("/client_authz_scope_permissions/<client_id>/<scope_id>", methods=["GET"])
#def get_client_authz_scope_permissions(client_id: str, scope_id: str):
Expand All @@ -29,21 +48,42 @@ def get_client_resource_permissions(client_id: str):
@permissions.route("/<client_id>/permissions/resources", methods=["POST"])
def create_client_authz_resource_based_permission(client_id: str):
payload = request.get_json()
return keycloak_client.create_client_authz_resource_based_permission(client_id, payload)
try:
response = keycloak_client.create_client_authz_resource_based_permission(client_id, payload)
return response
except KeycloakPostError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

@permissions.route("/<client_id>/permissions/management", methods=["PUT"])
def update_client_management_permissions(client_id: str):
payload = request.get_json()
return keycloak_client.update_client_management_permissions(client_id, payload)
try:
response = keycloak_client.update_client_management_permissions(client_id, payload)
return response
except KeycloakPostError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

@permissions.route("/<client_id>/permissions/resources/<permission_id>", methods=["PUT"])
def update_client_authz_resource_permission(client_id: str, permission_id):
payload = request.get_json()
return keycloak_client.update_client_authz_resource_permission(client_id, payload, permission_id)
try:
response = keycloak_client.update_client_authz_resource_permission(client_id, payload, permission_id)
return response
except KeycloakPutError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

#@permissions.route("/<client_id>/permissions/scopes/<scope_id>", methods=["PUT"])
#def update_client_authz_scope_permissions(client_id: str, scope_id):
# payload = request.get_json()
# return keycloak_client.update_client_authz_scope_permission(client_id, payload, scope_id)

def custom_error(message, status_code):
return message, status_code

return permissions
93 changes: 81 additions & 12 deletions src/blueprints/policies.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import Blueprint, request
from keycloak import KeycloakDeleteError, KeycloakGetError, KeycloakPostError, KeycloakPutError


def construct_blueprint(keycloak_client):
Expand All @@ -18,40 +19,82 @@ def construct_blueprint(keycloak_client):

@policies.route("/<client_id>/policies", methods=["GET"])
def get_client_authz_policies(client_id: str):
return keycloak_client.get_client_authz_policies(client_id)
try:
response = keycloak_client.get_client_authz_policies(client_id)
return response
except KeycloakGetError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

# --------------- POST -----------------

@policies.route("/<client_id>/policies/client", methods=["POST"])
def create_client_policy(client_id: str):
policy = request.get_json()
return keycloak_client.register_client_policy(policy, client_id)
try:
response = keycloak_client.register_client_policy(policy, client_id)
return response
except KeycloakPostError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)


@policies.route("/<client_id>/policies/aggregated", methods = ["POST"])
def create_aggregated_policy(client_id: str):
policy = request.get_json()
return keycloak_client.register_aggregated_policy(policy, client_id)
try:
response = keycloak_client.register_aggregated_policy(policy, client_id)
return response
except KeycloakPostError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

@policies.route("/<client_id>/policies/scope", methods = ["POST"])
def create_client_scope_policy(client_id: str):
policy = request.get_json()
return keycloak_client.register_client_scope_policy(policy, client_id)
try:
response = keycloak_client.register_client_scope_policy(policy, client_id)
return response
except KeycloakPostError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

@policies.route("/<client_id>/policies/group", methods = ["POST"])
def create_group_policy(client_id: str):
policy = request.get_json()
return keycloak_client.register_group_policy(policy, client_id)
try:
response = keycloak_client.register_group_policy(policy, client_id)
return response
except KeycloakPostError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

@policies.route("/<client_id>/policies/regex", methods = ["POST"])
def create_regex_policy(client_id: str):
policy = request.get_json()
return keycloak_client.register_regex_policy(policy, client_id)
try:
response = keycloak_client.register_regex_policy(policy, client_id)
return response
except KeycloakPostError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

@policies.route("/<client_id>/policies/role", methods = ["POST"])
def create_role_policy(client_id: str):
policy = request.get_json()
return keycloak_client.register_role_policy(policy, client_id)
try:
response = keycloak_client.register_role_policy(policy, client_id)
return response
except KeycloakPostError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

@policies.route("/<client_id>/policies/time", methods = ["POST"])
def create_time_policy(client_id: str):
Expand Down Expand Up @@ -83,12 +126,24 @@ def create_time_policy(client_id: str):
"minuteEnd"
]
policy = request.get_json()
return keycloak_client.register_time_policy(policy, client_id)
try:
response = keycloak_client.register_time_policy(policy, client_id)
return response
except KeycloakPostError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

@policies.route("/<client_id>/policies/user", methods = ["POST"])
def create_user_policy(client_id: str):
policy = request.get_json()
return keycloak_client.register_user_policy(policy, client_id)
try:
response = keycloak_client.register_user_policy(policy, client_id)
return response
except KeycloakPostError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)



Expand All @@ -97,13 +152,27 @@ def create_user_policy(client_id: str):
@policies.route("/<client_id>/policies/<policy_id>", methods=["PUT"])
def update_policy(client_id: str, policy_id: str):
policy = request.get_json()
return keycloak_client.update_policy(policy_id, policy, client_id)
try:
response = keycloak_client.update_policy(policy_id, policy, client_id)
return response
except KeycloakPutError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

# --------------- DELETE -----------------

@policies.route("/<client_id>/policies/<policy_id>", methods=["DELETE"])
def delete_policy(client_id: str ,policy_id: str):
return keycloak_client.delete_policy(policy_id, client_id)

try:
response = keycloak_client.delete_policy(policy_id, client_id)
return response
except KeycloakDeleteError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

def custom_error(message, status_code):
return message, status_code

return policies
44 changes: 39 additions & 5 deletions src/blueprints/resources.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import Blueprint, request
from keycloak import KeycloakDeleteError, KeycloakGetError, KeycloakPostError, KeycloakPutError


def construct_blueprint(keycloak_client):
Expand All @@ -7,24 +8,57 @@ def construct_blueprint(keycloak_client):

@resources.route("/<client_id>/resources", methods=["GET"])
def get_resources(client_id: str):
return keycloak_client.get_resources(client_id)
try:
response = keycloak_client.get_resources(client_id)
return response
except KeycloakGetError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

@resources.route("/resources/<resource_id>", methods=["GET"])
def get_resource(resource_id: str):
return keycloak_client.get_resource(resource_id)
try:
response = keycloak_client.get_resource(resource_id)
return response
except KeycloakGetError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

@resources.route("/<client_id>/resources", methods=["POST"])
def register_resource(client_id: str ):
resource = request.get_json()
return keycloak_client.register_resource(resource, client_id)
try:
response = keycloak_client.register_resource(resource, client_id)
return response
except KeycloakPostError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

@resources.route("/<client_id>/resources/<resource_id>", methods=["PUT"])
def update_resource(client_id: str, resource_id: str):
resource = request.get_json()
return keycloak_client.update_resource(resource_id, resource, client_id)
try:
response = keycloak_client.update_resource(resource_id, resource, client_id)
return response
except KeycloakPutError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

@resources.route("/<client_id>/resources/<resource_id>", methods=["DELETE"])
def delete_resource(client_id: str, resource_id: str):
return keycloak_client.delete_resource(resource_id, client_id)
try:
response = keycloak_client.delete_resource(resource_id, client_id)
return response
except KeycloakDeleteError as error:
return custom_error(error.error_message, error.response_code)
except:
return custom_error("Unknown server error", 500)

def custom_error(message, status_code):
return message, status_code

return resources

0 comments on commit 13b1ab6

Please sign in to comment.