Documentation ¶
Index ¶
- Constants
- Variables
- func AuthoriseProject(ctx context.Context) (context.Context, error)
- func NewProjectRepository(ctx context.Context, db *mongo.Database) (*projectRepository, error)
- func ProjectKeyFromContext(ctx context.Context) (string, bool)
- func ProjectKeyUnaryInterceptor(serverPath string) grpc.UnaryServerInterceptor
- type Project
- type ProjectRepository
- type ProjectServer
Constants ¶
const ProjectCollection string = "projects"
Variables ¶
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.
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.
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.
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.
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.
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.
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.
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.
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.
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 ¶
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 ProjectKeyFromContext ¶
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 (p *ProjectServer) CreateNewProject( ctx context.Context, req *projectpb.CreateNewProjectRequest, ) (*projectpb.CreateNewProjectResponse, error)
func (*ProjectServer) GetProjectKey ¶
func (p *ProjectServer) GetProjectKey( ctx context.Context, req *projectpb.GetProjectKeyRequest, ) (*projectpb.GetProjectKeyResponse, error)