project

package
v0.0.0-...-0874bd6 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ProjectCollection string = "projects"

Variables

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

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

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

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

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

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

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

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

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

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

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

ErrKeyMetadataLength 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 ErrMetadataNotFound = status.Error(
	codes.Internal,
	"request metadata was not found",
)

ErrMetadataNotFound 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 ErrNameTaken = status.Error(
	codes.AlreadyExists,
	"project already exists",
)

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

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

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

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

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

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 KeyFromContext

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

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

func KeyUnaryInterceptor

func KeyUnaryInterceptor(serverPath string) grpc.UnaryServerInterceptor

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

Types

type DataRepository

type DataRepository 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)
}

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

type MongoDataRepository

type MongoDataRepository struct {
	// contains filtered or unexported fields
}

func NewProjectRepository

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

func (*MongoDataRepository) AddEnvironment

func (p *MongoDataRepository) AddEnvironment(
	ctx context.Context,
	projectID primitive.ObjectID,
	environmentID primitive.ObjectID,
) (*mongo.UpdateResult, error)

func (*MongoDataRepository) AddFlag

func (p *MongoDataRepository) AddFlag(
	ctx context.Context,
	projectID primitive.ObjectID,
	flagID primitive.ObjectID,
) (*mongo.UpdateResult, error)

func (*MongoDataRepository) AddFlagSettings

func (p *MongoDataRepository) AddFlagSettings(
	ctx context.Context,
	projectID primitive.ObjectID,
	flagSettingIDs ...primitive.ObjectID,
) (*mongo.UpdateResult, error)

func (*MongoDataRepository) GetByNameAndUserID

func (p *MongoDataRepository) GetByNameAndUserID(
	ctx context.Context,
	projectName string,
	userID primitive.ObjectID,
) (*Project, error)

func (*MongoDataRepository) Save

func (p *MongoDataRepository) Save(
	ctx context.Context,
	project *Project,
) (*mongo.InsertOneResult, error)

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 Server

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

func NewProjectServer

func NewProjectServer(
	projectDataRepo DataRepository,
	userDataRepo user.DataRepository,
) *Server

NewProjectServer creates a new server for the project service.

func (*Server) GetProjectKey

Jump to

Keyboard shortcuts

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