controlplane

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: Apache-2.0 Imports: 66 Imported by: 0

Documentation

Overview

Package controlplane contains the gRPC server implementation for the control plane

Package controlplane contains the control plane API for the mediator.

Index

Constants

View Source
const PaginationLimit = 10

PaginationLimit is the maximum number of items that can be returned in a single page

Variables

View Source
var CONTAINER_TYPE = "container"

CONTAINER_TYPE is the type for container artifacts

View Source
var ErrArtifactNotFound = errors.New("artifact not found")

ErrArtifactNotFound is returned when an artifact is not found

View Source
var ErrRepoNotFound = errors.New("repository not found")

ErrRepoNotFound is returned when a repository is not found

Functions

func AuthUnaryInterceptor

func AuthUnaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler) (any, error)

AuthUnaryInterceptor is a server interceptor for authentication

func AuthorizedOnOrg added in v0.0.4

func AuthorizedOnOrg(ctx context.Context, orgId uuid.UUID) error

AuthorizedOnOrg checks if the request is authorized for the given organization, and returns an error if the request is not authorized.

func AuthorizedOnProject added in v0.0.5

func AuthorizedOnProject(ctx context.Context, projectID uuid.UUID) error

AuthorizedOnProject checks if the request is authorized for the given group, and returns an error if the request is not authorized.

func AuthorizedOnUser added in v0.0.4

func AuthorizedOnUser(ctx context.Context, userId int32) error

AuthorizedOnUser checks if the request is authorized for the given user, and returns an error if the request is not authorized.

func CreateDefaultRecordsForOrg added in v0.0.5

func CreateDefaultRecordsForOrg(ctx context.Context, qtx db.Querier,
	org db.Project, projectName string) (*pb.ProjectRecord, []*pb.RoleRecord, error)

CreateDefaultRecordsForOrg creates the default records, such as projects, roles and provider for the organization

func RegisterGRPCServices

func RegisterGRPCServices(s *Server)

RegisterGRPCServices registers the GRPC services

func RegisterGatewayHTTPHandlers

func RegisterGatewayHTTPHandlers(ctx context.Context, gwmux *runtime.ServeMux, grpcAddress string, opts []grpc.DialOption)

RegisterGatewayHTTPHandlers registers the gateway HTTP handlers

Types

type CreateRoleValidation

type CreateRoleValidation struct {
	Name string `db:"name" validate:"required"`
}

CreateRoleValidation is a struct for validating the CreateRole request

type OrgMeta added in v0.0.5

type OrgMeta struct {
	Company string `json:"company"`
}

OrgMeta is the metadata associated with an organization

type ProjectIDGetter added in v0.0.5

type ProjectIDGetter interface {
	// GetProjectId returns the project ID
	GetProjectId() string
}

ProjectIDGetter is an interface that can be implemented by a request

type ProjectMeta added in v0.0.5

type ProjectMeta struct {
	Description string `json:"description"`
	IsProtected bool   `json:"is_protected"`
}

ProjectMeta is the metadata associated with a project

type RegistrationStatus

type RegistrationStatus struct {
	Success bool
	Error   error
}

RegistrationStatus gathers the status of the webhook call for each repository

type Repository

type Repository struct {
	Owner  string
	Repo   string
	RepoID int32
}

Repository represents a GitHub repository

type RepositoryResult

type RepositoryResult struct {
	Owner      string
	Repository string
	RepoID     int32
	HookID     int64
	HookURL    string
	DeployURL  string
	CreatedAt  time.Time
	UpdatedAt  time.Time
	HookName   string
	HookType   string
	HookUUID   string
	RegistrationStatus
}

RepositoryResult represents the result of the webhook registration

func RegisterWebHook

func RegisterWebHook(
	ctx context.Context,
	token oauth2.Token,
	repositories []Repository,
	events []string,
) ([]RepositoryResult, error)

RegisterWebHook registers a webhook for the given repositories and events and returns the registration result for each repository. If an error occurs, the registration is aborted and the error is returned. https://docs.github.com/en/rest/reference/repos#create-a-repository-webhook

type Server

Server represents the controlplane server

func NewServer

func NewServer(store db.Store, evt *events.Eventer, cfg *config.Config, vldtr auth.JwtValidator) (*Server, error)

NewServer creates a new server instance

func (*Server) CheckHealth

CheckHealth is a simple health check for monitoring The lintcheck is disabled because the unused-receiver is required by the implementation. UnimplementedHealthServiceServer is initialized within the Server struct

func (*Server) ConsumeEvents

func (s *Server) ConsumeEvents(c ...events.Consumer)

ConsumeEvents implements events.Registrar

func (*Server) CreateKeyPair

func (s *Server) CreateKeyPair(ctx context.Context, req *pb.CreateKeyPairRequest) (*pb.CreateKeyPairResponse, error)

CreateKeyPair creates a new key pair for a given group

func (*Server) CreateOrganization

CreateOrganization is a service for creating an organization nolint:gocyclo // we should reactor this later.

func (*Server) CreateProfile added in v0.0.6

CreateProfile creates a profile for a group nolint: gocyclo

func (*Server) CreateProject added in v0.0.5

func (s *Server) CreateProject(ctx context.Context, req *pb.CreateProjectRequest) (*pb.CreateProjectResponse, error)

CreateProject creates a project

func (*Server) CreateRoleByOrganization

CreateRoleByOrganization is a service for creating a role for an organization

func (*Server) CreateRoleByProject added in v0.0.5

CreateRoleByProject is a service for creating a role for a project

func (*Server) CreateRuleType

CreateRuleType is a method to create a rule type

func (*Server) CreateUser

func (s *Server) CreateUser(ctx context.Context,
	_ *pb.CreateUserRequest) (*pb.CreateUserResponse, error)

CreateUser is a service for user self registration

func (*Server) DeleteOrganization

DeleteOrganization is a handler that deletes a organization

func (*Server) DeleteProfile added in v0.0.6

DeleteProfile is a method to delete a profile

func (*Server) DeleteProject added in v0.0.5

func (s *Server) DeleteProject(ctx context.Context,
	in *pb.DeleteProjectRequest) (*pb.DeleteProjectResponse, error)

DeleteProject is a handler that deletes a project

func (*Server) DeleteRole

func (s *Server) DeleteRole(ctx context.Context,
	in *pb.DeleteRoleRequest) (*pb.DeleteRoleResponse, error)

DeleteRole is a service for deleting a role

func (*Server) DeleteRuleType

DeleteRuleType is a method to delete a rule type

func (*Server) DeleteUser

func (s *Server) DeleteUser(ctx context.Context,
	in *pb.DeleteUserRequest) (*pb.DeleteUserResponse, error)

DeleteUser is a service for deleting an user

func (*Server) ExchangeCodeForTokenCLI

func (s *Server) ExchangeCodeForTokenCLI(ctx context.Context,
	in *pb.ExchangeCodeForTokenCLIRequest) (*httpbody.HttpBody, error)

ExchangeCodeForTokenCLI exchanges an OAuth2 code for a token This function gathers the state from the database and compares it to the state passed in. If they match, the code is exchanged for a token. This function is used by the CLI client.

func (*Server) ExchangeCodeForTokenWEB

ExchangeCodeForTokenWEB exchanges an OAuth2 code for a token and returns a JWT token as a session cookie. This handler is specific for web clients. The lint check for this function is disabled because it's a false positive. It will complain about am unsused receiver (s *Server), however this receiver will be used later when we implement the database store.

func (*Server) GetArtifactById

GetArtifactById gets an artifact by id nolint:gocyclo

func (*Server) GetAuthorizationURL

GetAuthorizationURL returns the URL to redirect the user to for authorization and the state to be used for the callback. It accepts a provider string and a boolean indicating whether the client is a CLI or web client

func (*Server) GetOrganization

GetOrganization is a service for getting an organization

func (*Server) GetOrganizationByName

GetOrganizationByName is a service for getting an organization

func (*Server) GetOrganizations

GetOrganizations is a service for getting a list of organizations

func (*Server) GetProfileById added in v0.0.6

GetProfileById is a method to get a profile by id

func (*Server) GetProfileStatusByName added in v0.0.6

GetProfileStatusByName is a method to get profile status nolint:gocyclo // TODO: Refactor this to be more readable

func (*Server) GetProfileStatusByProject added in v0.0.6

GetProfileStatusByProject is a method to get profile status for a group

func (*Server) GetProjectById added in v0.0.5

func (s *Server) GetProjectById(ctx context.Context, req *pb.GetProjectByIdRequest) (*pb.GetProjectByIdResponse, error)

GetProjectById returns a project by id

func (*Server) GetProjectByName added in v0.0.5

func (s *Server) GetProjectByName(ctx context.Context, req *pb.GetProjectByNameRequest) (*pb.GetProjectByNameResponse, error)

GetProjectByName returns a projects by name

func (*Server) GetProjects added in v0.0.5

func (s *Server) GetProjects(ctx context.Context, req *pb.GetProjectsRequest) (*pb.GetProjectsResponse, error)

GetProjects returns a list of projects

func (*Server) GetProviderAccessToken

func (s *Server) GetProviderAccessToken(ctx context.Context, provider string,
	projectID uuid.UUID, checkAuthz bool) (oauth2.Token, string, error)

GetProviderAccessToken returns the access token for providers

func (*Server) GetRepositoryById

GetRepositoryById returns a repository for a given repository id

func (*Server) GetRepositoryByName

GetRepositoryByName returns information about a repository. This function will typically be called by the client to get a repository which is already registered and present in the mediator database The API is called with a group id

func (*Server) GetRoleById

func (s *Server) GetRoleById(ctx context.Context,
	in *pb.GetRoleByIdRequest) (*pb.GetRoleByIdResponse, error)

GetRoleById is a service for getting a role by id

func (*Server) GetRoleByName

func (s *Server) GetRoleByName(ctx context.Context,
	in *pb.GetRoleByNameRequest) (*pb.GetRoleByNameResponse, error)

GetRoleByName is a service for getting a role by name

func (*Server) GetRoles

func (s *Server) GetRoles(ctx context.Context,
	in *pb.GetRolesRequest) (*pb.GetRolesResponse, error)

GetRoles is a service for getting roles

func (*Server) GetRolesByProject added in v0.0.5

GetRolesByProject is a service for getting roles for a projects

func (*Server) GetRuleTypeById

GetRuleTypeById is a method to get a rule type by id

func (*Server) GetRuleTypeByName

GetRuleTypeByName is a method to get a rule type by name

func (*Server) GetUser

func (s *Server) GetUser(ctx context.Context, _ *pb.GetUserRequest) (*pb.GetUserResponse, error)

GetUser is a service for getting personal user details

func (*Server) GetUserById

func (s *Server) GetUserById(ctx context.Context,
	in *pb.GetUserByIdRequest) (*pb.GetUserByIdResponse, error)

GetUserById is a service for getting a user by id

func (*Server) GetUsers

func (s *Server) GetUsers(ctx context.Context,
	in *pb.GetUsersRequest) (*pb.GetUsersResponse, error)

GetUsers is a service for getting a list of users

func (*Server) GetUsersByOrganization

GetUsersByOrganization is a service for getting a list of users of an organization

func (*Server) GetUsersByProject added in v0.0.5

GetUsersByProject is a service for getting a list of users of a project

func (*Server) HandleEvents

func (s *Server) HandleEvents(ctx context.Context) func() error

HandleEvents starts the event handler and blocks while handling events.

func (*Server) HandleGitHubWebHook

func (s *Server) HandleGitHubWebHook() http.HandlerFunc

HandleGitHubWebHook handles incoming GitHub webhooks See https://docs.github.com/en/developers/webhooks-and-events/webhooks/about-webhooks for more information.

func (*Server) IsProviderCallAuthorized

func (s *Server) IsProviderCallAuthorized(ctx context.Context, provider db.Provider, projectID uuid.UUID) bool

IsProviderCallAuthorized checks if the request is authorized

func (*Server) ListArtifacts

func (s *Server) ListArtifacts(ctx context.Context, in *pb.ListArtifactsRequest) (*pb.ListArtifactsResponse, error)

ListArtifacts lists all artifacts for a given group and provider nolint:gocyclo

func (*Server) ListProfiles added in v0.0.6

ListProfiles is a method to get all profiles for a group

func (*Server) ListRepositories

ListRepositories returns a list of repositories for a given group This function will typically be called by the client to get a list of repositories that are registered present in the mediator database The API is called with a group id, limit and offset

func (*Server) ListRuleTypes

ListRuleTypes is a method to list all rule types for a given context

func (*Server) RefreshToken

RefreshToken refreshes the access token

func (*Server) Register

func (s *Server) Register(topic string, handler events.Handler)

Register implements events.Registrar

func (*Server) RegisterRepository

RegisterRepository adds repositories to the database and registers a webhook Once a user had enrolled in a group (they have a valid token), they can register repositories to be monitored by the mediator by provisioning a webhook on the repositor(ies). The API is called with a slice of repositories to register and a slice of events e.g.

grpcurl -plaintext -d '{
	"repositories": [
		{ "owner": "acme", "name": "widgets" },
		{ "owner": "acme", "name": "gadgets" }
	  ],
	  "events": [ "push", "issues" ]
}' 127.0.0.1:8090 mediator.v1.RepositoryService/RegisterRepository

nolint: gocyclo

func (*Server) RevokeOauthProjectToken added in v0.0.5

RevokeOauthProjectToken revokes the oauth token for a group

func (*Server) RevokeOauthTokens

RevokeOauthTokens revokes the all oauth tokens for a provider This is in case of a security breach, where we need to revoke all tokens

func (*Server) StartGRPCServer

func (s *Server) StartGRPCServer(ctx context.Context) error

StartGRPCServer starts a gRPC server and blocks while serving.

func (*Server) StartHTTPServer

func (s *Server) StartHTTPServer(ctx context.Context) error

StartHTTPServer starts a HTTP server and registers the gRPC handler mux to it set store as a blank identifier for now as we will use it in the future

func (*Server) StoreProviderToken

StoreProviderToken stores the provider token for a group

func (*Server) SyncRepositories

SyncRepositories synchronizes the repositories for a given provider and group

func (*Server) UpdateRuleType

UpdateRuleType is a method to update a rule type

func (*Server) Verify

Verify verifies the access token

func (*Server) VerifyProviderTokenFrom

VerifyProviderTokenFrom verifies the provider token since a timestamp

Jump to

Keyboard shortcuts

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