Documentation ¶
Index ¶
- Constants
- Variables
- func AuthoriseProject(ctx context.Context) (context.Context, error)
- func KeyFromContext(ctx context.Context) (string, bool)
- func KeyUnaryInterceptor(serverPath string) grpc.UnaryServerInterceptor
- type DataRepository
- type MongoDataRepository
- func (p *MongoDataRepository) AddEnvironment(ctx context.Context, projectID primitive.ObjectID, ...) (*mongo.UpdateResult, error)
- func (p *MongoDataRepository) AddFlag(ctx context.Context, projectID primitive.ObjectID, flagID primitive.ObjectID) (*mongo.UpdateResult, error)
- func (p *MongoDataRepository) AddFlagSettings(ctx context.Context, projectID primitive.ObjectID, ...) (*mongo.UpdateResult, error)
- func (p *MongoDataRepository) GetByNameAndUserID(ctx context.Context, projectName string, userID primitive.ObjectID) (*Project, error)
- func (p *MongoDataRepository) Save(ctx context.Context, project *Project) (*mongo.InsertOneResult, error)
- type Project
- type Server
Constants ¶
const ProjectCollection string = "projects"
Variables ¶
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.
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.
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.
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.
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.
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.
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.
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.
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.
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 ¶
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 ¶
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 (*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 (*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) CreateNewProject ¶
func (p *Server) CreateNewProject( ctx context.Context, req *projectpb.CreateNewProjectRequest, ) (*projectpb.CreateNewProjectResponse, error)
func (*Server) GetProjectKey ¶
func (p *Server) GetProjectKey( ctx context.Context, req *projectpb.GetProjectKeyRequest, ) (*projectpb.GetProjectKeyResponse, error)