From 1378c8722d49c45900d019bd733feba5108123e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nadja=20von=20Reitzenstein=20=C4=8Cerpnjak?= Date: Tue, 16 Apr 2024 15:03:10 +0200 Subject: [PATCH] Make compile --- claim.capnp | 55 ++++++++++++++++++++++++----------------- interest.capnp | 17 +++++++++++-- measure.capnp | 5 ++++ notify.capnp | 3 ++- projects.capnp | 1 + resource.capnp | 16 ++++++------ resources.capnp | 8 +++++- traits.capnp | 4 +-- traits/checkable.capnp | 11 +++++---- traits/door.capnp | 16 ++++++------ traits/locateable.capnp | 20 +++++++++------ traits/lockers.capnp | 10 ++++---- traits/powerable.capnp | 12 ++++----- user.capnp | 21 +++++++++++++--- users.capnp | 48 +++++++++++++++++++++-------------- utils.capnp | 6 +++++ 16 files changed, 162 insertions(+), 91 deletions(-) create mode 100644 measure.capnp diff --git a/claim.capnp b/claim.capnp index e08b134..c7832f8 100644 --- a/claim.capnp +++ b/claim.capnp @@ -3,15 +3,13 @@ using CSharp = import "programming_language/csharp.capnp"; $CSharp.namespace("FabAccessAPI.Schema"); -# TODO: removed SturdyRef to build API in C# -# using import "/capnp/rpc.capnp".SturdyRef; -# using import "persistent.capnp".Persistent; - using import "resource.capnp".Resource; using import "notify.capnp".Notifiable; +using import "interest.capnp".Interest; using import "utils.capnp".Fallible; using import "utils.capnp".OID; using import "utils.capnp".Map; +using import "utils.capnp".SturdyRef; using import "projects.capnp".Project; interface Claimable { @@ -20,19 +18,12 @@ interface Claimable { # Disown the returned claim capability to unclaim it. struct ClaimError { - union { - locked @0 :Text; - } + locked @0 :Text; } } interface Lockable { - restore @0 ( ) -> ( lock :Lock ); - # TODO: removed SturdyRef to build API in C# - # restore @0 ( sturdy :SturdyRef ) -> ( lock :Lock ); - # Restore a previously saved SturdyRef pointing to a Lock - - lock @1 ( message :Text ) -> ( lock :Lock ); + lock @0 ( message :Text ) -> ( lock :Lock ); # Take exclusive access to a resource, disowning all other claims on this # resource. # @@ -52,22 +43,40 @@ interface Claim extends (Notifiable) { traits @1 () -> Map(OID, AnyPointer); - disown @2 () -> Fallible(Void, Error(DisownError)); + disown @2 () -> Fallible(DisownOk, DisownError); # Disown this claim TODO define ConstraintViolation type -> Dependencies! - makeTransferable @3 () -> Fallible(SturdyRef, Error(Void)); - makeLendable @4 () -> Fallible(( token :Sturdyref, returnToken :Interest ), Error(Void)); + struct DisownOk { + + } + + struct DisownError { + union { + dependency @0 :List(Claim); + badState @1 :Void; + } + } + + makeTransferable @3 () -> Fallible(SturdyRef, MakeTransferableError); + + struct MakeTransferableError { + permissionDenied @0 :Void; + } + + makeLendable @4 () -> Fallible(MakeLendableOk, MakeLendableError); + + struct MakeLendableOk { + token @0 :SturdyRef; + returnToken @1 :Interest; + } + + struct MakeLendableError { + permissionDenied @0 :Void; + } getDependencies @5 () -> ( dependencies: List(Claim) ); } -struct DisownError { - union { - dependency @0 :List(Claim); - badState @1 :Void; - } -} - interface Lock extends (Claim) { # An exclusive claim on a resource. Only a single Lock may exist for any given resource. diff --git a/interest.capnp b/interest.capnp index 37cdef9..a2751f1 100644 --- a/interest.capnp +++ b/interest.capnp @@ -3,9 +3,22 @@ using CSharp = import "programming_language/csharp.capnp"; $CSharp.namespace("FabAccessAPI.Schema"); +using import "resource.capnp".Resource; +using import "resource.capnp".Description; +using import "claim.capnp".Claim; +using import "utils.capnp".When; +using import "utils.capnp".Fallible; + interface Interestable { - queue @0 () -> Fallible(Interest, Error(Void)); - reserve @1 ( when :When ) -> Fallible(Interest, Error(Void)); + queue @0 () -> Fallible(Interest, ReserveError); + reserve @1 ( when :When ) -> Fallible(Interest, ReserveError); + struct ReserveError { + union { + permissionDenied @0 :Void; + reserveOverlapping @1 :Void; + queueFull @2 :Void; + } + } getInterests @2 () -> ( interests :List(Interest) ); # WARNING: Impersonates users } diff --git a/measure.capnp b/measure.capnp new file mode 100644 index 0000000..99a4981 --- /dev/null +++ b/measure.capnp @@ -0,0 +1,5 @@ +@0xdb815f35cc321540; + +struct Measurement { + +} diff --git a/notify.capnp b/notify.capnp index 62bbf52..46f86d7 100644 --- a/notify.capnp +++ b/notify.capnp @@ -7,6 +7,7 @@ using import "resource.capnp".Resource; using import "utils.capnp".OID; using import "utils.capnp".Map; using import "state.capnp".Update; +using import "measure.capnp".Measurement; interface Notifiable { state @0 () -> ( state :Map(OID, AnyPointer) ); @@ -16,7 +17,7 @@ interface Notifiable { # Subscribe to state updates. The passed in `subscriber` is an interface implemented on the # client side that a server calls to send update notifications. - measurements @2 () -> ( measurements :Map(Oid, AnyPointer) ); + measurements @2 () -> ( measurements :Map(OID, AnyPointer) ); subscribeMeasurements @3 ( subscriber :Subscriber(Measurement) ) -> ( subscription: Subscription ); } diff --git a/projects.capnp b/projects.capnp index 7906f16..9116d7d 100644 --- a/projects.capnp +++ b/projects.capnp @@ -1,3 +1,4 @@ +@0xdcc65f4a7b1b013a; interface Project { diff --git a/resource.capnp b/resource.capnp index 3947f8d..484dc49 100644 --- a/resource.capnp +++ b/resource.capnp @@ -3,13 +3,13 @@ using CSharp = import "programming_language/csharp.capnp"; $CSharp.namespace("FabAccessAPI.Schema"); -# TODO: removed SturdyRef to build API in C# -# using import "persistent.capnp".Persistent; - using import "notify.capnp".Notifiable; using import "interest.capnp".Interestable; +using import "interest.capnp".Interest; using import "claim.capnp".Claimable; +using import "claim.capnp".Claim; using import "claim.capnp".Lockable; +using import "claim.capnp".Lock; using import "audit.capnp".Auditable; using import "utils.capnp".OID; @@ -57,25 +57,25 @@ struct Resource { } struct Description { - name @1 :L10NString; + name @0 :L10NString; # A human-facing name for this resource. A name should be short and recognizable, and is meant # as the primary identifier for users to find a resource. - description @2 :L10NString; + description @1 :L10NString; # A human-facing description for this resource. Descriptions are longer-form text that give # additional information about a resource beyond a name. They are meant to provide either # further identifying information or important information that users should be actively shown # when selecting this resource. - types @3 :List(OID); + types @2 :List(OID); # The 'type' of Resource. Each OID in the list specifies certain behaviours that this Resource # follows. - category @4 :Category; + category @3 :Category; # A category this resource belongs to. If a resource was not assigned a category this is empty, # see the definition of [`Category`](struct::Category) for details. - metadata @5 :Map(Text, Metadata); + metadata @4 :Map(Text, Metadata); # Metadata associated with this resource. This can be things like links to wikis or similar. # Common keys are pre-defined as constants in this file. } diff --git a/resources.capnp b/resources.capnp index 861745e..19ebfe3 100644 --- a/resources.capnp +++ b/resources.capnp @@ -6,6 +6,8 @@ $CSharp.namespace("FabAccessAPI.Schema"); using import "resource.capnp".Resource; using import "resource.capnp".RestoredResource; using import "claim.capnp".Claim; +using import "utils.capnp".SturdyRef; +using import "utils.capnp".Fallible; interface Resources { restore @0 () -> ( resources :List(RestoredResource) ); @@ -23,5 +25,9 @@ interface Resources { getByUrl @4 ( url :Text ) -> ( resource :Resource ); # Returns a NULL capability if the resource doesn't exist or a user doesn't have read permission for that resource. - acceptToken @5 ( token :SturdyRef ) -> Fallible(Claim, Error(Void)); + acceptToken @5 ( token :SturdyRef ) -> Fallible(Claim, AcceptTokenError); + + struct AcceptTokenError { + permissionDenied @0 :Void; + } } diff --git a/traits.capnp b/traits.capnp index 61b7583..a1b0204 100644 --- a/traits.capnp +++ b/traits.capnp @@ -1,4 +1,4 @@ -@0xc0542f62613a5c5e +@0xc0542f62613a5c5e; using CSharp = import "programming_language/csharp.capnp"; $CSharp.namespace("FabAccessAPI.Schema"); @@ -10,6 +10,6 @@ interface TraitSuper { struct TraitError(ConstraintError) { union { permissionFailed @0 :Void; - constraintViolation @1 ( error :ConstraintError); + constraintViolation @1 :ConstraintError; } } diff --git a/traits/checkable.capnp b/traits/checkable.capnp index 6b25a08..5ee7cce 100644 --- a/traits/checkable.capnp +++ b/traits/checkable.capnp @@ -1,11 +1,12 @@ @0x80d4a09e28022edb; -using CSharp = import "programming_language/csharp.capnp"; +using CSharp = import "../programming_language/csharp.capnp"; $CSharp.namespace("FabAccessAPI.Schema"); -using import "traits.capnp".TraitSuper; -using import "utils.capnp".Fallible; -using import "traits_error.capnp".TraitError; +using import "../traits.capnp".TraitSuper; +using import "../traits.capnp".TraitError; +using import "../utils.capnp".Fallible; +using import "../utils.capnp".L10NString; # OID for this trait: 1.3.6.1.4.1.61783.612.1.3 # │ │ │ │ @@ -21,7 +22,7 @@ interface TraitCheckable extends (TraitSuper) { getState @0 () -> StateCheckable; turnOn @1 () -> Fallible(TraitCheckable, TraitError(StateCheckable)); turnOff @2 () -> Fallible(TraitCheckable, TraitError(StateCheckable)); - giveBack @3 () -> Fallible(TraitCheckable, TraitError(StateCheckable));; + giveBack @3 () -> Fallible(TraitCheckable, TraitError(StateCheckable)); accept @4 () -> Fallible(TraitCheckable, TraitError(StateCheckable)); reject @5 ( reason :Text, reason_lang :Text ) -> Fallible(TraitCheckable, TraitError(StateCheckable)); } diff --git a/traits/door.capnp b/traits/door.capnp index 76c86d5..d6a934a 100644 --- a/traits/door.capnp +++ b/traits/door.capnp @@ -1,12 +1,12 @@ @0xccad643c8c6f6b25; -using CSharp = import "programming_language/csharp.capnp"; +using CSharp = import "../programming_language/csharp.capnp"; $CSharp.namespace("FabAccessAPI.Schema"); -using import "traits.capnp".TraitSuper; -using import "utils.capnp".Fallible; -using import "utils.capnp".Duration; -using import "traits_error.capnp".TraitError; +using import "../traits.capnp".TraitSuper; +using import "../traits.capnp".TraitError; +using import "../utils.capnp".Fallible; +using import "../utils.capnp".Duration; # OID for this trait: 1.3.6.1.4.1.61783.612.1.2 # │ │ │ │ @@ -27,8 +27,8 @@ interface TraitDoorable extends (TraitSuper) { struct StateDoorable { union { - Closed @0 :Void; - Open @1 :Void; - TempOpen @2 :Void; + closed @0 :Void; + open @1 :Void; + tempOpen @2 :Void; } } diff --git a/traits/locateable.capnp b/traits/locateable.capnp index 978d1b5..4fb3db8 100644 --- a/traits/locateable.capnp +++ b/traits/locateable.capnp @@ -1,12 +1,12 @@ @0x9fa2b43397f34e02; -using CSharp = import "programming_language/csharp.capnp"; +using CSharp = import "../programming_language/csharp.capnp"; $CSharp.namespace("FabAccessAPI.Schema"); -using import "traits.capnp".TraitSuper; -using import "utils.capnp".Fallible; -using import "utils.capnp".Duration; -using import "traits.capnp".TraitError; +using import "../traits.capnp".TraitSuper; +using import "../traits.capnp".TraitError; +using import "../utils.capnp".Fallible; +using import "../utils.capnp".Duration; # OID for this trait: 1.3.6.1.4.1.61783.612.1.5 # │ │ │ │ @@ -20,9 +20,13 @@ using import "traits.capnp".TraitError; interface TraitLocateable extends (TraitSuper) { getState @0 () -> (); - identify @1 ( time :Duration ) -> Fallible(TraitLocateable, TraitError(Void)); - setActive @2 () -> Fallible(TraitLocateable, TraitError(Void)); - setIdle @2 () -> Fallible(TraitLocateable, TraitError(Void)); + identify @1 ( time :Duration ) -> Fallible(TraitLocateable, TraitError(ErrorLocateable)); + setActive @2 () -> Fallible(TraitLocateable, TraitError(ErrorLocateable)); + setIdle @3 () -> Fallible(TraitLocateable, TraitError(ErrorLocateable)); +} + +struct ErrorLocateable { + } struct StateLocateable { diff --git a/traits/lockers.capnp b/traits/lockers.capnp index e0ac406..7aab8ad 100644 --- a/traits/lockers.capnp +++ b/traits/lockers.capnp @@ -1,11 +1,11 @@ @0x82abdb5c1dcf399d; -using CSharp = import "programming_language/csharp.capnp"; +using CSharp = import "../programming_language/csharp.capnp"; $CSharp.namespace("FabAccessAPI.Schema"); -using import "traits.capnp".TraitSuper; -using import "utils.capnp".Fallible; -using import "traits_error.capnp".TraitError; +using import "../traits.capnp".TraitSuper; +using import "../traits.capnp".TraitError; +using import "../utils.capnp".Fallible; # OID for this trait: 1.3.6.1.4.1.61783.612.1.4 # │ │ │ │ @@ -19,7 +19,7 @@ using import "traits_error.capnp".TraitError; interface TraitLocker extends (TraitSuper) { getState @0 () -> StateLocker; - engage @1 () -> Fallible(TraitLocker, TraitError(ErrorLocker)) + engage @1 () -> Fallible(TraitLocker, TraitError(ErrorLocker)); unengage @2 () -> Fallible(TraitLocker, TraitError(ErrorLocker)); } diff --git a/traits/powerable.capnp b/traits/powerable.capnp index 021f242..c9c32e6 100644 --- a/traits/powerable.capnp +++ b/traits/powerable.capnp @@ -1,11 +1,11 @@ @0xbab3de8275be2271; -using CSharp = import "programming_language/csharp.capnp"; +using CSharp = import "../programming_language/csharp.capnp"; $CSharp.namespace("FabAccessAPI.Schema"); -using import "traits.capnp".TraitSuper; -using import "utils.capnp".Fallible; -using import "traits_error.capnp".TraitError; +using import "../traits.capnp".TraitSuper; +using import "../utils.capnp".Fallible; +using import "../traits.capnp".TraitError; # OID for this trait: 1.3.6.1.4.1.61783.612.1.1 # │ │ │ │ @@ -25,7 +25,7 @@ interface TraitPowerable extends (TraitSuper) { struct StatePowerable { union { - Off @0 :Void; - On @1 :Void; + off @0 :Void; + on @1 :Void; } } diff --git a/user.capnp b/user.capnp index 0fc650f..ac7756c 100644 --- a/user.capnp +++ b/user.capnp @@ -4,6 +4,8 @@ using CSharp = import "programming_language/csharp.capnp"; $CSharp.namespace("FabAccessAPI.Schema"); using import "role.capnp".Role; +using import "projects.capnp".Project; +using import "utils.capnp".Fallible; interface User { # Intergalactic lifeform that wants to use BFFH @@ -18,14 +20,27 @@ interface User { # lists explicit roles for this user. A session may have a number of additional, implicit, # roles set by their choice of authentication or other context. - projects @3 () -> ( projects :List(Project) ); + projects @7 () -> ( projects :List(Project) ); selfservice @3 () -> ( selfservice :SelfService ); interface SelfService { - changepw @0 ( old :Text, new :Text ) -> Fallible(Void, Void); - changePin @1 ( currentPassword :Text, newPin :List(u64) ) -> Fallible(Void, Void) + changepw @0 ( old :Text, new :Text ) -> Fallible(ChangeOk, ChangePwError); + changePin @1 ( currentPassword :Text, newPin :List(UInt64) ) -> Fallible(ChangeOk, ChangePinError); + + struct ChangeOk { + + } + + struct ChangePwError { + + } + + struct ChangePinError { + + } } + manage @4 () -> ( manage :Manage ); interface Manage $CSharp.name("ManageInterface") { addRole @0 ( role :Role ); diff --git a/users.capnp b/users.capnp index 506a2a0..d5b5c2d 100644 --- a/users.capnp +++ b/users.capnp @@ -4,33 +4,43 @@ using CSharp = import "programming_language/csharp.capnp"; $CSharp.namespace("FabAccessAPI.Schema"); using import "user.capnp".User; +using import "utils.capnp".Fallible; interface Users { list @0 () -> ( users :List(User) ); - addUser @1 ( username :Text ) -> ( user :User, initialPassword :Text, error :Error ); - # Add a new user. If adding the user succeeds then the newly created user is returned and - # `error` is NULL / set to Error::ok. If adding the user fails `user` is NULL and `error` - # contains the reason for the failure. + addUser @1 ( username :Text ) -> Fallible(AddUserOk, AddUserError); + struct AddUserOk { + user @0 :User; + initialPassword @1 :Text; + } + struct AddUserError { + union { + ok @0 :Void; + # This error is not actually set, i.e. the operation completed successfully. + # This field is necessary because a NULL struct pointer may be interpreted as a struct with + # default values. In that case this will appear as an `Error` with the `ok` field set. - removeUser @2 ( user :User ) -> Fallible(Void, Void); -} + exists @1 :Void; + # There is already an user with the requested username -struct Error { - union { - ok @0 :Void; - # This error is not actually set, i.e. the operation completed successfully. - # This field is necessary because a NULL struct pointer may be interpreted as a struct with - # default values. In that case this will appear as an `Error` with the `ok` field set. + usernameInvalid @2 :Void; + # The provided username is not usable, e.g. contains invalid characters, is too long, or too + # short. - exists @1 :Void; - # There is already an user with the requested username + passwordInvalid @3 :Void; + # The provided password is not usable, e.g. it's zero-length. + } + } - usernameInvalid @2 :Void; - # The provided username is not usable, e.g. contains invalid characters, is too long, or too - # short. + removeUser @2 ( user :User ) -> Fallible(RemoveUserOk, RemoveUserError); + struct RemoveUserOk { - passwordInvalid @3 :Void; - # The provided password is not usable, e.g. it's zero-length. + } + struct RemoveUserError { + union { + permissionDenied @0 :Void; + userAlreadyDeleted @1 :Void; + } } } diff --git a/utils.capnp b/utils.capnp index aaa8f7d..ea459db 100644 --- a/utils.capnp +++ b/utils.capnp @@ -90,3 +90,9 @@ struct Duration { seconds @0 :UInt64; nanoseconds @1 :UInt64; } + +using SturdyRef = Data; + +struct When { + # TODO: define this +}