instance

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2025 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package instance is a reverse proxy.

It translates gRPC into RESTful JSON APIs.

Index

Constants

View Source
const (
	InstanceManager_CreateInstance_FullMethodName   = "/api.v1.instance.InstanceManager/CreateInstance"
	InstanceManager_RetrieveInstance_FullMethodName = "/api.v1.instance.InstanceManager/RetrieveInstance"
	InstanceManager_QueryInstance_FullMethodName    = "/api.v1.instance.InstanceManager/QueryInstance"
	InstanceManager_RenewInstance_FullMethodName    = "/api.v1.instance.InstanceManager/RenewInstance"
	InstanceManager_DeleteInstance_FullMethodName   = "/api.v1.instance.InstanceManager/DeleteInstance"
)

Variables

View Source
var File_api_v1_instance_instance_proto protoreflect.FileDescriptor
View Source
var InstanceManager_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "api.v1.instance.InstanceManager",
	HandlerType: (*InstanceManagerServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "CreateInstance",
			Handler:    _InstanceManager_CreateInstance_Handler,
		},
		{
			MethodName: "RetrieveInstance",
			Handler:    _InstanceManager_RetrieveInstance_Handler,
		},
		{
			MethodName: "RenewInstance",
			Handler:    _InstanceManager_RenewInstance_Handler,
		},
		{
			MethodName: "DeleteInstance",
			Handler:    _InstanceManager_DeleteInstance_Handler,
		},
	},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    "QueryInstance",
			Handler:       _InstanceManager_QueryInstance_Handler,
			ServerStreams: true,
		},
	},
	Metadata: "api/v1/instance/instance.proto",
}

InstanceManager_ServiceDesc is the grpc.ServiceDesc for InstanceManager service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func RegisterInstanceManagerHandler

func RegisterInstanceManagerHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error

RegisterInstanceManagerHandler registers the http handlers for service InstanceManager to "mux". The handlers forward requests to the grpc endpoint over "conn".

func RegisterInstanceManagerHandlerClient

func RegisterInstanceManagerHandlerClient(ctx context.Context, mux *runtime.ServeMux, client InstanceManagerClient) error

RegisterInstanceManagerHandlerClient registers the http handlers for service InstanceManager to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "InstanceManagerClient". Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "InstanceManagerClient" doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in "InstanceManagerClient" to call the correct interceptors. This client ignores the HTTP middlewares.

func RegisterInstanceManagerHandlerFromEndpoint

func RegisterInstanceManagerHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)

RegisterInstanceManagerHandlerFromEndpoint is same as RegisterInstanceManagerHandler but automatically dials to "endpoint" and closes the connection when "ctx" gets done.

func RegisterInstanceManagerHandlerServer

func RegisterInstanceManagerHandlerServer(ctx context.Context, mux *runtime.ServeMux, server InstanceManagerServer) error

RegisterInstanceManagerHandlerServer registers the http handlers for service InstanceManager to "mux". UnaryRPC :call InstanceManagerServer directly. StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterInstanceManagerHandlerFromEndpoint instead. GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call.

func RegisterInstanceManagerServer

func RegisterInstanceManagerServer(s grpc.ServiceRegistrar, srv InstanceManagerServer)

Types

type CreateInstanceRequest

type CreateInstanceRequest struct {

	// The challenge identifier
	ChallengeId string `protobuf:"bytes,1,opt,name=challenge_id,json=challengeId,proto3" json:"challenge_id,omitempty"`
	// The source (user/team) identifier.
	SourceId string `protobuf:"bytes,2,opt,name=source_id,json=sourceId,proto3" json:"source_id,omitempty"`
	// A key=value configuration to pass to the instance when created.
	Config map[string]string `` /* 139-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*CreateInstanceRequest) Descriptor deprecated

func (*CreateInstanceRequest) Descriptor() ([]byte, []int)

Deprecated: Use CreateInstanceRequest.ProtoReflect.Descriptor instead.

func (*CreateInstanceRequest) GetChallengeId

func (x *CreateInstanceRequest) GetChallengeId() string

func (*CreateInstanceRequest) GetConfig added in v0.3.0

func (x *CreateInstanceRequest) GetConfig() map[string]string

func (*CreateInstanceRequest) GetSourceId

func (x *CreateInstanceRequest) GetSourceId() string

func (*CreateInstanceRequest) ProtoMessage

func (*CreateInstanceRequest) ProtoMessage()

func (*CreateInstanceRequest) ProtoReflect

func (x *CreateInstanceRequest) ProtoReflect() protoreflect.Message

func (*CreateInstanceRequest) Reset

func (x *CreateInstanceRequest) Reset()

func (*CreateInstanceRequest) String

func (x *CreateInstanceRequest) String() string

type DeleteInstanceRequest

type DeleteInstanceRequest struct {

	// The challenge identifier
	ChallengeId string `protobuf:"bytes,1,opt,name=challenge_id,json=challengeId,proto3" json:"challenge_id,omitempty"`
	// The source (user/team) identifier.
	SourceId string `protobuf:"bytes,2,opt,name=source_id,json=sourceId,proto3" json:"source_id,omitempty"`
	// contains filtered or unexported fields
}

func (*DeleteInstanceRequest) Descriptor deprecated

func (*DeleteInstanceRequest) Descriptor() ([]byte, []int)

Deprecated: Use DeleteInstanceRequest.ProtoReflect.Descriptor instead.

func (*DeleteInstanceRequest) GetChallengeId

func (x *DeleteInstanceRequest) GetChallengeId() string

func (*DeleteInstanceRequest) GetSourceId

func (x *DeleteInstanceRequest) GetSourceId() string

func (*DeleteInstanceRequest) ProtoMessage

func (*DeleteInstanceRequest) ProtoMessage()

func (*DeleteInstanceRequest) ProtoReflect

func (x *DeleteInstanceRequest) ProtoReflect() protoreflect.Message

func (*DeleteInstanceRequest) Reset

func (x *DeleteInstanceRequest) Reset()

func (*DeleteInstanceRequest) String

func (x *DeleteInstanceRequest) String() string

type Instance

type Instance struct {

	// The challenge identifier
	ChallengeId string `protobuf:"bytes,1,opt,name=challenge_id,json=challengeId,proto3" json:"challenge_id,omitempty"`
	// The source (user/team) identifier.
	SourceId string `protobuf:"bytes,2,opt,name=source_id,json=sourceId,proto3" json:"source_id,omitempty"`
	// The time since when the instance is running.
	Since *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=since,proto3" json:"since,omitempty"`
	// The last time the instance has been renewed.
	LastRenew *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=last_renew,json=lastRenew,proto3" json:"last_renew,omitempty"`
	// The time the instance will "die" i.e. be destroyed by the janitor.
	Until *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=until,proto3,oneof" json:"until,omitempty"`
	// The connection information that is given to the players in order
	// to reach their instance.
	ConnectionInfo string `protobuf:"bytes,6,opt,name=connection_info,json=connectionInfo,proto3" json:"connection_info,omitempty"`
	// If specified, the flag that validates the challenge instance.
	// This avoids shareflag, but don't block sharing solving strategy/write-up.
	Flag *string `protobuf:"bytes,7,opt,name=flag,proto3,oneof" json:"flag,omitempty"`
	// A key=value configuration to pass to the instance when created.
	Config map[string]string `` /* 139-byte string literal not displayed */
	// contains filtered or unexported fields
}

The challenge instance object that the chall-manager exposes. Notice it differs from the internal representation, as it handles filesystem-related information.

func (*Instance) Descriptor deprecated

func (*Instance) Descriptor() ([]byte, []int)

Deprecated: Use Instance.ProtoReflect.Descriptor instead.

func (*Instance) GetChallengeId

func (x *Instance) GetChallengeId() string

func (*Instance) GetConfig added in v0.3.0

func (x *Instance) GetConfig() map[string]string

func (*Instance) GetConnectionInfo

func (x *Instance) GetConnectionInfo() string

func (*Instance) GetFlag

func (x *Instance) GetFlag() string

func (*Instance) GetLastRenew

func (x *Instance) GetLastRenew() *timestamppb.Timestamp

func (*Instance) GetSince

func (x *Instance) GetSince() *timestamppb.Timestamp

func (*Instance) GetSourceId

func (x *Instance) GetSourceId() string

func (*Instance) GetUntil

func (x *Instance) GetUntil() *timestamppb.Timestamp

func (*Instance) ProtoMessage

func (*Instance) ProtoMessage()

func (*Instance) ProtoReflect

func (x *Instance) ProtoReflect() protoreflect.Message

func (*Instance) Reset

func (x *Instance) Reset()

func (*Instance) String

func (x *Instance) String() string

type InstanceManagerClient

type InstanceManagerClient interface {
	// Spins up a challenge instance, iif the challenge is registered
	// and no instance is yet running.
	CreateInstance(ctx context.Context, in *CreateInstanceRequest, opts ...grpc.CallOption) (*Instance, error)
	// Once created, you can retrieve the instance information.
	// If it has not been created yet, returns an error.
	RetrieveInstance(ctx context.Context, in *RetrieveInstanceRequest, opts ...grpc.CallOption) (*Instance, error)
	// Query all instances that matches the request parameters.
	// Especially usefull to query all the instances of a source_id.
	QueryInstance(ctx context.Context, in *QueryInstanceRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[Instance], error)
	// Once an instance is spinned up, it will have a lifetime.
	// Passed it, it will exprie i.e. will be deleted as soon as possible
	// by the chall-manager-janitor.
	// To increase this lifetime, a player can ask to renew it. This will
	// set the until date to the request time more the challenge timeout.
	RenewInstance(ctx context.Context, in *RenewInstanceRequest, opts ...grpc.CallOption) (*Instance, error)
	// After completion, the challenge instance is no longer required.
	// This spins down the instance and removes if from filesystem.
	DeleteInstance(ctx context.Context, in *DeleteInstanceRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
}

InstanceManagerClient is the client API for InstanceManager service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

The InstanceManager handles the charge of spinning up challenge instances (require it to be stored in the ChallengeStore). Through this manager, the instance implements all CRUD operations necessary to handle a lifecycle.

type InstanceManagerServer

type InstanceManagerServer interface {
	// Spins up a challenge instance, iif the challenge is registered
	// and no instance is yet running.
	CreateInstance(context.Context, *CreateInstanceRequest) (*Instance, error)
	// Once created, you can retrieve the instance information.
	// If it has not been created yet, returns an error.
	RetrieveInstance(context.Context, *RetrieveInstanceRequest) (*Instance, error)
	// Query all instances that matches the request parameters.
	// Especially usefull to query all the instances of a source_id.
	QueryInstance(*QueryInstanceRequest, grpc.ServerStreamingServer[Instance]) error
	// Once an instance is spinned up, it will have a lifetime.
	// Passed it, it will exprie i.e. will be deleted as soon as possible
	// by the chall-manager-janitor.
	// To increase this lifetime, a player can ask to renew it. This will
	// set the until date to the request time more the challenge timeout.
	RenewInstance(context.Context, *RenewInstanceRequest) (*Instance, error)
	// After completion, the challenge instance is no longer required.
	// This spins down the instance and removes if from filesystem.
	DeleteInstance(context.Context, *DeleteInstanceRequest) (*emptypb.Empty, error)
	// contains filtered or unexported methods
}

InstanceManagerServer is the server API for InstanceManager service. All implementations must embed UnimplementedInstanceManagerServer for forward compatibility.

The InstanceManager handles the charge of spinning up challenge instances (require it to be stored in the ChallengeStore). Through this manager, the instance implements all CRUD operations necessary to handle a lifecycle.

type InstanceManager_QueryInstanceClient

type InstanceManager_QueryInstanceClient = grpc.ServerStreamingClient[Instance]

This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.

type InstanceManager_QueryInstanceServer

type InstanceManager_QueryInstanceServer = grpc.ServerStreamingServer[Instance]

This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.

type Manager

type Manager struct {
	UnimplementedInstanceManagerServer
}

func NewManager

func NewManager() *Manager

func (*Manager) CreateInstance

func (man *Manager) CreateInstance(ctx context.Context, req *CreateInstanceRequest) (*Instance, error)

func (*Manager) DeleteInstance

func (man *Manager) DeleteInstance(ctx context.Context, req *DeleteInstanceRequest) (*emptypb.Empty, error)

func (*Manager) QueryInstance

func (man *Manager) QueryInstance(req *QueryInstanceRequest, server InstanceManager_QueryInstanceServer) error

func (*Manager) RenewInstance

func (man *Manager) RenewInstance(ctx context.Context, req *RenewInstanceRequest) (*Instance, error)

func (*Manager) RetrieveInstance

func (man *Manager) RetrieveInstance(ctx context.Context, req *RetrieveInstanceRequest) (*Instance, error)

type QueryInstanceRequest

type QueryInstanceRequest struct {

	// The source (user/team) identifier.
	SourceId string `protobuf:"bytes,1,opt,name=source_id,json=sourceId,proto3" json:"source_id,omitempty"`
	// contains filtered or unexported fields
}

func (*QueryInstanceRequest) Descriptor deprecated

func (*QueryInstanceRequest) Descriptor() ([]byte, []int)

Deprecated: Use QueryInstanceRequest.ProtoReflect.Descriptor instead.

func (*QueryInstanceRequest) GetSourceId

func (x *QueryInstanceRequest) GetSourceId() string

func (*QueryInstanceRequest) ProtoMessage

func (*QueryInstanceRequest) ProtoMessage()

func (*QueryInstanceRequest) ProtoReflect

func (x *QueryInstanceRequest) ProtoReflect() protoreflect.Message

func (*QueryInstanceRequest) Reset

func (x *QueryInstanceRequest) Reset()

func (*QueryInstanceRequest) String

func (x *QueryInstanceRequest) String() string

type RenewInstanceRequest

type RenewInstanceRequest struct {

	// The challenge identifier
	ChallengeId string `protobuf:"bytes,1,opt,name=challenge_id,json=challengeId,proto3" json:"challenge_id,omitempty"`
	// The source (user/team) identifier.
	SourceId string `protobuf:"bytes,2,opt,name=source_id,json=sourceId,proto3" json:"source_id,omitempty"`
	// contains filtered or unexported fields
}

func (*RenewInstanceRequest) Descriptor deprecated

func (*RenewInstanceRequest) Descriptor() ([]byte, []int)

Deprecated: Use RenewInstanceRequest.ProtoReflect.Descriptor instead.

func (*RenewInstanceRequest) GetChallengeId

func (x *RenewInstanceRequest) GetChallengeId() string

func (*RenewInstanceRequest) GetSourceId

func (x *RenewInstanceRequest) GetSourceId() string

func (*RenewInstanceRequest) ProtoMessage

func (*RenewInstanceRequest) ProtoMessage()

func (*RenewInstanceRequest) ProtoReflect

func (x *RenewInstanceRequest) ProtoReflect() protoreflect.Message

func (*RenewInstanceRequest) Reset

func (x *RenewInstanceRequest) Reset()

func (*RenewInstanceRequest) String

func (x *RenewInstanceRequest) String() string

type RetrieveInstanceRequest

type RetrieveInstanceRequest struct {

	// The challenge identifier
	ChallengeId string `protobuf:"bytes,1,opt,name=challenge_id,json=challengeId,proto3" json:"challenge_id,omitempty"`
	// The source (user/team) identifier.
	SourceId string `protobuf:"bytes,2,opt,name=source_id,json=sourceId,proto3" json:"source_id,omitempty"`
	// contains filtered or unexported fields
}

func (*RetrieveInstanceRequest) Descriptor deprecated

func (*RetrieveInstanceRequest) Descriptor() ([]byte, []int)

Deprecated: Use RetrieveInstanceRequest.ProtoReflect.Descriptor instead.

func (*RetrieveInstanceRequest) GetChallengeId

func (x *RetrieveInstanceRequest) GetChallengeId() string

func (*RetrieveInstanceRequest) GetSourceId

func (x *RetrieveInstanceRequest) GetSourceId() string

func (*RetrieveInstanceRequest) ProtoMessage

func (*RetrieveInstanceRequest) ProtoMessage()

func (*RetrieveInstanceRequest) ProtoReflect

func (x *RetrieveInstanceRequest) ProtoReflect() protoreflect.Message

func (*RetrieveInstanceRequest) Reset

func (x *RetrieveInstanceRequest) Reset()

func (*RetrieveInstanceRequest) String

func (x *RetrieveInstanceRequest) String() string

type UnimplementedInstanceManagerServer

type UnimplementedInstanceManagerServer struct{}

UnimplementedInstanceManagerServer must be embedded to have forward compatible implementations.

NOTE: this should be embedded by value instead of pointer to avoid a nil pointer dereference when methods are called.

func (UnimplementedInstanceManagerServer) CreateInstance

func (UnimplementedInstanceManagerServer) DeleteInstance

func (UnimplementedInstanceManagerServer) QueryInstance

func (UnimplementedInstanceManagerServer) RenewInstance

func (UnimplementedInstanceManagerServer) RetrieveInstance

type UnsafeInstanceManagerServer

type UnsafeInstanceManagerServer interface {
	// contains filtered or unexported methods
}

UnsafeInstanceManagerServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to InstanceManagerServer will result in compilation errors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL