controlplane

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 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 AuthorizedOnGroup added in v0.0.4

func AuthorizedOnGroup(ctx context.Context, groupId int32) error

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

func AuthorizedOnOrg added in v0.0.4

func AuthorizedOnOrg(ctx context.Context, orgId int32) error

AuthorizedOnOrg checks if the request is authorized for the given organization, 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 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 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) CreateGroup

func (s *Server) CreateGroup(ctx context.Context, req *pb.CreateGroupRequest) (*pb.CreateGroupResponse, error)

CreateGroup creates a group

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

func (s *Server) CreatePolicy(ctx context.Context,
	cpr *pb.CreatePolicyRequest) (*pb.CreatePolicyResponse, error)

CreatePolicy creates a policy for a group nolint: gocyclo

func (*Server) CreateRoleByGroup

CreateRoleByGroup is a service for creating a role for a group

func (*Server) CreateRoleByOrganization

CreateRoleByOrganization is a service for creating a role for an organization

func (*Server) CreateRuleType

func (s *Server) CreateRuleType(ctx context.Context, crt *pb.CreateRuleTypeRequest) (*pb.CreateRuleTypeResponse, error)

CreateRuleType is a method to create a rule type

func (*Server) CreateUser

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

CreateUser is a service for user self registration

func (*Server) DeleteGroup

func (s *Server) DeleteGroup(ctx context.Context,
	in *pb.DeleteGroupRequest) (*pb.DeleteGroupResponse, error)

DeleteGroup is a handler that deletes a group

func (*Server) DeleteOrganization

DeleteOrganization is a handler that deletes a organization

func (*Server) DeletePolicy

func (s *Server) DeletePolicy(ctx context.Context,
	in *pb.DeletePolicyRequest) (*pb.DeletePolicyResponse, error)

DeletePolicy is a method to delete a policy

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

func (s *Server) DeleteRuleType(ctx context.Context, in *pb.DeleteRuleTypeRequest) (*pb.DeleteRuleTypeResponse, error)

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

func (s *Server) GetGroupById(ctx context.Context, req *pb.GetGroupByIdRequest) (*pb.GetGroupByIdResponse, error)

GetGroupById returns a group by id

func (*Server) GetGroupByName

func (s *Server) GetGroupByName(ctx context.Context, req *pb.GetGroupByNameRequest) (*pb.GetGroupByNameResponse, error)

GetGroupByName returns a group by name

func (*Server) GetGroups

func (s *Server) GetGroups(ctx context.Context, req *pb.GetGroupsRequest) (*pb.GetGroupsResponse, error)

GetGroups returns a list of groups

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

func (s *Server) GetPolicyById(ctx context.Context,
	in *pb.GetPolicyByIdRequest) (*pb.GetPolicyByIdResponse, error)

GetPolicyById is a method to get a policy by id

func (*Server) GetPolicyStatusByGroup

GetPolicyStatusByGroup is a method to get policy status for a group

func (*Server) GetPolicyStatusById

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

func (*Server) GetProviderAccessToken

func (s *Server) GetProviderAccessToken(ctx context.Context, provider string,
	groupId int32, 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) GetRolesByGroup

GetRolesByGroup is a service for getting roles for a group

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

GetUsersByGroup is a service for getting a list of users of a group

func (*Server) GetUsersByOrganization

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

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, groupId int32) 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) ListPolicies

func (s *Server) ListPolicies(ctx context.Context,
	in *pb.ListPoliciesRequest) (*pb.ListPoliciesResponse, error)

ListPolicies is a method to get all policies 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

func (s *Server) ListRuleTypes(ctx context.Context, in *pb.ListRuleTypesRequest) (*pb.ListRuleTypesResponse, error)

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

RevokeOauthGroupToken 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

func (s *Server) UpdateRuleType(ctx context.Context, urt *pb.UpdateRuleTypeRequest) (*pb.UpdateRuleTypeResponse, error)

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