kopia lustrzana https://github.com/reiver/greatape
				
				
				
			feat(components): ✨ interaction authorization
							rodzic
							
								
									dbb041ee96
								
							
						
					
					
						commit
						60b372b0fa
					
				| 
						 | 
				
			
			@ -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,
 | 
			
		||||
		)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -16,6 +16,7 @@ func (factory *httpHandlerFactory) Handlers() []IHttpHandler {
 | 
			
		|||
		WebfingerHandler(),            // │ G . /.well-known/webfinger
 | 
			
		||||
		GetActorHandler(),             // │ G . /u/:username
 | 
			
		||||
		FollowActorHandler(),          // │ G . /u/:username/follow
 | 
			
		||||
		AuthorizeInteractionHandler(), // │ G . /authorize_interaction
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
}
 | 
			
		||||
*/
 | 
			
		||||
| 
						 | 
				
			
			@ -17,6 +17,7 @@ func (factory *operationFactory) Operations() []IOperation {
 | 
			
		|||
		WebfingerOperation(),
 | 
			
		||||
		GetActorOperation(),
 | 
			
		||||
		FollowActorOperation(),
 | 
			
		||||
		AuthorizeInteractionOperation(),
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,7 +1592,7 @@ 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
 | 
			
		||||
| 
						 | 
				
			
			@ -1504,18 +1616,20 @@ var file_spis_proto_goTypes = []interface{}{
 | 
			
		|||
	(*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
 | 
			
		||||
	(*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,
 | 
			
		||||
		},
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -149,4 +149,15 @@ message FollowActorResult {
 | 
			
		|||
    string url = 0x00000001;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// API: AuthorizeInteraction
 | 
			
		||||
//-----------------------------------------------------------
 | 
			
		||||
message AuthorizeInteractionRequest {
 | 
			
		||||
    string uri = 0x00000001;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
message AuthorizeInteractionResult {
 | 
			
		||||
    string uri = 0x00000001;
 | 
			
		||||
    bool success = 0x00000002;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//-----------------------------------------------------------
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -17,4 +17,5 @@ type IApi interface {
 | 
			
		|||
	Webfinger(*WebfingerRequest) (*WebfingerResult, error)
 | 
			
		||||
	GetActor(*GetActorRequest) (*GetActorResult, error)
 | 
			
		||||
	FollowActor(*FollowActorRequest) (*FollowActorResult, error)
 | 
			
		||||
	AuthorizeInteraction(*AuthorizeInteractionRequest) (*AuthorizeInteractionResult, error)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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",
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
	}
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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{}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue