From 1ed86e035beafbe786fe6521821bc1f9de4afdbd Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Fri, 27 Dec 2019 15:25:44 +0100 Subject: [PATCH] remove public information in message, it's remplace by role --- .../v1/messages/applicationservice.create.yml | 2 - .../applicationservice.dataset.updated.yml | 2 - .../messages/applicationservice.describe.yml | 2 - .../messages/applicationservice.get_by_id.yml | 2 - .../config.configuration.server.deploy.yml | 2 - .../config.configuration.server.get.yml | 2 - .../config.configuration.server.updated.yml | 2 - messages/v1/messages/server.create.yml | 2 - messages/v1/messages/server.created.yml | 2 - messages/v1/messages/server.deleted.yml | 2 - messages/v1/messages/server.describe.yml | 2 - messages/v1/messages/server.list.yml | 2 - messages/v1/messages/servermodel.created.yml | 2 - .../messages/servermodel.dataset.updated.yml | 2 - .../v1/messages/servermodel.get_by_id.yml | 2 - messages/v1/messages/servermodel.list.yml | 12 -- messages/v1/messages/servermodel.updated.yml | 2 - .../v1/messages/session.server.configure.yml | 2 - .../v1/messages/session.server.filter.yml | 2 - messages/v1/messages/session.server.get.yml | 2 - messages/v1/messages/session.server.list.yml | 2 - messages/v1/messages/session.server.start.yml | 2 - messages/v1/messages/session.server.stop.yml | 2 - .../v1/messages/session.server.validate.yml | 2 - .../session.servermodel.configure.yml | 2 - .../messages/session.servermodel.filter.yml | 2 - .../v1/messages/session.servermodel.get.yml | 2 - .../v1/messages/session.servermodel.list.yml | 2 - .../v1/messages/session.servermodel.start.yml | 2 - .../v1/messages/session.servermodel.stop.yml | 2 - .../messages/session.servermodel.validate.yml | 2 - messages/v1/messages/source.create.yml | 2 - .../v1/messages/source.dataset.update.yml | 2 - messages/v1/messages/source.describe.yml | 2 - messages/v1/messages/source.list.yml | 2 - .../v1/messages/source.release.create.yml | 2 - .../source.release.get_by_distribution.yml | 2 - .../v1/messages/source.release.get_by_id.yml | 2 - messages/v1/messages/source.release.list.yml | 2 - messages/v1/messages/template.generate.yml | 2 - messages/v1/messages/uri.role.join.yml | 22 +++ messages/v1/messages/uri.role.list.yml | 11 ++ messages/v1/messages/user.create.yml | 25 +++ messages/v1/messages/user.delete.yml | 18 +++ messages/v1/messages/user.list.yml | 11 ++ messages/v1/messages/user.role.create.yml | 32 ++++ messages/v1/messages/user.role.list.yml | 19 +++ messages/v1/types/role.yml | 26 ++++ messages/v1/types/uri.role.yml | 15 ++ messages/v1/types/user.yml | 24 +++ messages/v1/types/userrole.yml | 20 +++ src/risotto/http.py | 10 +- src/risotto/message/message.py | 21 +-- src/risotto/services/uri/__init__.py | 1 + src/risotto/services/uri/uri.py | 43 ++++++ src/risotto/services/user/__init__.py | 1 + src/risotto/services/user/user.py | 143 ++++++++++++++++++ 57 files changed, 419 insertions(+), 113 deletions(-) create mode 100644 messages/v1/messages/uri.role.join.yml create mode 100644 messages/v1/messages/uri.role.list.yml create mode 100644 messages/v1/messages/user.create.yml create mode 100644 messages/v1/messages/user.delete.yml create mode 100644 messages/v1/messages/user.list.yml create mode 100644 messages/v1/messages/user.role.create.yml create mode 100644 messages/v1/messages/user.role.list.yml create mode 100644 messages/v1/types/role.yml create mode 100644 messages/v1/types/uri.role.yml create mode 100644 messages/v1/types/user.yml create mode 100644 messages/v1/types/userrole.yml create mode 100644 src/risotto/services/uri/__init__.py create mode 100644 src/risotto/services/uri/uri.py create mode 100644 src/risotto/services/user/__init__.py create mode 100644 src/risotto/services/user/user.py diff --git a/messages/v1/messages/applicationservice.create.yml b/messages/v1/messages/applicationservice.create.yml index 085b6d6..ab95b6b 100644 --- a/messages/v1/messages/applicationservice.create.yml +++ b/messages/v1/messages/applicationservice.create.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: applicationservice_name: type: String diff --git a/messages/v1/messages/applicationservice.dataset.updated.yml b/messages/v1/messages/applicationservice.dataset.updated.yml index c5dc68f..17c6376 100644 --- a/messages/v1/messages/applicationservice.dataset.updated.yml +++ b/messages/v1/messages/applicationservice.dataset.updated.yml @@ -5,8 +5,6 @@ description: | pattern: rpc -public: true - parameters: source_name: type: String diff --git a/messages/v1/messages/applicationservice.describe.yml b/messages/v1/messages/applicationservice.describe.yml index 8e6c4a5..ac4bd3d 100644 --- a/messages/v1/messages/applicationservice.describe.yml +++ b/messages/v1/messages/applicationservice.describe.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: applicationservice_name: type: String diff --git a/messages/v1/messages/applicationservice.get_by_id.yml b/messages/v1/messages/applicationservice.get_by_id.yml index e079b2c..97b2013 100644 --- a/messages/v1/messages/applicationservice.get_by_id.yml +++ b/messages/v1/messages/applicationservice.get_by_id.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: applicationservice_id: type: Number diff --git a/messages/v1/messages/config.configuration.server.deploy.yml b/messages/v1/messages/config.configuration.server.deploy.yml index f2c91bb..86ee2ee 100644 --- a/messages/v1/messages/config.configuration.server.deploy.yml +++ b/messages/v1/messages/config.configuration.server.deploy.yml @@ -6,8 +6,6 @@ description: | pattern: event -public: false - parameters: server_id: type: Number diff --git a/messages/v1/messages/config.configuration.server.get.yml b/messages/v1/messages/config.configuration.server.get.yml index 9a6332c..73165f0 100644 --- a/messages/v1/messages/config.configuration.server.get.yml +++ b/messages/v1/messages/config.configuration.server.get.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: false - parameters: server_id: type: Number diff --git a/messages/v1/messages/config.configuration.server.updated.yml b/messages/v1/messages/config.configuration.server.updated.yml index 030996d..aa1f84e 100644 --- a/messages/v1/messages/config.configuration.server.updated.yml +++ b/messages/v1/messages/config.configuration.server.updated.yml @@ -6,8 +6,6 @@ description: | pattern: event -public: false - parameters: server_id: type: Number diff --git a/messages/v1/messages/server.create.yml b/messages/v1/messages/server.create.yml index 85e6f79..cdd6a04 100644 --- a/messages/v1/messages/server.create.yml +++ b/messages/v1/messages/server.create.yml @@ -5,8 +5,6 @@ description: Crée un serveur. pattern: rpc -public: true - parameters: server_name: type: String diff --git a/messages/v1/messages/server.created.yml b/messages/v1/messages/server.created.yml index 9c234d1..e4deb58 100644 --- a/messages/v1/messages/server.created.yml +++ b/messages/v1/messages/server.created.yml @@ -5,8 +5,6 @@ description: Un serveur a été créé. pattern: event -public: false - parameters: type: Server description: Description du serveur. diff --git a/messages/v1/messages/server.deleted.yml b/messages/v1/messages/server.deleted.yml index e348b0f..9e90f9f 100644 --- a/messages/v1/messages/server.deleted.yml +++ b/messages/v1/messages/server.deleted.yml @@ -6,8 +6,6 @@ description: | pattern: event -public: false - parameters: server_id: type: Number diff --git a/messages/v1/messages/server.describe.yml b/messages/v1/messages/server.describe.yml index cb703c1..0a19356 100644 --- a/messages/v1/messages/server.describe.yml +++ b/messages/v1/messages/server.describe.yml @@ -5,8 +5,6 @@ description: Retourne les attributs détaillés d’un serveur. pattern: rpc -public: true - parameters: server_name: type: String diff --git a/messages/v1/messages/server.list.yml b/messages/v1/messages/server.list.yml index 730d37d..9219919 100644 --- a/messages/v1/messages/server.list.yml +++ b/messages/v1/messages/server.list.yml @@ -4,8 +4,6 @@ uri: server.list description: | Liste les serveurs disponibles. -public: true - pattern: rpc response: diff --git a/messages/v1/messages/servermodel.created.yml b/messages/v1/messages/servermodel.created.yml index b2a82e3..89ee34b 100644 --- a/messages/v1/messages/servermodel.created.yml +++ b/messages/v1/messages/servermodel.created.yml @@ -5,8 +5,6 @@ description: Des modèles de serveur ont été créés. pattern: event -public: false - parameters: type: Servermodel description: Informations sur les modèles de serveur créés. diff --git a/messages/v1/messages/servermodel.dataset.updated.yml b/messages/v1/messages/servermodel.dataset.updated.yml index 24237b5..6f37f23 100644 --- a/messages/v1/messages/servermodel.dataset.updated.yml +++ b/messages/v1/messages/servermodel.dataset.updated.yml @@ -5,8 +5,6 @@ description: | pattern: rpc -public: true - parameters: source_name: type: String diff --git a/messages/v1/messages/servermodel.get_by_id.yml b/messages/v1/messages/servermodel.get_by_id.yml index 5ed3311..4f11666 100644 --- a/messages/v1/messages/servermodel.get_by_id.yml +++ b/messages/v1/messages/servermodel.get_by_id.yml @@ -5,8 +5,6 @@ description: Retourne les attributs détaillés d'un modèle de serveur suivant pattern: rpc -public: false - parameters: servermodel_id: type: Number diff --git a/messages/v1/messages/servermodel.list.yml b/messages/v1/messages/servermodel.list.yml index 5faa2f5..887e7b1 100644 --- a/messages/v1/messages/servermodel.list.yml +++ b/messages/v1/messages/servermodel.list.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: source_id: type: Number @@ -19,13 +17,3 @@ parameters: response: type: '[]Servermodel' description: Liste des modèles de serveur disponibles. - -errors: - - uri: servermodel.list.error.database_not_available - -related: - - servermodel.describe - - servermodel.create - - servermodel.update - - servermodel.delete - - servermodel.event diff --git a/messages/v1/messages/servermodel.updated.yml b/messages/v1/messages/servermodel.updated.yml index 82a1078..cdd53d9 100644 --- a/messages/v1/messages/servermodel.updated.yml +++ b/messages/v1/messages/servermodel.updated.yml @@ -5,8 +5,6 @@ description: Des modèles de serveur ont été modifiés. pattern: event -public: false - parameters: type: 'Servermodel' description: Informations sur les modèles de serveur modifiés. diff --git a/messages/v1/messages/session.server.configure.yml b/messages/v1/messages/session.server.configure.yml index db06ab4..dee924d 100644 --- a/messages/v1/messages/session.server.configure.yml +++ b/messages/v1/messages/session.server.configure.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: session_id: type: String diff --git a/messages/v1/messages/session.server.filter.yml b/messages/v1/messages/session.server.filter.yml index 36b0aa9..009f6fe 100644 --- a/messages/v1/messages/session.server.filter.yml +++ b/messages/v1/messages/session.server.filter.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: session_id: type: String diff --git a/messages/v1/messages/session.server.get.yml b/messages/v1/messages/session.server.get.yml index 058520e..013e048 100644 --- a/messages/v1/messages/session.server.get.yml +++ b/messages/v1/messages/session.server.get.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: session_id: type: String diff --git a/messages/v1/messages/session.server.list.yml b/messages/v1/messages/session.server.list.yml index 6d23343..7ab80b6 100644 --- a/messages/v1/messages/session.server.list.yml +++ b/messages/v1/messages/session.server.list.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - response: type: '[]Session' description: | diff --git a/messages/v1/messages/session.server.start.yml b/messages/v1/messages/session.server.start.yml index dd5867f..1b8264a 100644 --- a/messages/v1/messages/session.server.start.yml +++ b/messages/v1/messages/session.server.start.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: id: type: Number diff --git a/messages/v1/messages/session.server.stop.yml b/messages/v1/messages/session.server.stop.yml index 69a65a1..a68d1de 100644 --- a/messages/v1/messages/session.server.stop.yml +++ b/messages/v1/messages/session.server.stop.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: session_id: ref: Config.SessionId diff --git a/messages/v1/messages/session.server.validate.yml b/messages/v1/messages/session.server.validate.yml index 98552e5..480c5e6 100644 --- a/messages/v1/messages/session.server.validate.yml +++ b/messages/v1/messages/session.server.validate.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: session_id: ref: Config.SessionId diff --git a/messages/v1/messages/session.servermodel.configure.yml b/messages/v1/messages/session.servermodel.configure.yml index 8cbc0e2..703057a 100644 --- a/messages/v1/messages/session.servermodel.configure.yml +++ b/messages/v1/messages/session.servermodel.configure.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: session_id: type: String diff --git a/messages/v1/messages/session.servermodel.filter.yml b/messages/v1/messages/session.servermodel.filter.yml index 84723a5..9032fcc 100644 --- a/messages/v1/messages/session.servermodel.filter.yml +++ b/messages/v1/messages/session.servermodel.filter.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: session_id: type: String diff --git a/messages/v1/messages/session.servermodel.get.yml b/messages/v1/messages/session.servermodel.get.yml index 4e14e17..e0ffe0f 100644 --- a/messages/v1/messages/session.servermodel.get.yml +++ b/messages/v1/messages/session.servermodel.get.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: session_id: type: String diff --git a/messages/v1/messages/session.servermodel.list.yml b/messages/v1/messages/session.servermodel.list.yml index dfec232..750ec2b 100644 --- a/messages/v1/messages/session.servermodel.list.yml +++ b/messages/v1/messages/session.servermodel.list.yml @@ -5,8 +5,6 @@ description: | pattern: rpc -public: true - response: type: '[]Session' description: | diff --git a/messages/v1/messages/session.servermodel.start.yml b/messages/v1/messages/session.servermodel.start.yml index b18438d..3307e5a 100644 --- a/messages/v1/messages/session.servermodel.start.yml +++ b/messages/v1/messages/session.servermodel.start.yml @@ -5,8 +5,6 @@ description: | pattern: rpc -public: true - parameters: id: type: Number diff --git a/messages/v1/messages/session.servermodel.stop.yml b/messages/v1/messages/session.servermodel.stop.yml index 6402cb7..513cdcc 100644 --- a/messages/v1/messages/session.servermodel.stop.yml +++ b/messages/v1/messages/session.servermodel.stop.yml @@ -5,8 +5,6 @@ description: | pattern: rpc -public: true - parameters: session_id: ref: Config.SessionId diff --git a/messages/v1/messages/session.servermodel.validate.yml b/messages/v1/messages/session.servermodel.validate.yml index 1518af8..3e93380 100644 --- a/messages/v1/messages/session.servermodel.validate.yml +++ b/messages/v1/messages/session.servermodel.validate.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: session_id: ref: Config.SessionId diff --git a/messages/v1/messages/source.create.yml b/messages/v1/messages/source.create.yml index 7f696c6..4525299 100644 --- a/messages/v1/messages/source.create.yml +++ b/messages/v1/messages/source.create.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: source_name: type: String diff --git a/messages/v1/messages/source.dataset.update.yml b/messages/v1/messages/source.dataset.update.yml index 02d421d..f9e5329 100644 --- a/messages/v1/messages/source.dataset.update.yml +++ b/messages/v1/messages/source.dataset.update.yml @@ -5,8 +5,6 @@ description: | pattern: rpc -public: true - parameters: source_id: type: Number diff --git a/messages/v1/messages/source.describe.yml b/messages/v1/messages/source.describe.yml index 336506f..c5aed81 100644 --- a/messages/v1/messages/source.describe.yml +++ b/messages/v1/messages/source.describe.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: source_name: type: String diff --git a/messages/v1/messages/source.list.yml b/messages/v1/messages/source.list.yml index f6d5d24..fe7c5bb 100644 --- a/messages/v1/messages/source.list.yml +++ b/messages/v1/messages/source.list.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - response: type: '[]Source' description: Liste des sources disponibles. diff --git a/messages/v1/messages/source.release.create.yml b/messages/v1/messages/source.release.create.yml index 082532a..f9082fd 100644 --- a/messages/v1/messages/source.release.create.yml +++ b/messages/v1/messages/source.release.create.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: source_id: type: Number diff --git a/messages/v1/messages/source.release.get_by_distribution.yml b/messages/v1/messages/source.release.get_by_distribution.yml index acc13d7..a860218 100644 --- a/messages/v1/messages/source.release.get_by_distribution.yml +++ b/messages/v1/messages/source.release.get_by_distribution.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: source_id: type: Number diff --git a/messages/v1/messages/source.release.get_by_id.yml b/messages/v1/messages/source.release.get_by_id.yml index 0aab4e5..1653a60 100644 --- a/messages/v1/messages/source.release.get_by_id.yml +++ b/messages/v1/messages/source.release.get_by_id.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: release_id: type: Number diff --git a/messages/v1/messages/source.release.list.yml b/messages/v1/messages/source.release.list.yml index 8bc920e..5fe82b7 100644 --- a/messages/v1/messages/source.release.list.yml +++ b/messages/v1/messages/source.release.list.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - response: type: '[]Release' description: Liste des versions disponibles. diff --git a/messages/v1/messages/template.generate.yml b/messages/v1/messages/template.generate.yml index 8a97141..e805b85 100644 --- a/messages/v1/messages/template.generate.yml +++ b/messages/v1/messages/template.generate.yml @@ -6,8 +6,6 @@ description: | pattern: rpc -public: true - parameters: server_name: type: String diff --git a/messages/v1/messages/uri.role.join.yml b/messages/v1/messages/uri.role.join.yml new file mode 100644 index 0000000..6da97e6 --- /dev/null +++ b/messages/v1/messages/uri.role.join.yml @@ -0,0 +1,22 @@ +--- +uri: uri.role.join + +description: Crée un rôle utilisateur. + +pattern: rpc + +parameters: + role_name: + type: String + shortarg: n + description: Nom du rôle. + ref: User.RoleName + uri: + type: String + shortarg: u + description: Nom du message. + +response: + type: URIRole + description: Association de rôle créé. + diff --git a/messages/v1/messages/uri.role.list.yml b/messages/v1/messages/uri.role.list.yml new file mode 100644 index 0000000..bfd6a73 --- /dev/null +++ b/messages/v1/messages/uri.role.list.yml @@ -0,0 +1,11 @@ +--- +uri: uri.role.list + +description: Liste des associations d'URI et de rôle. + +pattern: rpc + +response: + type: '[]URIRole' + description: Liste des associations. + diff --git a/messages/v1/messages/user.create.yml b/messages/v1/messages/user.create.yml new file mode 100644 index 0000000..dfa28c2 --- /dev/null +++ b/messages/v1/messages/user.create.yml @@ -0,0 +1,25 @@ +--- +uri: user.create + +description: Crée un utilisateur. + +pattern: rpc + +parameters: + user_login: + type: String + shortarg: l + description: Login de l'utilisateur. + ref: User.Login + user_name: + type: String + shortarg: n + description: Nom de l'utilisateur. + user_surname: + type: String + shortarg: s + description: Nom de famille de l'utilisateur. + +response: + type: User + description: Description de l'utilisateur créé. diff --git a/messages/v1/messages/user.delete.yml b/messages/v1/messages/user.delete.yml new file mode 100644 index 0000000..2006418 --- /dev/null +++ b/messages/v1/messages/user.delete.yml @@ -0,0 +1,18 @@ +--- +uri: user.delete + +description: Supprimer un utilisateur. + +pattern: rpc + +parameters: + user_login: + type: String + shortarg: l + description: Login de l'utilisateur. + ref: User.Login + +response: + type: User + description: Description de l'utilisateur supprimé. + diff --git a/messages/v1/messages/user.list.yml b/messages/v1/messages/user.list.yml new file mode 100644 index 0000000..0f23434 --- /dev/null +++ b/messages/v1/messages/user.list.yml @@ -0,0 +1,11 @@ +--- +uri: user.list + +description: | + Liste les utilisateurs disponibles. + +pattern: rpc + +response: + type: '[]User' + description: Retourne la liste des utilisateurs. diff --git a/messages/v1/messages/user.role.create.yml b/messages/v1/messages/user.role.create.yml new file mode 100644 index 0000000..e583297 --- /dev/null +++ b/messages/v1/messages/user.role.create.yml @@ -0,0 +1,32 @@ +--- +uri: user.role.create + +description: Crée un rôle utilisateur. + +pattern: rpc + +parameters: + user_login: + type: String + shortarg: l + description: Login de l'utilisateur. + ref: User.UserLogin + role_name: + type: String + shortarg: n + description: Nom du rôle. + ref: User.RoleName + role_attribute: + type: String + shortarg: a + description: Attribut contrôlé. + default: null + role_attribute_value: + type: String + shortarg: v + description: Valeur de l'attribut contrôlé. + default: null + +response: + type: Role + description: Description du rôle créé. diff --git a/messages/v1/messages/user.role.list.yml b/messages/v1/messages/user.role.list.yml new file mode 100644 index 0000000..26317dd --- /dev/null +++ b/messages/v1/messages/user.role.list.yml @@ -0,0 +1,19 @@ +--- +uri: user.role.list + +description: | + Liste les rôles disponibles. + +pattern: rpc + +parameters: + user_login: + type: String + shortarg: l + description: Login de l'utilisateur associé. + ref: User.RoleName + default: null + +response: + type: '[]Role' + description: Retourne la liste des rôles. diff --git a/messages/v1/types/role.yml b/messages/v1/types/role.yml new file mode 100644 index 0000000..e0ea426 --- /dev/null +++ b/messages/v1/types/role.yml @@ -0,0 +1,26 @@ +--- +title: Role +type: object +description: Description du rôle. +properties: + role_id: + type: number + description: Identifiant de l'utilisateur. + ref: User.RoleUserId + user_login: + type: string + description: Login du l'utilisateur. + ref: User.Login + role_name: + type: string + description: Nom du rôle. + role_attribute: + type: string + description: Nom de l'utilisateur. + role_attribute_value: + type: string + description: Valeur de l'attribut contrôlé. + +required: + - role_id + - role_name diff --git a/messages/v1/types/uri.role.yml b/messages/v1/types/uri.role.yml new file mode 100644 index 0000000..26aaa82 --- /dev/null +++ b/messages/v1/types/uri.role.yml @@ -0,0 +1,15 @@ +--- +title: URIRole +type: object +description: Description de l'assication du message et du rôle. +properties: + role_name: + type: string + description: Nom du rôle + ref: User.RoleName + uri: + type: string + description: Nom du message +required: + - role_name + - uri diff --git a/messages/v1/types/user.yml b/messages/v1/types/user.yml new file mode 100644 index 0000000..5f2ea54 --- /dev/null +++ b/messages/v1/types/user.yml @@ -0,0 +1,24 @@ +--- +title: User +type: object +description: Description de l'utilisateur. +properties: + user_id: + type: number + description: Identifiant de l'utilisateur. + ref: User.UserId + user_login: + type: string + description: Login de l'utilisateur. + user_name: + type: string + description: Nom de l'utilisateur. + user_surname: + type: string + description: Nom de famille de l'utilisateur. + +required: + - user_id + - user_login + - user_name + - user_surname diff --git a/messages/v1/types/userrole.yml b/messages/v1/types/userrole.yml new file mode 100644 index 0000000..e64b0d7 --- /dev/null +++ b/messages/v1/types/userrole.yml @@ -0,0 +1,20 @@ +--- +title: UserRole +type: object +description: Description de l'association du rôle et de l'utilisateur. +properties: + user_role_id: + type: number + description: Identifiant de l'association. + ref: User.UserRoleId + user_login: + type: string + description: Login de l'utilisateur. + role_name: + type: string + description: Nom du rôle. + +required: + - user_role_id + - user_login + - role_name diff --git a/src/risotto/http.py b/src/risotto/http.py index f94726e..094ac18 100644 --- a/src/risotto/http.py +++ b/src/risotto/http.py @@ -89,8 +89,7 @@ async def handle(request): async def api(request, risotto_context): global tiramisu if not tiramisu: - config = await Config(get_messages(load_shortarg=True, - only_public=True)[1]) + config = await Config(get_messages(load_shortarg=True)[1]) await config.property.read_write() tiramisu = await config.option.dict(remotable='none') return tiramisu @@ -113,11 +112,8 @@ async def get_app(loop): print(_('======== Registered messages ========')) for message in messages: web_message = f'/api/{version}/{message}' - if dispatcher.messages[version][message]['public']: - print(f' - {web_message}') - else: - pattern = dispatcher.messages[version][message]['pattern'] - print(f' - {web_message} (private {pattern})') + pattern = dispatcher.messages[version][message]['pattern'] + print(f' - {web_message} ({pattern})') routes.append(post(web_message, handle)) print() print(_('======== Registered extra routes ========')) diff --git a/src/risotto/message/message.py b/src/risotto/message/message.py index 4871179..c6527f3 100644 --- a/src/risotto/message/message.py +++ b/src/risotto/message/message.py @@ -44,7 +44,6 @@ class MessageDefinition: 'uri', 'description', 'parameters', - 'public', 'errors', 'pattern', 'related', @@ -54,7 +53,6 @@ class MessageDefinition: # default value for non mandatory key self.version = u'' self.parameters = OrderedDict() - self.public = False self.errors = [] self.related = [] self.response = None @@ -63,10 +61,7 @@ class MessageDefinition: for key, value in raw_def.items(): if isinstance(value, str): value = value.strip() - if key == 'public': - if not isinstance(value, bool): - raise ValueError(_("{} must be a boolean, not {}").format(key, value)) - elif key == 'pattern': + if key == 'pattern': if value not in ['rpc', 'event', 'error']: raise Exception(_('unknown pattern {}').format(value)) elif key == 'parameters': @@ -86,9 +81,6 @@ class MessageDefinition: getattr(self, key) except AttributeError: raise Exception(_('mandatory key not set {} message').format(key)) - # message with pattern = error must be public - if self.public is False and self.pattern == 'error': - raise Exception(_('Error message must be public : {}').format(self.uri)) if self.uri != message: raise Exception(_(f'yaml file name "{message}.yml" does not match uri "{self.uri}"')) @@ -581,7 +573,7 @@ def _get_root_option(select_option, optiondescriptions): return OptionDescription('root', 'root', options_obj) -def get_messages(load_shortarg=False, only_public=False): +def get_messages(load_shortarg=False): """generate description from yml files """ optiondescriptions = OrderedDict() @@ -592,8 +584,7 @@ def get_messages(load_shortarg=False, only_public=False): messages.sort() for message_name in messages: message_def = get_message(message_name) - if message_def.pattern not in ['rpc', 'event'] or \ - (not message_def.public and only_public): + if message_def.pattern not in ['rpc', 'event']: continue optiondescriptions_name.append(message_def.uri) optiondescriptions_name.sort() @@ -603,11 +594,9 @@ def get_messages(load_shortarg=False, only_public=False): properties=frozenset(['mandatory', 'positional'])) for message_name in messages: message_def = get_message(message_name) - if message_def.pattern not in ['rpc', 'event'] or \ - (not message_def.public and only_public): + if message_def.pattern not in ['rpc', 'event']: continue - optiondescriptions_info[message_def.uri] = {'pattern': message_def.pattern, - 'public': message_def.public} + optiondescriptions_info[message_def.uri] = {'pattern': message_def.pattern} if message_def.pattern == 'rpc': optiondescriptions_info[message_def.uri]['response'] = _parse_responses(message_def, message_name) diff --git a/src/risotto/services/uri/__init__.py b/src/risotto/services/uri/__init__.py new file mode 100644 index 0000000..51c174b --- /dev/null +++ b/src/risotto/services/uri/__init__.py @@ -0,0 +1 @@ +from .uri import Risotto diff --git a/src/risotto/services/uri/uri.py b/src/risotto/services/uri/uri.py new file mode 100644 index 0000000..6c9ca34 --- /dev/null +++ b/src/risotto/services/uri/uri.py @@ -0,0 +1,43 @@ +from typing import Dict, List + +from ...controller import Controller +from ...register import register +from ...context import Context +from ...utils import _ + + +class Risotto(Controller): + @register('v1.uri.role.join', None, database=True) + async def uri_role_join(self, + risotto_context: Context, + role_name: str, + uri: str) -> Dict: + # Verify if user exists and get ID + sql = ''' + SELECT URIId + FROM URI + WHERE URIName = $1 + ''' + uri_id = await risotto_context.connection.fetchval(sql, + uri) + if uri_id is None: + raise Exception(_(f'unable to find message {uri}')) + sql = ''' + INSERT INTO RoleURI(RoleName, URIId) + VALUES ($1,$2) + ''' + uri_id = await risotto_context.connection.fetchrow(sql, + role_name, + uri_id) + return {'role_name': role_name, + 'uri': uri} + + @register('v1.uri.role.list', None, database=True) + async def uri_role_list(self, + risotto_context: Context) -> List[Dict]: + sql = ''' + SELECT RoleName as role_name, URI.URIName as uri + FROM RoleURI, URI + WHERE RoleURI.URIId = URI.URIId + ''' + return [dict(r) for r in await risotto_context.connection.fetch(sql)] diff --git a/src/risotto/services/user/__init__.py b/src/risotto/services/user/__init__.py new file mode 100644 index 0000000..092fc52 --- /dev/null +++ b/src/risotto/services/user/__init__.py @@ -0,0 +1 @@ +from .user import Risotto diff --git a/src/risotto/services/user/user.py b/src/risotto/services/user/user.py new file mode 100644 index 0000000..aa7a150 --- /dev/null +++ b/src/risotto/services/user/user.py @@ -0,0 +1,143 @@ +from typing import Dict, Optional + +from ...controller import Controller +from ...register import register +from ...context import Context +from ...utils import _ + + +class Risotto(Controller): + @register('v1.user.create', None, database=True) + async def user_create(self, + risotto_context: Context, + user_login: str, + user_name: str, + user_surname: str) -> Dict: + user_insert = """INSERT INTO RisottoUser(UserLogin, UserName, UserSurname) + VALUES ($1,$2,$3) + RETURNING UserId + """ + user_id = await risotto_context.connection.fetchval(user_insert, + user_login, + user_name, + user_surname) + return {'user_id': user_id, + 'user_login': user_login, + 'user_name': user_name, + 'user_surname': user_surname} + + @register('v1.user.list', None, database=True) + async def user_list(self, + risotto_context: Context) -> Dict: + sql = ''' + SELECT UserId as user_id, UserLogin as user_login, UserName as user_name, UserSurname as user_surname + FROM RisottoUser + ''' + users = await risotto_context.connection.fetch(sql) + return [dict(r) for r in users] + + @register('v1.user.delete', None, database=True) + async def user_delete(self, + risotto_context: Context, + user_login: str) -> Dict: + sql = ''' + DELETE FROM RisottoUser + WHERE UserLogin = $1 + RETURNING UserId as user_id, UserLogin as user_login, UserName as user_name, UserSurname as user_surname + ''' + user = await risotto_context.connection.fetchrow(sql, + user_login) + if user is None: + raise Exception(_(f'unable to find user {user_login}')) + return dict(user) + + @register('v1.user.role.create', None, database=True) + async def user_role_create(self, + risotto_context: Context, + user_login: str, + role_name: str, + role_attribute: str, + role_attribute_value: str) -> Dict: + # Verify if user exists and get ID + sql = ''' + SELECT UserId + FROM RisottoUser + WHERE UserLogin = $1 + ''' + user_id = await risotto_context.connection.fetchval(sql, + user_login) + if user_id is None: + raise Exception(_(f'unable to find user {user_login}')) + sql = '''INSERT INTO UserRole(RoleUserId, RoleName, RoleAttribute, RoleAttributeValue) + VALUES($1,$2,$3,$4) + RETURNING RoleId + ''' + role_id = await risotto_context.connection.fetchval(sql, + user_id, + role_name, + role_attribute, + role_attribute_value) + return {'role_id': role_id, + 'user_login': user_login, + 'role_name': role_name, + 'role_attribute': role_attribute, + 'role_attribute_value': role_attribute_value} + + @register('v1.user.role.list', None, database=True) + async def user_role_list(self, + risotto_context: Context, + user_login: Optional[str]) -> Dict: + if not user_login: + sql = ''' + SELECT RoleId as role_id, RoleName as role_name, RoleAttribute as role_attribute, RoleAttributeValue as role_attribute_value, RisottoUser.UserLogin as user_login + FROM UserRole, RisottoUser + WHERE UserRole.RoleUserId = RisottoUser.UserId + ''' + roles = await risotto_context.connection.fetch(sql) + else: + # Verify if user exists and get ID + sql = ''' + SELECT UserId + FROM RisottoUser + WHERE UserLogin = $1 + ''' + user_id = await risotto_context.connection.fetchval(sql, + user_login) + if user_id is None: + raise Exception(_(f'unable to find user {user_login}')) + sql = ''' + SELECT RoleId as role_id, RoleName as role_name, RoleAttribute as role_attribute, RoleAttributeValue as role_attribute_value, RisottoUser.UserLogin as user_login + FROM UserRole, RisottoUser + WHERE UserRole.RoleUserId = RisottoUser.UserId AND UserRole.RoleUserId = $1 + ''' + roles = await risotto_context.connection.fetch(sql, + user_id) + return [dict(r) for r in roles] +# +# FIXME comment savoir quel role il faut supprimer ? avec attribut ou juste l'ID ? +# @register('v1.user.role.delete', None, database=True) +# async def user_role_delete(self, +# risotto_context: Context, +# user_login: str, +# role_name: str) -> Dict: +# # Verify if user exists and get ID +# sql = ''' +# SELECT UserId +# FROM RisottoUser +# WHERE UserLogin = $1 +# ''' +# user_id = await risotto_context.connection.fetchval(sql, +# user_login) +# if user_id is None: +# raise Exception(_(f'unable to find user {user_login}')) +# sql = ''' +# DELETE FROM RisottoRole +# WHERE RoleName = $1 AND UserId = $2 +# RETURNING RoleId as role_id, RoleName as role_name, RoleAttribute as role_attribute, RoleAttributeValue as role_attribute_value +# ''' +# role = await risotto_context.connection.fetchrow(sql, +# role_name, +# user_id) +# if role is None: +# raise Exception(_(f'unable to find role {role_name}')) +# return dict(role)