controlplane

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 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 ErrRepoIsPrivate = errors.New("repository is private")

ErrRepoIsPrivate is returned when a repository is private

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.Project, []int32, error)

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

func DeleteUser added in v0.0.8

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

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

func HandleEvents added in v0.0.8

func HandleEvents(ctx context.Context, store db.Store, cfg *config.Config)

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

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 added in v0.0.8

func SubscribeToIdentityEvents(ctx context.Context, store db.Store, cfg *config.Config) error

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

Types

type AccountEvent added in v0.0.8

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 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 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) CreateProfile added in v0.0.6

CreateProfile creates a profile for a group nolint: gocyclo

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 added in v0.0.6

DeleteProfile is a method to delete a profile

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) 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) 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) 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) 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) 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) ListRemoteRepositoriesFromProvider added in v0.0.7

ListRemoteRepositoriesFromProvider returns a list of repositories from a provider

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

UpdateRuleType is a method to update a rule type

func (*Server) VerifyProviderTokenFrom

VerifyProviderTokenFrom verifies the provider token since a timestamp

type UpstreamRepositoryReference added in v0.0.7

type UpstreamRepositoryReference struct {
	Owner      string
	Name       string
	UpstreamID int32
}

UpstreamRepositoryReference represents a GitHub repository

Jump to

Keyboard shortcuts

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