project

package
v0.0.0-...-ec63eb9 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const ProjectCollection string = "projects"

Variables

View Source
var EKeyMetadataLength = status.Error(
	codes.InvalidArgument,
	"invalid length of project key metadata",
)

EKeyMetadataLength is a GRPC error that is returned when the length of the project key metadata does not match the expected length i.e. 1.

View Source
var EMetadataNotFound = status.Error(
	codes.Internal,
	"request metadata was not found",
)

EMetadataNotFound is a GRPC error that is returned when trying to authenticate a request using the project key and the required request metadata was not found.

View Source
var EProjectAddEnvironment = status.Error(
	codes.Internal,
	"could not create a new environment",
)

EProjectAddEnvironment is a GRPC error that is returned when an error occurs while updating the environments array for a project.

View Source
var EProjectAddFlag = status.Error(
	codes.Internal,
	"could not update project with the flag",
)

EProjectAddFlag is a GRPC error that is returned when an error occurs while updating the flags array for a project.

View Source
var EProjectAddFlagSetting = status.Error(
	codes.Internal,
	"error while updating project with flag settings",
)

EProjectAddFlagSetting is a GRPC error that is returned when an error occurs while updating the flag settings array of a project.

View Source
var EProjectFetch = status.Error(
	codes.Internal,
	"error occurred while fetching project",
)

EProjectFetch is a GRPC error that is returned when an unknown error occurs while fetching the project.

View Source
var EProjectKeyNotFound = status.Error(
	codes.Unauthenticated,
	"project key not found in request metadata",
)

EProjectKeyNotFound is a GRPC error that is returned when the project key was not found in the request metadata.

View Source
var EProjectNameTaken = status.Error(
	codes.AlreadyExists,
	"project already exists",
)

EProjectNameTaken is a GRPC error that is returned when attempting to save a new project and the project name is already taken.

View Source
var EProjectNotFound = status.Error(
	codes.NotFound,
	"no project was found with that name",
)

EProjectNotFound is a GRPC error that is returned when no projects were found.

View Source
var EProjectSave = status.Error(
	codes.Internal,
	"could not create a new project",
)

EProjectSave is a GRPC error that is returned when an unknown error occurs while saving the project.

Functions

func AuthoriseProject

func AuthoriseProject(ctx context.Context) (context.Context, error)

AuthoriseProject takes an incoming GRPC context and checks if the project token is present in the incoming context. If the project token exists, it adds the token to the returned context. All errors returned by this function are GRPC compliant.

func NewProjectRepository

func NewProjectRepository(
	ctx context.Context,
	db *mongo.Database,
) (*projectRepository, error)

func ProjectKeyFromContext

func ProjectKeyFromContext(ctx context.Context) (string, bool)

ProjectKeyFromContext returns the project key from the provided context if it is available.

func ProjectKeyUnaryInterceptor

func ProjectKeyUnaryInterceptor(serverPath string) grpc.UnaryServerInterceptor

ProjectKeyUnaryInterceptor intercepts an incoming request to the provided server path and ensures that the request contains the project key in the metadata.

Types

type Project

type Project struct {
	ID           primitive.ObjectID   `bson:"_id,omitempty"`
	Key          string               `bson:"key"`
	Name         string               `bson:"name"`
	Environments []primitive.ObjectID `bson:"environments,omitempty"`
	Flags        []primitive.ObjectID `bson:"flags,omitempty"`
	FlagSettings []primitive.ObjectID `bson:"flag_settings,omitempty"`
	CreatedBy    primitive.ObjectID   `bson:"created_by"`
	CreatedAt    time.Time            `bson:"created_at"`
	UpdatedAt    time.Time            `bson:"updated_at"`
}

type ProjectRepository

type ProjectRepository interface {
	// Creates a new `Project` document
	Save(ctx context.Context, project *Project) (*mongo.InsertOneResult, error)

	// Gets the project by the name and the ID of the user that created the
	// project.
	GetByNameAndUserID(
		ctx context.Context,
		projectName string,
		userID primitive.ObjectID,
	) (*Project, error)

	// Adds a new environment to the project by the project name and the user
	// ID.
	AddEnvironment(
		ctx context.Context,
		projectID primitive.ObjectID,
		environmentID primitive.ObjectID,
	) (*mongo.UpdateResult, error)

	// Adds a new flag to the project by the project name.
	AddFlag(
		ctx context.Context,
		projectID primitive.ObjectID,
		flagID primitive.ObjectID,
	) (*mongo.UpdateResult, error)

	// AddFlagSettings adds new flag settings to the project.
	AddFlagSettings(
		ctx context.Context,
		projectID primitive.ObjectID,
		flagSettingIDs ...primitive.ObjectID,
	) (*mongo.UpdateResult, error)
}

ProjectRepository is an interface to the operations that can be performed on the projects collection.

type ProjectServer

type ProjectServer struct {
	projectpb.UnimplementedProjectServer
	// contains filtered or unexported fields
}

func NewProjectServer

func NewProjectServer(
	projectRepo ProjectRepository,
	userRepo user.UserRepository,
) *ProjectServer

NewProjectServer creates a new server for the project service.

func (*ProjectServer) CreateNewProject

func (*ProjectServer) GetProjectKey

Jump to

Keyboard shortcuts

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