From 60b372b0fa4baa4dde5c6bf5740483a710e921c7 Mon Sep 17 00:00:00 2001 From: Xeronith Date: Tue, 6 Dec 2022 11:48:31 +0330 Subject: [PATCH] feat(components): :sparkles: interaction authorization --- .../handlers/authorize_interaction_handler.go | 45 ++++ greataped/components/api/handlers/factory.go | 21 +- .../authorize_interaction_operation.go | 51 +++++ .../components/api/operations/factory.go | 1 + greataped/components/api/protobuf/spis.pb.go | 208 +++++++++++++++--- greataped/components/api/protobuf/spis.proto | 11 + .../services/authorize_interaction_service.go | 30 +++ greataped/components/contracts/api.go | 1 + greataped/components/contracts/opcodes.go | 6 + greataped/components/contracts/spi.go | 6 + .../components/contracts/system_component.go | 2 + .../components/contracts/system_dispatcher.go | 3 + greataped/components/core/api_methods.go | 11 + greataped/components/core/initializer.go | 8 + greataped/components/core/spi.go | 4 + greataped/components/core/spi_manager.go | 41 ++++ greataped/components/core/system_results.go | 4 + 17 files changed, 408 insertions(+), 45 deletions(-) create mode 100644 greataped/components/api/handlers/authorize_interaction_handler.go create mode 100644 greataped/components/api/operations/authorize_interaction_operation.go create mode 100644 greataped/components/api/services/authorize_interaction_service.go diff --git a/greataped/components/api/handlers/authorize_interaction_handler.go b/greataped/components/api/handlers/authorize_interaction_handler.go new file mode 100644 index 0000000..c199459 --- /dev/null +++ b/greataped/components/api/handlers/authorize_interaction_handler.go @@ -0,0 +1,45 @@ +package handlers + +import ( + "net/http" + + . "github.com/xeronith/diamante/contracts/network/http" + pipeline "github.com/xeronith/diamante/network/http" + . "rail.town/infrastructure/components/api/protobuf" + . "rail.town/infrastructure/components/contracts" +) + +type authorizeInteractionHandler struct { +} + +func AuthorizeInteractionHandler() IHttpHandler { + return &authorizeInteractionHandler{} +} + +func (handler *authorizeInteractionHandler) Method() string { + return http.MethodGet +} + +func (handler *authorizeInteractionHandler) Path() string { + return "/authorize_interaction" +} + +func (handler *authorizeInteractionHandler) HandlerFunc() HttpHandlerFunc { + return func(x IServerDispatcher) error { + request := &AuthorizeInteractionRequest{} + result := &AuthorizeInteractionResult{} + + onRequestUnmarshalled := func(request *AuthorizeInteractionRequest) { + request.Uri = x.Query("uri") + } + + return pipeline.Handle(x, + "authorize_interaction", + AUTHORIZE_INTERACTION_REQUEST, + AUTHORIZE_INTERACTION_RESULT, + request, result, + onRequestUnmarshalled, + false, + ) + } +} diff --git a/greataped/components/api/handlers/factory.go b/greataped/components/api/handlers/factory.go index 0eafbcf..4baaa2f 100644 --- a/greataped/components/api/handlers/factory.go +++ b/greataped/components/api/handlers/factory.go @@ -6,16 +6,17 @@ type httpHandlerFactory struct{} func (factory *httpHandlerFactory) Handlers() []IHttpHandler { return []IHttpHandler{ - EchoHandler(), // │ P . /api/v1/echo - SignupHandler(), // │ P . /api/v1/signup - VerifyHandler(), // │ P . /api/v1/verify - LoginHandler(), // │ P . /api/v1/login - GetProfileByUserHandler(), // │ G . /api/v1/profile - UpdateProfileByUserHandler(), // │ P . /api/v1/profile - LogoutHandler(), // │ P . /api/v1/logout - WebfingerHandler(), // │ G . /.well-known/webfinger - GetActorHandler(), // │ G . /u/:username - FollowActorHandler(), // │ G . /u/:username/follow + EchoHandler(), // │ P . /api/v1/echo + SignupHandler(), // │ P . /api/v1/signup + VerifyHandler(), // │ P . /api/v1/verify + LoginHandler(), // │ P . /api/v1/login + GetProfileByUserHandler(), // │ G . /api/v1/profile + UpdateProfileByUserHandler(), // │ P . /api/v1/profile + LogoutHandler(), // │ P . /api/v1/logout + WebfingerHandler(), // │ G . /.well-known/webfinger + GetActorHandler(), // │ G . /u/:username + FollowActorHandler(), // │ G . /u/:username/follow + AuthorizeInteractionHandler(), // │ G . /authorize_interaction } } diff --git a/greataped/components/api/operations/authorize_interaction_operation.go b/greataped/components/api/operations/authorize_interaction_operation.go new file mode 100644 index 0000000..f94b1ab --- /dev/null +++ b/greataped/components/api/operations/authorize_interaction_operation.go @@ -0,0 +1,51 @@ +package operations + +import ( + . "github.com/xeronith/diamante/contracts/operation" + . "github.com/xeronith/diamante/contracts/service" + . "github.com/xeronith/diamante/contracts/system" + . "github.com/xeronith/diamante/operation" + . "rail.town/infrastructure/components/api/protobuf" + . "rail.town/infrastructure/components/api/services" + . "rail.town/infrastructure/components/contracts" +) + +type authorizeInteractionOperation struct { + Operation + + run func(IContext, *AuthorizeInteractionRequest) (*AuthorizeInteractionResult, error) +} + +func AuthorizeInteractionOperation() IOperation { + return &authorizeInteractionOperation{ + run: AuthorizeInteractionService, + } +} + +func (operation *authorizeInteractionOperation) Id() (ID, ID) { + return AUTHORIZE_INTERACTION_REQUEST, AUTHORIZE_INTERACTION_RESULT +} + +func (operation *authorizeInteractionOperation) InputContainer() Pointer { + return new(AuthorizeInteractionRequest) +} + +func (operation *authorizeInteractionOperation) OutputContainer() Pointer { + return new(AuthorizeInteractionResult) +} + +func (operation *authorizeInteractionOperation) Execute(context IContext, payload Pointer) (Pointer, error) { + return operation.run(context, payload.(*AuthorizeInteractionRequest)) +} + +/* +func (operation *authorizeInteractionOperation) ExecutionTimeLimits() (Duration, Duration, Duration) { + var ( + TIME_LIMIT_WARNING Duration = 20_000_000 + TIME_LIMIT_ALERT Duration = 35_000_000 + TIME_LIMIT_CRITICAL Duration = 50_000_000 + ) + + return TIME_LIMIT_WARNING, TIME_LIMIT_ALERT, TIME_LIMIT_CRITICAL +} +*/ diff --git a/greataped/components/api/operations/factory.go b/greataped/components/api/operations/factory.go index 5e1b8cc..32eadc5 100644 --- a/greataped/components/api/operations/factory.go +++ b/greataped/components/api/operations/factory.go @@ -17,6 +17,7 @@ func (factory *operationFactory) Operations() []IOperation { WebfingerOperation(), GetActorOperation(), FollowActorOperation(), + AuthorizeInteractionOperation(), } } diff --git a/greataped/components/api/protobuf/spis.pb.go b/greataped/components/api/protobuf/spis.pb.go index 8aacf72..b18c61a 100644 --- a/greataped/components/api/protobuf/spis.pb.go +++ b/greataped/components/api/protobuf/spis.pb.go @@ -1336,6 +1336,110 @@ func (x *FollowActorResult) GetUrl() string { return "" } +// API: AuthorizeInteraction +// ----------------------------------------------------------- +type AuthorizeInteractionRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Uri string `protobuf:"bytes,1,opt,name=uri,proto3" json:"uri,omitempty"` +} + +func (x *AuthorizeInteractionRequest) Reset() { + *x = AuthorizeInteractionRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_spis_proto_msgTypes[22] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AuthorizeInteractionRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AuthorizeInteractionRequest) ProtoMessage() {} + +func (x *AuthorizeInteractionRequest) ProtoReflect() protoreflect.Message { + mi := &file_spis_proto_msgTypes[22] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AuthorizeInteractionRequest.ProtoReflect.Descriptor instead. +func (*AuthorizeInteractionRequest) Descriptor() ([]byte, []int) { + return file_spis_proto_rawDescGZIP(), []int{22} +} + +func (x *AuthorizeInteractionRequest) GetUri() string { + if x != nil { + return x.Uri + } + return "" +} + +type AuthorizeInteractionResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Uri string `protobuf:"bytes,1,opt,name=uri,proto3" json:"uri,omitempty"` + Success bool `protobuf:"varint,2,opt,name=success,proto3" json:"success,omitempty"` +} + +func (x *AuthorizeInteractionResult) Reset() { + *x = AuthorizeInteractionResult{} + if protoimpl.UnsafeEnabled { + mi := &file_spis_proto_msgTypes[23] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AuthorizeInteractionResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AuthorizeInteractionResult) ProtoMessage() {} + +func (x *AuthorizeInteractionResult) ProtoReflect() protoreflect.Message { + mi := &file_spis_proto_msgTypes[23] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AuthorizeInteractionResult.ProtoReflect.Descriptor instead. +func (*AuthorizeInteractionResult) Descriptor() ([]byte, []int) { + return file_spis_proto_rawDescGZIP(), []int{23} +} + +func (x *AuthorizeInteractionResult) GetUri() string { + if x != nil { + return x.Uri + } + return "" +} + +func (x *AuthorizeInteractionResult) GetSuccess() bool { + if x != nil { + return x.Success + } + return false +} + var File_spis_proto protoreflect.FileDescriptor var file_spis_proto_rawDesc = []byte{ @@ -1465,7 +1569,15 @@ var file_spis_proto_rawDesc = []byte{ 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x63, 0x63, 0x74, 0x22, 0x25, 0x0a, 0x11, 0x46, 0x6f, 0x6c, 0x6c, 0x6f, 0x77, 0x41, 0x63, 0x74, 0x6f, 0x72, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, - 0x42, 0x04, 0x5a, 0x02, 0x2e, 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x22, 0x2f, 0x0a, 0x1b, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x49, 0x6e, 0x74, + 0x65, 0x72, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x10, 0x0a, 0x03, 0x75, 0x72, 0x69, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, + 0x69, 0x22, 0x48, 0x0a, 0x1a, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x49, 0x6e, + 0x74, 0x65, 0x72, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, + 0x10, 0x0a, 0x03, 0x75, 0x72, 0x69, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, + 0x69, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x42, 0x04, 0x5a, 0x02, 0x2e, + 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1480,42 +1592,44 @@ func file_spis_proto_rawDescGZIP() []byte { return file_spis_proto_rawDescData } -var file_spis_proto_msgTypes = make([]protoimpl.MessageInfo, 22) +var file_spis_proto_msgTypes = make([]protoimpl.MessageInfo, 24) var file_spis_proto_goTypes = []interface{}{ - (*SystemCallRequest)(nil), // 0: protobuf.SystemCallRequest - (*SystemCallResult)(nil), // 1: protobuf.SystemCallResult - (*EchoRequest)(nil), // 2: protobuf.EchoRequest - (*EchoResult)(nil), // 3: protobuf.EchoResult - (*SignupRequest)(nil), // 4: protobuf.SignupRequest - (*SignupResult)(nil), // 5: protobuf.SignupResult - (*VerifyRequest)(nil), // 6: protobuf.VerifyRequest - (*VerifyResult)(nil), // 7: protobuf.VerifyResult - (*LoginRequest)(nil), // 8: protobuf.LoginRequest - (*LoginResult)(nil), // 9: protobuf.LoginResult - (*GetProfileByUserRequest)(nil), // 10: protobuf.GetProfileByUserRequest - (*GetProfileByUserResult)(nil), // 11: protobuf.GetProfileByUserResult - (*UpdateProfileByUserRequest)(nil), // 12: protobuf.UpdateProfileByUserRequest - (*UpdateProfileByUserResult)(nil), // 13: protobuf.UpdateProfileByUserResult - (*LogoutRequest)(nil), // 14: protobuf.LogoutRequest - (*LogoutResult)(nil), // 15: protobuf.LogoutResult - (*WebfingerRequest)(nil), // 16: protobuf.WebfingerRequest - (*WebfingerResult)(nil), // 17: protobuf.WebfingerResult - (*GetActorRequest)(nil), // 18: protobuf.GetActorRequest - (*GetActorResult)(nil), // 19: protobuf.GetActorResult - (*FollowActorRequest)(nil), // 20: protobuf.FollowActorRequest - (*FollowActorResult)(nil), // 21: protobuf.FollowActorResult - (*Document)(nil), // 22: protobuf.Document - (*ActivityPubLink)(nil), // 23: protobuf.ActivityPubLink - (*ActivityPubMedia)(nil), // 24: protobuf.ActivityPubMedia - (*ActivityPubPublicKey)(nil), // 25: protobuf.ActivityPubPublicKey + (*SystemCallRequest)(nil), // 0: protobuf.SystemCallRequest + (*SystemCallResult)(nil), // 1: protobuf.SystemCallResult + (*EchoRequest)(nil), // 2: protobuf.EchoRequest + (*EchoResult)(nil), // 3: protobuf.EchoResult + (*SignupRequest)(nil), // 4: protobuf.SignupRequest + (*SignupResult)(nil), // 5: protobuf.SignupResult + (*VerifyRequest)(nil), // 6: protobuf.VerifyRequest + (*VerifyResult)(nil), // 7: protobuf.VerifyResult + (*LoginRequest)(nil), // 8: protobuf.LoginRequest + (*LoginResult)(nil), // 9: protobuf.LoginResult + (*GetProfileByUserRequest)(nil), // 10: protobuf.GetProfileByUserRequest + (*GetProfileByUserResult)(nil), // 11: protobuf.GetProfileByUserResult + (*UpdateProfileByUserRequest)(nil), // 12: protobuf.UpdateProfileByUserRequest + (*UpdateProfileByUserResult)(nil), // 13: protobuf.UpdateProfileByUserResult + (*LogoutRequest)(nil), // 14: protobuf.LogoutRequest + (*LogoutResult)(nil), // 15: protobuf.LogoutResult + (*WebfingerRequest)(nil), // 16: protobuf.WebfingerRequest + (*WebfingerResult)(nil), // 17: protobuf.WebfingerResult + (*GetActorRequest)(nil), // 18: protobuf.GetActorRequest + (*GetActorResult)(nil), // 19: protobuf.GetActorResult + (*FollowActorRequest)(nil), // 20: protobuf.FollowActorRequest + (*FollowActorResult)(nil), // 21: protobuf.FollowActorResult + (*AuthorizeInteractionRequest)(nil), // 22: protobuf.AuthorizeInteractionRequest + (*AuthorizeInteractionResult)(nil), // 23: protobuf.AuthorizeInteractionResult + (*Document)(nil), // 24: protobuf.Document + (*ActivityPubLink)(nil), // 25: protobuf.ActivityPubLink + (*ActivityPubMedia)(nil), // 26: protobuf.ActivityPubMedia + (*ActivityPubPublicKey)(nil), // 27: protobuf.ActivityPubPublicKey } var file_spis_proto_depIdxs = []int32{ - 22, // 0: protobuf.EchoRequest.document:type_name -> protobuf.Document - 22, // 1: protobuf.EchoResult.document:type_name -> protobuf.Document - 23, // 2: protobuf.WebfingerResult.links:type_name -> protobuf.ActivityPubLink - 24, // 3: protobuf.GetActorResult.icon:type_name -> protobuf.ActivityPubMedia - 24, // 4: protobuf.GetActorResult.image:type_name -> protobuf.ActivityPubMedia - 25, // 5: protobuf.GetActorResult.publicKey:type_name -> protobuf.ActivityPubPublicKey + 24, // 0: protobuf.EchoRequest.document:type_name -> protobuf.Document + 24, // 1: protobuf.EchoResult.document:type_name -> protobuf.Document + 25, // 2: protobuf.WebfingerResult.links:type_name -> protobuf.ActivityPubLink + 26, // 3: protobuf.GetActorResult.icon:type_name -> protobuf.ActivityPubMedia + 26, // 4: protobuf.GetActorResult.image:type_name -> protobuf.ActivityPubMedia + 27, // 5: protobuf.GetActorResult.publicKey:type_name -> protobuf.ActivityPubPublicKey 6, // [6:6] is the sub-list for method output_type 6, // [6:6] is the sub-list for method input_type 6, // [6:6] is the sub-list for extension type_name @@ -1794,6 +1908,30 @@ func file_spis_proto_init() { return nil } } + file_spis_proto_msgTypes[22].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*AuthorizeInteractionRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_spis_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*AuthorizeInteractionResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -1801,7 +1939,7 @@ func file_spis_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_spis_proto_rawDesc, NumEnums: 0, - NumMessages: 22, + NumMessages: 24, NumExtensions: 0, NumServices: 0, }, diff --git a/greataped/components/api/protobuf/spis.proto b/greataped/components/api/protobuf/spis.proto index 87b8331..93c2c88 100644 --- a/greataped/components/api/protobuf/spis.proto +++ b/greataped/components/api/protobuf/spis.proto @@ -149,4 +149,15 @@ message FollowActorResult { string url = 0x00000001; } +// API: AuthorizeInteraction +//----------------------------------------------------------- +message AuthorizeInteractionRequest { + string uri = 0x00000001; +} + +message AuthorizeInteractionResult { + string uri = 0x00000001; + bool success = 0x00000002; +} + //----------------------------------------------------------- diff --git a/greataped/components/api/services/authorize_interaction_service.go b/greataped/components/api/services/authorize_interaction_service.go new file mode 100644 index 0000000..c6ae113 --- /dev/null +++ b/greataped/components/api/services/authorize_interaction_service.go @@ -0,0 +1,30 @@ +package services + +import ( + . "github.com/xeronith/diamante/contracts/service" + . "rail.town/infrastructure/components/api/protobuf" + . "rail.town/infrastructure/components/contracts" + "rail.town/infrastructure/components/core" +) + +// noinspection GoUnusedParameter +func AuthorizeInteractionService(context IContext, input *AuthorizeInteractionRequest) (result *AuthorizeInteractionResult, err error) { + conductor := core.Conductor + _ = AUTHORIZE_INTERACTION_REQUEST + + conductor.LogRemoteCall(context, INITIALIZE, "authorize_interaction", input, result, err) + defer func() { conductor.LogRemoteCall(context, FINALIZE, "authorize_interaction", input, result, err) }() + + _result, _err := conductor.AuthorizeInteraction(input.Uri, context.Identity()) + if _err != nil { + err = _err + return nil, err + } + + _ = _result + + result = context.ResultContainer().(*AuthorizeInteractionResult) + result.Uri = _result.Uri() + result.Success = _result.Success() + return result, nil +} diff --git a/greataped/components/contracts/api.go b/greataped/components/contracts/api.go index cd94d10..77240d6 100644 --- a/greataped/components/contracts/api.go +++ b/greataped/components/contracts/api.go @@ -17,4 +17,5 @@ type IApi interface { Webfinger(*WebfingerRequest) (*WebfingerResult, error) GetActor(*GetActorRequest) (*GetActorResult, error) FollowActor(*FollowActorRequest) (*FollowActorResult, error) + AuthorizeInteraction(*AuthorizeInteractionRequest) (*AuthorizeInteractionResult, error) } diff --git a/greataped/components/contracts/opcodes.go b/greataped/components/contracts/opcodes.go index cac4d39..d8640a8 100644 --- a/greataped/components/contracts/opcodes.go +++ b/greataped/components/contracts/opcodes.go @@ -47,6 +47,10 @@ const ( //FollowActorOperation FOLLOW_ACTOR_REQUEST = 0xD30C2420 FOLLOW_ACTOR_RESULT = 0x30154D74 + + //AuthorizeInteractionOperation + AUTHORIZE_INTERACTION_REQUEST = 0x59EA7612 + AUTHORIZE_INTERACTION_RESULT = 0xB38E936F ) var OPCODES = Opcodes{ @@ -71,4 +75,6 @@ var OPCODES = Opcodes{ 0x136B82A8: "GetActor", 0xD30C2420: "FOLLOW_ACTOR", 0x30154D74: "FollowActor", + 0x59EA7612: "AUTHORIZE_INTERACTION", + 0xB38E936F: "AuthorizeInteraction", } diff --git a/greataped/components/contracts/spi.go b/greataped/components/contracts/spi.go index 4c872cd..fc34dd6 100644 --- a/greataped/components/contracts/spi.go +++ b/greataped/components/contracts/spi.go @@ -64,6 +64,7 @@ type ( Webfinger(resource string, editor Identity) (IWebfingerResult, error) GetActor(username string, editor Identity) (IGetActorResult, error) FollowActor(username string, acct string, editor Identity) (IFollowActorResult, error) + AuthorizeInteraction(uri string, editor Identity) (IAuthorizeInteractionResult, error) } IEchoResult interface { @@ -131,4 +132,9 @@ type ( IFollowActorResult interface { Url() string } + + IAuthorizeInteractionResult interface { + Uri() string + Success() bool + } ) diff --git a/greataped/components/contracts/system_component.go b/greataped/components/contracts/system_component.go index 6c40796..fdf0dbd 100644 --- a/greataped/components/contracts/system_component.go +++ b/greataped/components/contracts/system_component.go @@ -267,6 +267,7 @@ type ( Webfinger(resource string, editor Identity) (IWebfingerResult, error) GetActor(username string, editor Identity) (IGetActorResult, error) FollowActor(username string, acct string, editor Identity) (IFollowActorResult, error) + AuthorizeInteraction(uri string, editor Identity) (IAuthorizeInteractionResult, error) NewDocument(id int64, content string) (IDocument, error) NewSystemSchedule(id int64, enabled bool, config string) (ISystemSchedule, error) @@ -295,6 +296,7 @@ type ( NewWebfingerResult(aliases []string, links []IActivityPubLink, subject string, ignored interface{}) IWebfingerResult NewGetActorResult(context []string, id string, followers string, following string, inbox string, outbox string, name string, preferredUsername string, type_ string, url string, icon IActivityPubMedia, image IActivityPubMedia, publicKey IActivityPubPublicKey, summary string, published string, ignored interface{}) IGetActorResult NewFollowActorResult(url string, ignored interface{}) IFollowActorResult + NewAuthorizeInteractionResult(uri string, success bool, ignored interface{}) IAuthorizeInteractionResult } ISystemComponent interface { diff --git a/greataped/components/contracts/system_dispatcher.go b/greataped/components/contracts/system_dispatcher.go index 743be97..85f9765 100644 --- a/greataped/components/contracts/system_dispatcher.go +++ b/greataped/components/contracts/system_dispatcher.go @@ -1041,6 +1041,7 @@ type IDispatcher interface { Webfinger(resource string) (IWebfingerResult, error) GetActor(username string) (IGetActorResult, error) FollowActor(username string, acct string) (IFollowActorResult, error) + AuthorizeInteraction(uri string) (IAuthorizeInteractionResult, error) // NewDocument creates a new 'Document' instance using the provided property values. NewDocument(id int64, content string) (IDocument, error) @@ -1130,6 +1131,8 @@ type IDispatcher interface { NewGetActorResult(context []string, id string, followers string, following string, inbox string, outbox string, name string, preferredUsername string, type_ string, url string, icon IActivityPubMedia, image IActivityPubMedia, publicKey IActivityPubPublicKey, summary string, published string) IGetActorResult // NewFollowActorResult creates a new result container for 'Follow Actor' system action. NewFollowActorResult(url string) IFollowActorResult + // NewAuthorizeInteractionResult creates a new result container for 'Authorize Interaction' system action. + NewAuthorizeInteractionResult(uri string, success bool) IAuthorizeInteractionResult // Assert asserts the provided condition and panics if the assertion is not valid. Assert(condition bool) IAssertionResult // AssertNoError panics if the provided error is not nil. diff --git a/greataped/components/core/api_methods.go b/greataped/components/core/api_methods.go index 2fbfdd4..61104c0 100644 --- a/greataped/components/core/api_methods.go +++ b/greataped/components/core/api_methods.go @@ -115,6 +115,16 @@ func (api *api) FollowActor(request *FollowActorRequest) (*FollowActorResult, er } } +func (api *api) AuthorizeInteraction(request *AuthorizeInteractionRequest) (*AuthorizeInteractionResult, error) { + result, err := api.call(AUTHORIZE_INTERACTION_REQUEST, request) + + if err != nil { + return nil, err + } else { + return result.(*AuthorizeInteractionResult), nil + } +} + func init() { API_RESULT[SYSTEM_CALL_RESULT] = SystemCallResult{} API_RESULT[ECHO_RESULT] = EchoResult{} @@ -127,4 +137,5 @@ func init() { API_RESULT[WEBFINGER_RESULT] = WebfingerResult{} API_RESULT[GET_ACTOR_RESULT] = GetActorResult{} API_RESULT[FOLLOW_ACTOR_RESULT] = FollowActorResult{} + API_RESULT[AUTHORIZE_INTERACTION_RESULT] = AuthorizeInteractionResult{} } diff --git a/greataped/components/core/initializer.go b/greataped/components/core/initializer.go index 3653aac..be8f349 100644 --- a/greataped/components/core/initializer.go +++ b/greataped/components/core/initializer.go @@ -1135,6 +1135,10 @@ func (conductor *conductor) FollowActor(username string, acct string, editor Ide return conductor.spiManager.FollowActor(username, acct, editor) } +func (conductor *conductor) AuthorizeInteraction(uri string, editor Identity) (IAuthorizeInteractionResult, error) { + return conductor.spiManager.AuthorizeInteraction(uri, editor) +} + func (conductor *conductor) NewDocument(id int64, content string) (IDocument, error) { return NewDocument(id, content) } @@ -1243,6 +1247,10 @@ func (conductor *conductor) NewFollowActorResult(url string, _ interface{}) IFol return NewFollowActorResult(url, nil) } +func (conductor *conductor) NewAuthorizeInteractionResult(uri string, success bool, _ interface{}) IAuthorizeInteractionResult { + return NewAuthorizeInteractionResult(uri, success, nil) +} + func (conductor *conductor) LogRemoteCall(context IContext, eventType uint32, source string, input, result interface{}, err error) { errorMessage := "" if err != nil { diff --git a/greataped/components/core/spi.go b/greataped/components/core/spi.go index 8cd8f48..29eaa02 100644 --- a/greataped/components/core/spi.go +++ b/greataped/components/core/spi.go @@ -274,3 +274,7 @@ func (dispatcher *dispatcher) GetActor(username string) (IGetActorResult, error) func (dispatcher *dispatcher) FollowActor(username string, acct string) (IFollowActorResult, error) { return dispatcher.conductor.SpiManager().FollowActor(username, acct, dispatcher.identity) } + +func (dispatcher *dispatcher) AuthorizeInteraction(uri string) (IAuthorizeInteractionResult, error) { + return dispatcher.conductor.SpiManager().AuthorizeInteraction(uri, dispatcher.identity) +} diff --git a/greataped/components/core/spi_manager.go b/greataped/components/core/spi_manager.go index 4321de3..666fae2 100644 --- a/greataped/components/core/spi_manager.go +++ b/greataped/components/core/spi_manager.go @@ -738,3 +738,44 @@ func (manager *spiManager) FollowActor(username string, acct string, editor Iden return result, nil } } + +//region IAuthorizeInteractionResult Implementation + +type authorizeInteractionResult struct { + uri string + success bool +} + +func NewAuthorizeInteractionResult(uri string, success bool, _ interface{}) IAuthorizeInteractionResult { + return &authorizeInteractionResult{ + uri: uri, + success: success, + } +} + +func (result authorizeInteractionResult) Uri() string { + return result.uri +} + +func (result authorizeInteractionResult) Success() bool { + return result.success +} + +//endregion + +func (manager *spiManager) AuthorizeInteraction(uri string, editor Identity) (result IAuthorizeInteractionResult, err error) { + defer func() { + if reason := recover(); reason != nil { + err = manager.Error(reason) + } + }() + + editor.Lock(AUTHORIZE_INTERACTION_REQUEST) + defer editor.Unlock(AUTHORIZE_INTERACTION_REQUEST) + + if result, err = commands.AuthorizeInteraction(NewDispatcher(Conductor, editor), uri); err != nil { + return nil, err + } else { + return result, nil + } +} diff --git a/greataped/components/core/system_results.go b/greataped/components/core/system_results.go index 15cd1f1..b7a09c8 100644 --- a/greataped/components/core/system_results.go +++ b/greataped/components/core/system_results.go @@ -44,4 +44,8 @@ func (dispatcher *dispatcher) NewFollowActorResult(url string) IFollowActorResul return NewFollowActorResult(url, nil) } +func (dispatcher *dispatcher) NewAuthorizeInteractionResult(uri string, success bool) IAuthorizeInteractionResult { + return NewAuthorizeInteractionResult(uri, success, nil) +} + //endregion