controlplane

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: Apache-2.0 Imports: 77 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 minder.

Index

Constants

View Source
const PaginationLimit = 10

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

Variables

This section is empty.

Functions

func DecodeValue added in v0.0.27

func DecodeValue(value string) (string, error)

DecodeValue decodes a base64 encoded string into a string

func DeleteUser

func DeleteUser(ctx context.Context, store db.Store, authzClient authz.Client, userId string) error

DeleteUser deletes a user and all their associated data from the minder database

func EncodeValue added in v0.0.27

func EncodeValue(value string) string

EncodeValue encodes a string into a base64 encoded string

func EntityContextProjectInterceptor added in v0.0.27

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

EntityContextProjectInterceptor is a server interceptor that sets up the entity context project

func HandleEvents

func HandleEvents(
	ctx context.Context,
	store db.Store,
	authzClient authz.Client,
	cfg *serverconfig.Config,
)

HandleEvents fetches events from the identity provider and performs any related changes to the minder database

func NewMetrics

func NewMetrics() *metrics

NewMetrics creates a new controlplane metrics instance.

func PermissionsContextUnaryInterceptor added in v0.0.27

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

PermissionsContextUnaryInterceptor is a server interceptor that sets up the user permissions

func ProjectAuthorizationInterceptor added in v0.0.27

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

ProjectAuthorizationInterceptor is a server interceptor that checks if a user is authorized on the requested project

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

func SubscribeToIdentityEvents

func SubscribeToIdentityEvents(
	ctx context.Context,
	store db.Store,
	authzClient authz.Client,
	cfg *serverconfig.Config,
) error

SubscribeToIdentityEvents starts a cron job that periodically fetches events from the identity provider

func TokenValidationInterceptor added in v0.0.24

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

TokenValidationInterceptor is a server interceptor that validates the bearer token

Types

type AccountEvent

type AccountEvent struct {
	Time     int64  `json:"time"`
	Type     string `json:"type"`
	RealmId  string `json:"realmId"`
	ClientId string `json:"clientId"`
	UserId   string `json:"userId"`
}

AccountEvent is an event returned by the identity provider

type HasProtoContext added in v0.0.21

type HasProtoContext interface {
	GetContext() *pb.Context
}

HasProtoContext is an interface that can be implemented by a request

type OrgMeta

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

OrgMeta is the metadata associated with an organization

type ProjectMeta

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

ProjectMeta is the metadata associated with a project

type RepoCursor added in v0.0.27

type RepoCursor struct {
	ProjectId string
	Provider  string
	RepoId    int32
}

RepoCursor is a cursor for listing repositories

func NewRepoCursor added in v0.0.27

func NewRepoCursor(encodedCursor string) (*RepoCursor, error)

NewRepoCursor creates a new RepoCursor from an encoded cursor

func (*RepoCursor) String added in v0.0.27

func (c *RepoCursor) String() string

type Server

Server represents the controlplane server

func NewServer

func NewServer(
	store db.Store,
	evt *events.Eventer,
	cpm *metrics,
	cfg *serverconfig.Config,
	vldtr auth.JwtValidator,
	opts ...ServerOption,
) (*Server, error)

NewServer creates a new server instance

func (*Server) CheckHealth

CheckHealth is a simple health check for monitoring

func (*Server) ConsumeEvents

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

ConsumeEvents implements events.Registrar

func (*Server) CreateDefaultRecordsForOrg added in v0.0.27

func (s *Server) CreateDefaultRecordsForOrg(ctx context.Context, qtx db.Querier,
	org db.Project, projectName string, userSub string) (outproj *pb.Project, outroles []int32, projerr error)

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

func (*Server) CreateProfile

CreateProfile creates a profile 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) DeleteProfile

DeleteProfile is a method to delete a profile

func (*Server) DeleteRepositoryById

DeleteRepositoryById deletes a repository by name

func (*Server) DeleteRepositoryByName

DeleteRepositoryByName deletes a repository by name

func (*Server) DeleteRuleType

DeleteRuleType is a method to delete a rule type

func (*Server) DeleteUser

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

DeleteUser is a service for user self deletion

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) GetArtifactById

GetArtifactById gets an artifact by id nolint:gocyclo

func (*Server) GetArtifactByName added in v0.0.22

GetArtifactByName gets an artifact by name 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) GetProfileById

GetProfileById is a method to get a profile by id

func (*Server) GetProfileStatusByName

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

func (*Server) GetProfileStatusByProject

GetProfileStatusByProject is a method to get profile status for a project

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 minder database The API is called with a project id

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) 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) ListArtifacts

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

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

func (*Server) ListProfiles

ListProfiles is a method to get all profiles for a project

func (*Server) ListRemoteRepositoriesFromProvider

ListRemoteRepositoriesFromProvider returns a list of repositories from a provider

func (*Server) ListRepositories

ListRepositories returns a list of repositories for a given project This function will typically be called by the client to get a list of repositories that are registered present in the minder database

func (*Server) ListRuleTypes

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

func (*Server) Register

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

Register implements events.Registrar

func (*Server) RegisterRepository

RegisterRepository adds repositories to the database and registers a webhook Once a user had enrolled in a project (they have a valid token), they can register repositories to be monitored by the minder by provisioning a webhook on the repository(ies).

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 project

func (*Server) UpdateProfile added in v0.0.16

UpdateProfile updates a profile for a project

func (*Server) UpdateRuleType

UpdateRuleType is a method to update a rule type

func (*Server) VerifyProviderTokenFrom

VerifyProviderTokenFrom verifies the provider token since a timestamp

type ServerOption

type ServerOption func(*Server)

ServerOption is a function that modifies a server

func WithAuthzClient added in v0.0.27

func WithAuthzClient(c authz.Client) ServerOption

WithAuthzClient sets the authz client for the server

func WithProviderMetrics

func WithProviderMetrics(mt provtelemetry.ProviderMetrics) ServerOption

WithProviderMetrics sets the provider metrics for the server

Jump to

Keyboard shortcuts

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