usecase

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2025 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSlackServiceNotConfigured = goerr.New("slack service not configured")
)

Functions

This section is empty.

Types

type AlertMock

type AlertMock struct {
	// HandleAlertWithAuthFunc mocks the HandleAlertWithAuth method.
	HandleAlertWithAuthFunc func(ctx context.Context, schema types.AlertSchema, alertData any) ([]*alert.Alert, error)
	// contains filtered or unexported fields
}

AlertMock is a mock implementation of Alert.

func TestSomethingThatUsesAlert(t *testing.T) {

	// make and configure a mocked Alert
	mockedAlert := &AlertMock{
		HandleAlertWithAuthFunc: func(ctx context.Context, schema types.AlertSchema, alertData any) ([]*alert.Alert, error) {
			panic("mock out the HandleAlertWithAuth method")
		},
	}

	// use mockedAlert in code that requires Alert
	// and then make assertions.

}

func (*AlertMock) HandleAlertWithAuth

func (mock *AlertMock) HandleAlertWithAuth(ctx context.Context, schema types.AlertSchema, alertData any) ([]*alert.Alert, error)

HandleAlertWithAuth calls HandleAlertWithAuthFunc.

func (*AlertMock) HandleAlertWithAuthCalls

func (mock *AlertMock) HandleAlertWithAuthCalls() []struct {
	Ctx       context.Context
	Schema    types.AlertSchema
	AlertData any
}

HandleAlertWithAuthCalls gets all the calls that were made to HandleAlertWithAuth. Check the length with:

len(mockedAlert.HandleAlertWithAuthCalls())

type AuthUseCase

type AuthUseCase struct {
	// contains filtered or unexported fields
}

func NewAuthUseCase

func NewAuthUseCase(repo interfaces.Repository, slackSvc *slack.Service, clientID, clientSecret, callbackURL string) *AuthUseCase

func (*AuthUseCase) GetAuthURL

func (uc *AuthUseCase) GetAuthURL(state string) string

GetAuthURL returns the URL for Slack OAuth

func (*AuthUseCase) HandleCallback

func (uc *AuthUseCase) HandleCallback(ctx context.Context, code string) (*auth.Token, error)

HandleCallback processes the OAuth callback

func (*AuthUseCase) Logout

func (uc *AuthUseCase) Logout(ctx context.Context, tokenID auth.TokenID) error

Logout deletes the token

func (*AuthUseCase) ValidateToken

func (uc *AuthUseCase) ValidateToken(ctx context.Context, tokenID auth.TokenID, tokenSecret auth.TokenSecret) (*auth.Token, error)

ValidateToken validates the token and returns user info

type AuthUseCaseForDev

type AuthUseCaseForDev struct {
	// contains filtered or unexported fields
}

AuthUseCaseForDev is a development-only authentication use case that bypasses Slack OAuth

func NewAuthUseCaseForDev

func NewAuthUseCaseForDev(devUser string) *AuthUseCaseForDev

NewAuthUseCaseForDev creates an AuthUseCase for development mode

func (*AuthUseCaseForDev) DevModeAuth

func (uc *AuthUseCaseForDev) DevModeAuth(ctx context.Context) (*auth.Token, error)

DevModeAuth creates a dev token (same as HandleCallback for dev mode)

func (*AuthUseCaseForDev) GetAuthURL

func (uc *AuthUseCaseForDev) GetAuthURL(state string) string

GetAuthURL returns a dummy URL for dev mode (will be handled by login handler)

func (*AuthUseCaseForDev) HandleCallback

func (uc *AuthUseCaseForDev) HandleCallback(ctx context.Context, code string) (*auth.Token, error)

HandleCallback creates a dev token directly

func (*AuthUseCaseForDev) Logout

func (uc *AuthUseCaseForDev) Logout(ctx context.Context, tokenID auth.TokenID) error

Logout removes token from in-memory storage

func (*AuthUseCaseForDev) ValidateToken

func (uc *AuthUseCaseForDev) ValidateToken(ctx context.Context, tokenID auth.TokenID, tokenSecret auth.TokenSecret) (*auth.Token, error)

ValidateToken validates token from in-memory storage

type AuthUseCaseInterface

type AuthUseCaseInterface interface {
	GetAuthURL(state string) string
	HandleCallback(ctx context.Context, code string) (*auth.Token, error)
	ValidateToken(ctx context.Context, tokenID auth.TokenID, tokenSecret auth.TokenSecret) (*auth.Token, error)
	Logout(ctx context.Context, tokenID auth.TokenID) error
}

AuthUseCaseInterface defines the interface for authentication use cases

type OpenIDConfiguration

type OpenIDConfiguration struct {
	Issuer                            string   `json:"issuer"`
	AuthorizationEndpoint             string   `json:"authorization_endpoint"`
	TokenEndpoint                     string   `json:"token_endpoint"`
	UserinfoEndpoint                  string   `json:"userinfo_endpoint"`
	JWKSURI                           string   `json:"jwks_uri"`
	ScopesSupported                   []string `json:"scopes_supported"`
	ResponseTypesSupported            []string `json:"response_types_supported"`
	ResponseModesSupported            []string `json:"response_modes_supported"`
	GrantTypesSupported               []string `json:"grant_types_supported"`
	SubjectTypesSupported             []string `json:"subject_types_supported"`
	IDTokenSigningAlgValuesSupported  []string `json:"id_token_signing_alg_values_supported"`
	ClaimsSupported                   []string `json:"claims_supported"`
	ClaimsParameterSupported          bool     `json:"claims_parameter_supported"`
	RequestParameterSupported         bool     `json:"request_parameter_supported"`
	RequestURIParameterSupported      bool     `json:"request_uri_parameter_supported"`
	TokenEndpointAuthMethodsSupported []string `json:"token_endpoint_auth_methods_supported"`
}

OpenIDConfiguration represents Slack's OpenID Connect configuration

type Option

type Option func(*UseCases)

func WithActionLimit

func WithActionLimit(actionLimit int) Option

func WithEmbeddingClient

func WithEmbeddingClient(embeddingClient interfaces.EmbeddingClient) Option

func WithFindingLimit

func WithFindingLimit(findingLimit int) Option

func WithLLMClient

func WithLLMClient(llmClient gollem.LLMClient) Option

func WithPolicyClient

func WithPolicyClient(policyClient interfaces.PolicyClient) Option

func WithRepository

func WithRepository(repository interfaces.Repository) Option

func WithSlackService

func WithSlackService(slackService *slack.Service) Option

func WithStorageClient

func WithStorageClient(storageClient interfaces.StorageClient) Option

func WithStoragePrefix

func WithStoragePrefix(storagePrefix string) Option

func WithTimeSpan

func WithTimeSpan(timeSpan time.Duration) Option

WithTimeSpan is used to set the time span for fetching alerts to search similar alerts

func WithTools

func WithTools(tools []gollem.ToolSet) Option

type SlackEventMock

type SlackEventMock struct {
	// HandleSlackAppMentionFunc mocks the HandleSlackAppMention method.
	HandleSlackAppMentionFunc func(ctx context.Context, slackMsg slack.Message) error

	// HandleSlackMessageFunc mocks the HandleSlackMessage method.
	HandleSlackMessageFunc func(ctx context.Context, slackMsg slack.Message) error
	// contains filtered or unexported fields
}

SlackEventMock is a mock implementation of SlackEvent.

func TestSomethingThatUsesSlackEvent(t *testing.T) {

	// make and configure a mocked SlackEvent
	mockedSlackEvent := &SlackEventMock{
		HandleSlackAppMentionFunc: func(ctx context.Context, slackMsg slack.Message) error {
			panic("mock out the HandleSlackAppMention method")
		},
		HandleSlackMessageFunc: func(ctx context.Context, slackMsg slack.Message) error {
			panic("mock out the HandleSlackMessage method")
		},
	}

	// use mockedSlackEvent in code that requires SlackEvent
	// and then make assertions.

}

func (*SlackEventMock) HandleSlackAppMention

func (mock *SlackEventMock) HandleSlackAppMention(ctx context.Context, slackMsg slack.Message) error

HandleSlackAppMention calls HandleSlackAppMentionFunc.

func (*SlackEventMock) HandleSlackAppMentionCalls

func (mock *SlackEventMock) HandleSlackAppMentionCalls() []struct {
	Ctx      context.Context
	SlackMsg slack.Message
}

HandleSlackAppMentionCalls gets all the calls that were made to HandleSlackAppMention. Check the length with:

len(mockedSlackEvent.HandleSlackAppMentionCalls())

func (*SlackEventMock) HandleSlackMessage

func (mock *SlackEventMock) HandleSlackMessage(ctx context.Context, slackMsg slack.Message) error

HandleSlackMessage calls HandleSlackMessageFunc.

func (*SlackEventMock) HandleSlackMessageCalls

func (mock *SlackEventMock) HandleSlackMessageCalls() []struct {
	Ctx      context.Context
	SlackMsg slack.Message
}

HandleSlackMessageCalls gets all the calls that were made to HandleSlackMessage. Check the length with:

len(mockedSlackEvent.HandleSlackMessageCalls())

type SlackIDToken

type SlackIDToken struct {
	Sub   string `json:"sub"`
	Email string `json:"email"`
	Name  string `json:"name"`
}

SlackIDToken represents the decoded ID token from Slack

type SlackInteractionMock

type SlackInteractionMock struct {
	// HandleSlackInteractionBlockActionsFunc mocks the HandleSlackInteractionBlockActions method.
	HandleSlackInteractionBlockActionsFunc func(ctx context.Context, user slack.User, slackThread slack.Thread, actionID slack.ActionID, value string, triggerID string) error

	// HandleSlackInteractionViewSubmissionFunc mocks the HandleSlackInteractionViewSubmission method.
	HandleSlackInteractionViewSubmissionFunc func(ctx context.Context, user slack.User, callbackID slack.CallbackID, metadata string, values slack.StateValue) error
	// contains filtered or unexported fields
}

SlackInteractionMock is a mock implementation of SlackInteraction.

func TestSomethingThatUsesSlackInteraction(t *testing.T) {

	// make and configure a mocked SlackInteraction
	mockedSlackInteraction := &SlackInteractionMock{
		HandleSlackInteractionBlockActionsFunc: func(ctx context.Context, user slack.User, slackThread slack.Thread, actionID slack.ActionID, value string, triggerID string) error {
			panic("mock out the HandleSlackInteractionBlockActions method")
		},
		HandleSlackInteractionViewSubmissionFunc: func(ctx context.Context, user slack.User, callbackID slack.CallbackID, metadata string, values slack.StateValue) error {
			panic("mock out the HandleSlackInteractionViewSubmission method")
		},
	}

	// use mockedSlackInteraction in code that requires SlackInteraction
	// and then make assertions.

}

func (*SlackInteractionMock) HandleSlackInteractionBlockActions

func (mock *SlackInteractionMock) HandleSlackInteractionBlockActions(ctx context.Context, user slack.User, slackThread slack.Thread, actionID slack.ActionID, value string, triggerID string) error

HandleSlackInteractionBlockActions calls HandleSlackInteractionBlockActionsFunc.

func (*SlackInteractionMock) HandleSlackInteractionBlockActionsCalls

func (mock *SlackInteractionMock) HandleSlackInteractionBlockActionsCalls() []struct {
	Ctx         context.Context
	User        slack.User
	SlackThread slack.Thread
	ActionID    slack.ActionID
	Value       string
	TriggerID   string
}

HandleSlackInteractionBlockActionsCalls gets all the calls that were made to HandleSlackInteractionBlockActions. Check the length with:

len(mockedSlackInteraction.HandleSlackInteractionBlockActionsCalls())

func (*SlackInteractionMock) HandleSlackInteractionViewSubmission

func (mock *SlackInteractionMock) HandleSlackInteractionViewSubmission(ctx context.Context, user slack.User, callbackID slack.CallbackID, metadata string, values slack.StateValue) error

HandleSlackInteractionViewSubmission calls HandleSlackInteractionViewSubmissionFunc.

func (*SlackInteractionMock) HandleSlackInteractionViewSubmissionCalls

func (mock *SlackInteractionMock) HandleSlackInteractionViewSubmissionCalls() []struct {
	Ctx        context.Context
	User       slack.User
	CallbackID slack.CallbackID
	Metadata   string
	Values     slack.StateValue
}

HandleSlackInteractionViewSubmissionCalls gets all the calls that were made to HandleSlackInteractionViewSubmission. Check the length with:

len(mockedSlackInteraction.HandleSlackInteractionViewSubmissionCalls())

type SlackTokenResponse

type SlackTokenResponse struct {
	OK          bool   `json:"ok"`
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	Scope       string `json:"scope"`
	BotUserID   string `json:"bot_user_id"`
	AppID       string `json:"app_id"`
	Team        struct {
		Name string `json:"name"`
		ID   string `json:"id"`
	} `json:"team"`
	Enterprise interface{} `json:"enterprise"`
	AuthedUser struct {
		ID          string `json:"id"`
		Scope       string `json:"scope"`
		AccessToken string `json:"access_token"`
		TokenType   string `json:"token_type"`
	} `json:"authed_user"`
	IDToken string `json:"id_token"`
	Error   string `json:"error"`
}

SlackTokenResponse represents the response from Slack token exchange

type TicketCreationOptions

type TicketCreationOptions struct {
	AlertIDs     []types.AlertID
	SlackThread  *slack.Thread
	Assignee     *slack.User
	Title        string
	Description  string
	FillMetadata bool // Whether to use LLM to fill metadata
	IsTest       bool // Whether this is a test ticket
}

TicketCreationOptions contains options for ticket creation

type TicketUpdateFunction

type TicketUpdateFunction func(ctx context.Context, ticket *ticket.Ticket) error

TicketUpdateFunction defines a function that updates a ticket

type UseCases

type UseCases struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *UseCases

func (*UseCases) Chat

func (x *UseCases) Chat(ctx context.Context, target *ticket.Ticket, message string) error

func (*UseCases) CreateManualTicket

func (uc *UseCases) CreateManualTicket(ctx context.Context, title, description string, user *slack.User) (*ticket.Ticket, error)

CreateManualTicket creates a ticket manually without associated alerts

func (*UseCases) CreateManualTicketWithTest

func (uc *UseCases) CreateManualTicketWithTest(ctx context.Context, title, description string, user *slack.User, isTest bool) (*ticket.Ticket, error)

CreateManualTicketWithTest creates a ticket manually without associated alerts with test flag

func (*UseCases) GetUserIcon

func (u *UseCases) GetUserIcon(ctx context.Context, userID string) ([]byte, string, error)

GetUserIcon returns the user's icon image data via Slack service

func (*UseCases) GetUserProfile

func (u *UseCases) GetUserProfile(ctx context.Context, userID string) (string, error)

GetUserProfile returns the user's profile name via Slack service

func (*UseCases) HandleAlert

func (uc *UseCases) HandleAlert(ctx context.Context, schema types.AlertSchema, alertData any) ([]*alert.Alert, error)

func (*UseCases) HandleSalvageRefresh

func (uc *UseCases) HandleSalvageRefresh(ctx context.Context, user slack.User, metadata string, values slack.StateValue, viewID string) error

func (*UseCases) HandleSlackAppMention

func (uc *UseCases) HandleSlackAppMention(ctx context.Context, slackMsg slack.Message) error

HandleSlackAppMention handles a slack app mention event. It will dispatch a slack action to the alert.

func (*UseCases) HandleSlackInteractionBlockActions

func (uc *UseCases) HandleSlackInteractionBlockActions(ctx context.Context, slackUser slack.User, slackThread slack.Thread, actionID slack.ActionID, value, triggerID string) error

HandleSlackInteractionBlockActions handles a slack interaction block action.

func (*UseCases) HandleSlackInteractionViewSubmission

func (uc *UseCases) HandleSlackInteractionViewSubmission(ctx context.Context, slackUser slack.User, callbackID slack.CallbackID, metadata string, values slack.StateValue) error

func (*UseCases) HandleSlackMessage

func (uc *UseCases) HandleSlackMessage(ctx context.Context, slackMsg slack.Message) error

HandleSlackMessage handles a message from a slack user. It saves the message as an alert comment if the message is in the Alert thread.

func (*UseCases) UpdateMultipleTicketsStatus

func (uc *UseCases) UpdateMultipleTicketsStatus(ctx context.Context, ticketIDs []types.TicketID, status types.TicketStatus) ([]*ticket.Ticket, error)

UpdateMultipleTicketsStatus updates multiple tickets' status

func (*UseCases) UpdateTicket

func (uc *UseCases) UpdateTicket(ctx context.Context, ticketID types.TicketID, title, description string, user *slack.User) (*ticket.Ticket, error)

UpdateTicket updates a ticket's title and description

func (*UseCases) UpdateTicketConclusion

func (uc *UseCases) UpdateTicketConclusion(ctx context.Context, ticketID types.TicketID, conclusion types.AlertConclusion, reason string) (*ticket.Ticket, error)

UpdateTicketConclusion updates a ticket's conclusion and reason

func (*UseCases) UpdateTicketStatus

func (uc *UseCases) UpdateTicketStatus(ctx context.Context, ticketID types.TicketID, status types.TicketStatus) (*ticket.Ticket, error)

UpdateTicketStatus updates a ticket's status

Jump to

Keyboard shortcuts

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