From 750ae0c34b5c93286e61b8530168ea45c8d1c32b Mon Sep 17 00:00:00 2001 From: Nadja Reitzenstein Date: Thu, 28 Apr 2022 19:01:15 +0200 Subject: [PATCH 1/4] Make the API be more proper regarding user mgmnt --- general.capnp | 10 ++++++++++ usersystem.capnp | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/general.capnp b/general.capnp index 01460cc..8819eef 100644 --- a/general.capnp +++ b/general.capnp @@ -33,3 +33,13 @@ struct Optional(T) { just @1 :T; } } + +struct Fallible(T, E) { + # Some operations can fail in several expected ways. + # In those cases returning an `Optional` doesn't transfer information about the way that the + # operation failed. `Fallible` contains this information in the generic `E` type. + union { + successful @0 :T; + failed @1 :E; + } +} diff --git a/usersystem.capnp b/usersystem.capnp index f5754c4..722065b 100644 --- a/usersystem.capnp +++ b/usersystem.capnp @@ -8,6 +8,8 @@ $CSharp.namespace("FabAccessAPI.Schema"); using General = import "general.capnp"; using User = import "user.capnp".User; +using Optional = General.Optional; +using Fallible = General.Fallible; struct UserSystem { @@ -16,11 +18,23 @@ struct UserSystem getUserSelf @0 ( ) -> User; } + search @2 :Search; + interface Search $CSharp.name("SearchInterface") { + getUserByName @0 (username: Text) -> Optional(User); + } + manage @1 :Manage; interface Manage $CSharp.name("ManageInterface") { getUserList @0 () -> ( user_list :List(User) ); - addUser @1 (username :Text, password: Text) -> User; + enum AddUserError { + alreadyExists @0; + # An user with that username already exists + usernameInvalid @1; + # The provided username is unusable, e.g. contains invalid characters, + # is too long or too short. + } + addUser @1 (username :Text, password: Text) -> Fallible(User, AddUserError); removeUser @2 (user: User); } } From 93f130873eb23357a32cc04269dbf927c9041b17 Mon Sep 17 00:00:00 2001 From: Nadja Reitzenstein Date: Thu, 28 Apr 2022 20:10:06 +0200 Subject: [PATCH 2/4] stay backwards compatible --- general.capnp | 6 +++--- usersystem.capnp | 21 +++++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/general.capnp b/general.capnp index 8819eef..9ce6218 100644 --- a/general.capnp +++ b/general.capnp @@ -39,7 +39,7 @@ struct Fallible(T, E) { # In those cases returning an `Optional` doesn't transfer information about the way that the # operation failed. `Fallible` contains this information in the generic `E` type. union { - successful @0 :T; - failed @1 :E; + failed @0 :E; + successful @1 :T; } -} +} \ No newline at end of file diff --git a/usersystem.capnp b/usersystem.capnp index 722065b..0148425 100644 --- a/usersystem.capnp +++ b/usersystem.capnp @@ -27,14 +27,19 @@ struct UserSystem interface Manage $CSharp.name("ManageInterface") { getUserList @0 () -> ( user_list :List(User) ); - enum AddUserError { - alreadyExists @0; - # An user with that username already exists - usernameInvalid @1; - # The provided username is unusable, e.g. contains invalid characters, - # is too long or too short. - } - addUser @1 (username :Text, password: Text) -> Fallible(User, AddUserError); + addUser @1 (username :Text, password: Text) -> User; removeUser @2 (user: User); + + struct AddUserError { + enum AddUserError { + alreadyExists @0; + # An user with that username already exists + usernameInvalid @1; + # The provided username is unusable, e.g. contains invalid characters, + # is too long or too short. + } + error @0 :AddUserError; + } + addUserFallible @3 (username :Text, password: Text) -> Fallible(User, AddUserError); } } From c00a274a16e9ec3e68502131e73648ca9edbcfe3 Mon Sep 17 00:00:00 2001 From: Nadja Reitzenstein Date: Thu, 28 Apr 2022 20:11:08 +0200 Subject: [PATCH 3/4] Add deprecation comment --- usersystem.capnp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/usersystem.capnp b/usersystem.capnp index 0148425..60c2a71 100644 --- a/usersystem.capnp +++ b/usersystem.capnp @@ -28,6 +28,8 @@ struct UserSystem getUserList @0 () -> ( user_list :List(User) ); addUser @1 (username :Text, password: Text) -> User; + # DEPRECATED: use `addUserFallible` instead + removeUser @2 (user: User); struct AddUserError { From d04d930bd3de31a718459440361ab50dee020e6e Mon Sep 17 00:00:00 2001 From: Nadja Reitzenstein Date: Thu, 28 Apr 2022 20:12:16 +0200 Subject: [PATCH 4/4] Add an 'invalid password' error --- usersystem.capnp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/usersystem.capnp b/usersystem.capnp index 60c2a71..ca9ff69 100644 --- a/usersystem.capnp +++ b/usersystem.capnp @@ -36,9 +36,13 @@ struct UserSystem enum AddUserError { alreadyExists @0; # An user with that username already exists + usernameInvalid @1; # The provided username is unusable, e.g. contains invalid characters, # is too long or too short. + + passwordInvalid @2; + # The provided password is unusable, e.g. it's of zero length } error @0 :AddUserError; }