services

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: BSD-3-Clause Imports: 45 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AccountStatusApproved = "Approved"
	AccountStatusDenied   = "Denied"
	AccountStatusPending  = "Pending"
)

Functions

func HasRole

func HasRole(roles []string, role string) bool

HasRole checks if a user has a specific role in the JWT claims.

func IsDNSCompatible

func IsDNSCompatible(name string) bool

isDNSCompatible returns true if the provided name is DNS-compatible

func WriteResponse

func WriteResponse(w http.ResponseWriter, statusCode int, response interface{}, location ...string)

Types

type AirbusContractsData

type AirbusContractsData struct {
	Optical map[string]string `json:"optical,omitempty"`
	SAR     bool              `json:"sar"`
}

type AirbusOpticalContract

type AirbusOpticalContract struct {
	ContractID string `json:"contractId"`
	Name       string `json:"name"`
}

type AirbusOpticalContractsResponse

type AirbusOpticalContractsResponse struct {
	Contracts []AirbusOpticalContract `json:"contracts"`
}

type AirbusSARContractsResponse

type AirbusSARContractsResponse struct {
	Services []string `json:"services"`
}

type BillingAccountService

type BillingAccountService struct {
	Config         *appconfig.Config
	DB             db.WorkspaceDBInterface
	AWSEmailClient EmailClient
	KC             KeycloakClientInterface
}

func (*BillingAccountService) AccountApprovalService

func (svc *BillingAccountService) AccountApprovalService(w http.ResponseWriter, r *http.Request, accountStatusRequest string)

DeleteAccountService deletes an account specified by the account ID from the URL path.

func (*BillingAccountService) CreateAccountService

func (svc *BillingAccountService) CreateAccountService(w http.ResponseWriter, r *http.Request)

CreateAccountService creates a new account for the authenticated user.

func (*BillingAccountService) DeleteAccountService

func (svc *BillingAccountService) DeleteAccountService(w http.ResponseWriter, r *http.Request)

DeleteAccountService deletes an account specified by the account ID from the URL path.

func (*BillingAccountService) GetAccountService

func (svc *BillingAccountService) GetAccountService(w http.ResponseWriter, r *http.Request)

GetAccountService retrieves a single account all accounts for the authenticated user.

func (*BillingAccountService) GetAccountsService

func (svc *BillingAccountService) GetAccountsService(w http.ResponseWriter, r *http.Request)

GetAccountsService retrieves all accounts for the authenticated user.

func (*BillingAccountService) SendAccountApprovalEmail

func (svc *BillingAccountService) SendAccountApprovalEmail(account *ws_services.Account, recipient string) error

SendAccountApprovalEmail sends an email to the account owner with the account approval details.

func (*BillingAccountService) SendAccountDenialEmail

func (svc *BillingAccountService) SendAccountDenialEmail(account *ws_services.Account, recipient string) error

SendAccountDenialEmail sends an email to the account owner with the account denial details.

func (*BillingAccountService) SendAccountRequestEmail

func (svc *BillingAccountService) SendAccountRequestEmail(account *ws_services.Account, token string) error

SendAccountRequestEmail sends an email to the helpdesk with the account request details.

func (*BillingAccountService) UpdateAccountService

func (svc *BillingAccountService) UpdateAccountService(w http.ResponseWriter, r *http.Request)

UpdateAccountService updates an account based on account ID from the URL path.

type EmailClient

type EmailClient interface {
	SendEmail(ctx context.Context, input *sesv2.SendEmailInput, optFns ...func(*sesv2.Options)) (*sesv2.SendEmailOutput, error)
}

type FileDeleteResponse

type FileDeleteResponse struct {
	Workspace string     `json:"workspace"`
	Deleted   []string   `json:"deleted"`
	Failed    []FileFail `json:"failed,omitempty"`
}

type FileFail

type FileFail struct {
	FileName string `json:"fileName"`
	Error    string `json:"error"`
}

type FileItem

type FileItem struct {
	StoreType    string `json:"storeType"`
	FileName     string `json:"fileName"`
	Size         int64  `json:"size,omitempty"`
	LastModified string `json:"lastModified,omitempty"`
	ETag         string `json:"etag,omitempty"`
}

type FileListResponse

type FileListResponse struct {
	Workspace string     `json:"workspace"`
	Items     []FileItem `json:"items"`
}

type FileMetadataResponse

type FileMetadataResponse struct {
	Workspace string   `json:"workspace"`
	Item      FileItem `json:"item"`
}

type FileService

type FileService struct {
	Config *appconfig.Config
	DB     db.WorkspaceDBInterface
	KC     KeycloakClientInterface
	STS    STSClient
}

func (*FileService) DeleteFilesService

func (svc *FileService) DeleteFilesService(w http.ResponseWriter, r *http.Request, storeType string)

DeleteFilesService deletes files from a single store.

func (*FileService) GetFileMetadataService

func (svc *FileService) GetFileMetadataService(w http.ResponseWriter, r *http.Request, storeType string)

GetFileMetadataService gets metadata for a single file.

func (*FileService) ListFilesService

func (svc *FileService) ListFilesService(w http.ResponseWriter, r *http.Request)

ListFilesService lists files from object and/or block stores.

func (*FileService) UploadFilesService

func (svc *FileService) UploadFilesService(w http.ResponseWriter, r *http.Request, storeType string)

UploadFilesService uploads files to a single store.

type FileUploadResponse

type FileUploadResponse struct {
	Workspace string     `json:"workspace"`
	Items     []FileItem `json:"items"`
}

type HTTPError

type HTTPError struct {
	Message string
	Status  int
}

func (*HTTPError) Error

func (e *HTTPError) Error() string

type KeycloakClient

type KeycloakClient struct {
	BaseURL      string
	ClientID     string
	ClientSecret string
	Realm        string
	Token        string
	HTTPClient   *http.Client
}

KeycloakClient is a client for interacting with the Keycloak API.

func NewKeycloakClient

func NewKeycloakClient(baseURL, clientID, clientSecret, realm string) *KeycloakClient

NewKeycloakClient creates a new instance of KeycloakClient.

func (*KeycloakClient) AddMemberToGroup

func (kc *KeycloakClient) AddMemberToGroup(userID, groupID string) error

AddMemberToGroup adds a user to a group in Keycloak.

func (*KeycloakClient) CreateGroup

func (kc *KeycloakClient) CreateGroup(groupName string) (int, error)

CreateGroup creates a new group in Keycloak.

func (*KeycloakClient) DeleteGroup

func (kc *KeycloakClient) DeleteGroup(groupName string) (int, error)

DeleteGroup deletes a group in Keycloak

func (KeycloakClient) ExchangeToken

func (kc KeycloakClient) ExchangeToken(accessToken, scope string) (*TokenResponse,
	error)

ExchangeToken exchanges an access token for a new token with a different scope.

func (*KeycloakClient) GetGroup

func (kc *KeycloakClient) GetGroup(groupName string) (*models.Group, error)

GetGroup retrieves a group by name from Keycloak.

func (*KeycloakClient) GetGroupMember

func (kc *KeycloakClient) GetGroupMember(groupID, userID string) (*models.User, error)

GetGroupMember retrieves a specific member of a group in Keycloak.

func (*KeycloakClient) GetGroupMembers

func (kc *KeycloakClient) GetGroupMembers(groupID string) ([]models.User, error)

GetGroupMembers retrieves a list of members of a group in Keycloak.

func (*KeycloakClient) GetToken

func (kc *KeycloakClient) GetToken() error

GetToken retrieves a Keycloak access token using client_credentials.

func (*KeycloakClient) GetUser

func (kc *KeycloakClient) GetUser(username string) (*models.User, error)

GetUser retrieves a user ID by username from Keycloak.

func (*KeycloakClient) GetUserGroups

func (kc *KeycloakClient) GetUserGroups(userID string) ([]string, error)

GetUserGroups retrieves a list of group names that a user is a member of.

func (*KeycloakClient) RemoveMemberFromGroup

func (kc *KeycloakClient) RemoveMemberFromGroup(userID, groupID string) error

RemoveMemberFromGroup adds a user to a group in Keycloak.

type KeycloakClientInterface

type KeycloakClientInterface interface {
	GetToken() error
	CreateGroup(groupName string) (int, error)
	DeleteGroup(groupName string) (int, error)
	GetGroup(groupName string) (*models.Group, error)
	GetGroupMembers(groupID string) ([]models.User, error)
	GetGroupMember(groupID, userID string) (*models.User, error)
	AddMemberToGroup(userID, groupID string) error
	RemoveMemberFromGroup(userID, groupID string) error
	GetUser(username string) (*models.User, error)
	GetUserGroups(userID string) ([]string, error)
	ExchangeToken(accessToken, scope string) (*TokenResponse, error)
}

type KeycloakError

type KeycloakError struct {
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
}

type KeycloakResponse

type KeycloakResponse = map[string]any

type LinkedAccountService

type LinkedAccountService struct {
	Config         *appconfig.Config
	DB             *db.WorkspaceDB
	SecretsManager *secretsmanager.Client
	K8sClient      *kubernetes.Clientset
	KC             KeycloakClientInterface
}

func (*LinkedAccountService) CreateLinkedAccountService

func (svc *LinkedAccountService) CreateLinkedAccountService(w http.ResponseWriter, r *http.Request)

CreateLinkedAccountService handles the creation of a linked account, encrypts the API key using OTP, and securely stores it in both Kubernetes (for the OTP key) and AWS Secrets Manager (for the encrypted key).

func (*LinkedAccountService) DeleteLinkedAccountService

func (svc *LinkedAccountService) DeleteLinkedAccountService(w http.ResponseWriter, r *http.Request)

func (*LinkedAccountService) GetLinkedAccounts

func (svc *LinkedAccountService) GetLinkedAccounts(w http.ResponseWriter, r *http.Request)

GetLinkedAccountsService handles the retrieval of linked accounts from AWS Secrets Manager. The linked account secrets are stored as key-value pairs, where the key is the provider name and the value is the encrypted API key.

func (*LinkedAccountService) ValidateAirbusLinkedAccountService

func (svc *LinkedAccountService) ValidateAirbusLinkedAccountService(w http.ResponseWriter, r *http.Request)

ValidateAirbusLinkedAccountService validates the Airbus key and returns the associated contracts. The key is used to obtain an access token, which is then used to fetch the contracts from the Airbus API.

func (*LinkedAccountService) ValidatePlanetLinkedAccountService

func (svc *LinkedAccountService) ValidatePlanetLinkedAccountService(w http.ResponseWriter, r *http.Request)

ValidatePlanetLinkedAccountService validates the Planet key

type LinkedAccountServiceInterface

type LinkedAccountServiceInterface interface {
	GetLinkedAccounts(w http.ResponseWriter, r *http.Request)
	DeleteLinkedAccountService(w http.ResponseWriter, r *http.Request)
	CreateLinkedAccountService(w http.ResponseWriter, r *http.Request)
	// contains filtered or unexported methods
}

type MockAWSEmailClient

type MockAWSEmailClient struct {
	mock.Mock
}

func (*MockAWSEmailClient) SendEmail

func (m *MockAWSEmailClient) SendEmail(ctx context.Context, input *sesv2.SendEmailInput, opts ...func(*sesv2.Options)) (*sesv2.SendEmailOutput, error)

type MockEventPublisher

type MockEventPublisher struct {
	mock.Mock
}

func (*MockEventPublisher) Close

func (m *MockEventPublisher) Close()

Mock the Close method

func (*MockEventPublisher) Publish

Mock the Publish method

type MockKeycloakClient

type MockKeycloakClient struct {
	mock.Mock
}

func (*MockKeycloakClient) AddMemberToGroup

func (m *MockKeycloakClient) AddMemberToGroup(userID, groupID string) error

AddMemberToGroup mock (Add this method)

func (*MockKeycloakClient) AddUserToGroup

func (m *MockKeycloakClient) AddUserToGroup(userID, groupID string) error

AddUserToGroup mock

func (*MockKeycloakClient) CreateGroup

func (m *MockKeycloakClient) CreateGroup(groupName string) (int, error)

CreateGroup mock

func (*MockKeycloakClient) CreateUser

func (m *MockKeycloakClient) CreateUser(username, email, password string) (string, error)

CreateUser mock

func (*MockKeycloakClient) DeleteGroup

func (m *MockKeycloakClient) DeleteGroup(groupID string) (int, error)

DeleteGroup mock (This was missing)

func (*MockKeycloakClient) DeleteUser

func (m *MockKeycloakClient) DeleteUser(userID string) error

DeleteUser mock

func (*MockKeycloakClient) ExchangeToken

func (m *MockKeycloakClient) ExchangeToken(accessToken, scope string) (*TokenResponse, error)

func (*MockKeycloakClient) GetGroup

func (m *MockKeycloakClient) GetGroup(groupName string) (*ws_services.Group, error)

func (*MockKeycloakClient) GetGroupMember

func (m *MockKeycloakClient) GetGroupMember(groupID, userID string) (*ws_services.User, error)

func (*MockKeycloakClient) GetGroupMembers

func (m *MockKeycloakClient) GetGroupMembers(groupID string) ([]ws_services.User, error)

func (*MockKeycloakClient) GetToken

func (m *MockKeycloakClient) GetToken() error

func (*MockKeycloakClient) GetUser

func (m *MockKeycloakClient) GetUser(username string) (*ws_services.User, error)

func (*MockKeycloakClient) GetUserGroups

func (m *MockKeycloakClient) GetUserGroups(userID string) ([]string, error)

func (*MockKeycloakClient) RemoveMemberFromGroup

func (m *MockKeycloakClient) RemoveMemberFromGroup(userID, groupID string) error

func (*MockKeycloakClient) RemoveUserFromGroup

func (m *MockKeycloakClient) RemoveUserFromGroup(userID, groupID string) error

RemoveUserFromGroup mock

type MockWorkspaceDB

type MockWorkspaceDB struct {
	mock.Mock
}

func (*MockWorkspaceDB) CheckAccountIsVerified

func (m *MockWorkspaceDB) CheckAccountIsVerified(accountID uuid.UUID) (bool, error)

func (*MockWorkspaceDB) CheckWorkspaceExists

func (m *MockWorkspaceDB) CheckWorkspaceExists(name string) (bool, error)

func (*MockWorkspaceDB) Close

func (m *MockWorkspaceDB) Close() error

func (*MockWorkspaceDB) CommitTransaction

func (m *MockWorkspaceDB) CommitTransaction(tx *sql.Tx) error

func (*MockWorkspaceDB) CreateAccount

func (m *MockWorkspaceDB) CreateAccount(account *ws_services.Account) (*ws_services.Account, error)

func (*MockWorkspaceDB) CreateAccountApprovalToken

func (m *MockWorkspaceDB) CreateAccountApprovalToken(accountID uuid.UUID) (string, error)

func (*MockWorkspaceDB) CreateWorkspace

func (m *MockWorkspaceDB) CreateWorkspace(req *ws_manager.WorkspaceSettings) (*sql.Tx, error)

func (*MockWorkspaceDB) DeleteAccount

func (m *MockWorkspaceDB) DeleteAccount(accountID uuid.UUID) error

func (*MockWorkspaceDB) DisableWorkspace

func (m *MockWorkspaceDB) DisableWorkspace(workspaceName string) error

func (*MockWorkspaceDB) GetAccount

func (m *MockWorkspaceDB) GetAccount(accountID uuid.UUID) (*ws_services.Account, error)

func (*MockWorkspaceDB) GetAccounts

func (m *MockWorkspaceDB) GetAccounts(username string) ([]ws_services.Account, error)

func (*MockWorkspaceDB) GetOwnedWorkspaces

func (m *MockWorkspaceDB) GetOwnedWorkspaces(username string) ([]ws_manager.WorkspaceSettings, error)

func (*MockWorkspaceDB) GetUserWorkspaces

func (m *MockWorkspaceDB) GetUserWorkspaces(memberGroups []string) ([]ws_manager.WorkspaceSettings, error)

func (*MockWorkspaceDB) GetWorkspace

func (m *MockWorkspaceDB) GetWorkspace(workspaceName string) (*ws_manager.WorkspaceSettings, error)

func (*MockWorkspaceDB) IsUserAccountOwner

func (m *MockWorkspaceDB) IsUserAccountOwner(username, workspaceID string) (bool, error)

func (*MockWorkspaceDB) UpdateAccount

func (m *MockWorkspaceDB) UpdateAccount(accountID uuid.UUID, account ws_services.Account) (*ws_services.Account, error)

func (*MockWorkspaceDB) UpdateAccountStatus

func (m *MockWorkspaceDB) UpdateAccountStatus(token, accountID, status string) error

func (*MockWorkspaceDB) UpdateWorkspaceStatus

func (m *MockWorkspaceDB) UpdateWorkspaceStatus(status ws_manager.WorkspaceStatus) error

func (*MockWorkspaceDB) ValidateApprovalToken

func (m *MockWorkspaceDB) ValidateApprovalToken(token string) (string, error)

type Payload

type Payload struct {
	Name      string              `json:"name"`
	Key       string              `json:"key"`
	Contracts AirbusContractsData `json:"contracts,omitempty"` // Airbus only
}

Payload represents the expected JSON structure

type STSClient

type STSClient interface {
	AssumeRoleWithWebIdentity(ctx context.Context,
		params *sts.AssumeRoleWithWebIdentityInput, optFns ...func(*sts.Options)) (
		*sts.AssumeRoleWithWebIdentityOutput, error)
}

STSClient defines the minimal interface needed for STS AssumeRoleWithWebIdentity.

type TokenResponse

type TokenResponse struct {
	Access           string `json:"access_token"`
	Refresh          string `json:"refresh_token"`
	ExpiresIn        int    `json:"expires_in"`
	RefreshExpiresIn int    `json:"refresh_expires_in"`
	Scope            string `json:"scope"`
}

type WorkspaceService

type WorkspaceService struct {
	Config    *appconfig.Config
	DB        db.WorkspaceDBInterface
	Publisher events.Publisher
	KC        KeycloakClientInterface
}

func (*WorkspaceService) AddUserService

func (svc *WorkspaceService) AddUserService(w http.ResponseWriter, r *http.Request)

AddUserService adds a user to a workspace.

func (*WorkspaceService) CreateWorkspaceService

func (svc *WorkspaceService) CreateWorkspaceService(w http.ResponseWriter, r *http.Request)

CreateWorkspaceService handles creating a new workspace and publishing its creation event.

func (*WorkspaceService) DeleteWorkspaceService

func (svc *WorkspaceService) DeleteWorkspaceService(w http.ResponseWriter, r *http.Request)

Deletes a workspace and its associated resources.

func (*WorkspaceService) GetUserService

func (svc *WorkspaceService) GetUserService(w http.ResponseWriter, r *http.Request)

GetUsersService retrieves all users associated with a workspace.

func (*WorkspaceService) GetUsersService

func (svc *WorkspaceService) GetUsersService(w http.ResponseWriter, r *http.Request)

GetUsersService retrieves all users associated with a workspace.

func (*WorkspaceService) GetWorkspaceService

func (svc *WorkspaceService) GetWorkspaceService(w http.ResponseWriter, r *http.Request)

GetWorkspaceService retrieves an individual workspace accessible to the authenticated user's groups.

func (*WorkspaceService) GetWorkspacesService

func (svc *WorkspaceService) GetWorkspacesService(w http.ResponseWriter, r *http.Request)

GetWorkspacesService retrieves all workspaces accessible to the authenticated user's groups.

func (*WorkspaceService) RemoveUserService

func (svc *WorkspaceService) RemoveUserService(w http.ResponseWriter, r *http.Request)

RemoveUserService removes a user from a workspace.

Jump to

Keyboard shortcuts

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