services

package
v0.0.0-...-87f5de6 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2020 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateAPIKey

func CreateAPIKey(ctx context.Context, db *database.Connection, userSlug string) (*dtos.APIKey, error)

func CreateEvidence

func CreateEvidence(ctx context.Context, db *database.Connection, contentStore contentstore.Store, i CreateEvidenceInput) (*dtos.Evidence, error)

func CreateQuery

func CreateQuery(ctx context.Context, db *database.Connection, i CreateQueryInput) (*dtos.Query, error)

CreateQuery inserts a new query into the database

func CreateTag

func CreateTag(ctx context.Context, db *database.Connection, i CreateTagInput) (*dtos.Tag, error)

func DeleteAuthScheme

func DeleteAuthScheme(ctx context.Context, db *database.Connection, i DeleteAuthSchemeInput) error

DeleteAuthScheme removes a user's association with a particular auth_scheme. This function applies for both admin related actions and plain user actions. If UserSlug is not provided, this will apply to the requesting user. If it is provided, then this triggers admin validation, and will apply to the provided user matching the given slug.

func DeleteAuthSchemeUsers

func DeleteAuthSchemeUsers(ctx context.Context, db *database.Connection, schemeCode string) error

DeleteAuthSchemeUsers removes/unlinks all users from a provided scheme

func DeleteEvidence

func DeleteEvidence(ctx context.Context, db *database.Connection, contentStore contentstore.Store, i DeleteEvidenceInput) error

func DeleteOperation

func DeleteOperation(ctx context.Context, db *database.Connection, contentStore contentstore.Store, slug string) error

func DeleteQuery

func DeleteQuery(ctx context.Context, db *database.Connection, i DeleteQueryInput) error

DeleteQuery removes a saved query for the given operation

func DeleteSessionsForUserSlug

func DeleteSessionsForUserSlug(ctx context.Context, db *database.Connection, userSlug string) error

DeleteSessionsForUserSlug finds all existing sessions for a given user, then removes them, effectively logging the user out of the service.

func DeleteTag

func DeleteTag(ctx context.Context, db *database.Connection, i DeleteTagInput) error

DeleteTag removes a tag and untags all evidence with the tag

func DeleteUser

func DeleteUser(ctx context.Context, db *database.Connection, slug string) error

DeleteUser needs some godocs

func ListAPIKeys

func ListAPIKeys(ctx context.Context, db *database.Connection, userSlug string) ([]*dtos.APIKey, error)

func ListAuthDetails

func ListAuthDetails(ctx context.Context, db *database.Connection, supportedAuthSchemes *[]dtos.SupportedAuthScheme) ([]*dtos.DetailedAuthenticationInfo, error)

func ListEvidenceForOperation

func ListEvidenceForOperation(ctx context.Context, db *database.Connection, i ListEvidenceForOperationInput) ([]*dtos.Evidence, error)

ListEvidenceForOperation retrieves all evidence for a particular operation id matching a particular set of filters (e.g. tag:some_tag)

func ListOperations

func ListOperations(ctx context.Context, db *database.Connection) ([]*dtos.Operation, error)

ListOperations retrieves a list of all operations that the contextual user can see

func ListOperationsForAdmin

func ListOperationsForAdmin(ctx context.Context, db *database.Connection) ([]*dtos.Operation, error)

ListOperationsForAdmin is a specialized version of ListOperations where no operations are filtered For use in admin screens only

func ListQueriesForOperation

func ListQueriesForOperation(ctx context.Context, db *database.Connection, operationSlug string) ([]*dtos.Query, error)

ListQueriesForOperation retrieves all saved queries for a given operation id

func ListTagDifference

ListTagDifference determines which tag values are common between two operations. This is done via relative comparison. That is, all of the tags in the "source" are compared against the "destination" returning only tags that are common, and tags that are in the source, but not in the destination. The opposite list (tags that exist in the destination, but not the source) is not generated.

func ListTagsForOperation

func ListTagsForOperation(ctx context.Context, db *database.Connection, i ListTagsForOperationInput) ([]*dtos.Tag, error)

func ListUsers

func ListUsers(ctx context.Context, db *database.Connection, i ListUsersInput) ([]*dtos.User, error)

func ListUsersForAdmin

ListUsersForAdmin retreives standard User (public) details, and aguments with some particular fields meant for admin review. For use in admin views only.

func ReadOperation

func ReadOperation(ctx context.Context, db *database.Connection, operationSlug string) (*dtos.Operation, error)

func ReadUser

func ReadUser(ctx context.Context, db *database.Connection, userSlug string) (*dtos.UserOwnView, error)

ReadUser retrieves a detailed view of a user. This is separate from the data retriving by listing users, or reading another user's profile (when not an admin)

func SanitizeOperationSlug

func SanitizeOperationSlug(slug string) string

SanitizeOperationSlug removes objectionable characters from a slug and returns the new slug. Current logic: only allow alphanumeric characters and hyphen, with hypen excluded at the start and end

func SetUserFlags

func SetUserFlags(ctx context.Context, db *database.Connection, i SetUserFlagsInput) error

SetUserFlags updates flags for the indicated user, namely: admin and disabled. Then removes all sessions for that user (logging them out)

NOTE: The flag is to _disable_ the user, which prevents access. To enable a user, set Disabled=false

func UpdateEvidence

func UpdateEvidence(ctx context.Context, db *database.Connection, contentStore contentstore.Store, i UpdateEvidenceInput) error

func UpdateQuery

func UpdateQuery(ctx context.Context, db *database.Connection, i UpdateQueryInput) error

UpdateQuery modifies a query for the given operation

func UpdateTag

func UpdateTag(ctx context.Context, db *database.Connection, i UpdateTagInput) error

UpdateTag updates a tag's name and color

Types

type AddEvidenceToFindingInput

type AddEvidenceToFindingInput struct {
	OperationSlug    string
	FindingUUID      string
	EvidenceToAdd    []string
	EvidenceToRemove []string
}

type CreateEvidenceInput

type CreateEvidenceInput struct {
	OperatorID    int64
	OperationSlug string
	Description   string
	Content       io.Reader
	ContentType   string
	TagIDs        []int64
	OccurredAt    time.Time
}

type CreateFindingInput

type CreateFindingInput struct {
	OperationSlug string
	Category      string
	Title         string
	Description   string
}

type CreateOperationInput

type CreateOperationInput struct {
	Slug    string
	OwnerID int64
	Name    string
}

type CreateQueryInput

type CreateQueryInput struct {
	OperationSlug string
	Name          string
	Query         string
	Type          string
}

CreateQueryInput provides a structure that holds the values needed to generate a new saved query

type CreateTagInput

type CreateTagInput struct {
	Name          string
	ColorName     string
	OperationSlug string
}

type CreateUserInput

type CreateUserInput struct {
	FirstName string
	LastName  string
	Slug      string
	Email     string
	Headless  bool
}

type CreateUserOutput

type CreateUserOutput struct {
	RealSlug string
	UserID   int64
}

func CreateHeadlessUser

func CreateHeadlessUser(ctx context.Context, db *database.Connection, i CreateUserInput) (CreateUserOutput, error)

CreateHeadlessUser is really just CreateUser. The difference here is that _headless_ users will not have authentication, and instead rely on user-impersonation and API keys for access.

func CreateUser

CreateUser generates an entry in the users table in the database. No more is done here, but it is expected that the caller will, at a minimum, also want to create an entry in the authentication tables, so that the user can actually log in.

Note: CreateUserInput.Slug is a _suggestion_, and it may be altered to ensure uniqueness.

Returns a structure containing both the true slug (i.e. what it was mangled to, if it was infact mangled), plus the associated user_id value

type DeleteAPIKeyInput

type DeleteAPIKeyInput struct {
	AccessKey string
	UserSlug  string
}

type DeleteAuthSchemeInput

type DeleteAuthSchemeInput struct {
	UserSlug   string
	SchemeName string
}

type DeleteEvidenceInput

type DeleteEvidenceInput struct {
	OperationSlug            string
	EvidenceUUID             string
	DeleteAssociatedFindings bool
}

type DeleteFindingInput

type DeleteFindingInput struct {
	OperationSlug string
	FindingUUID   string
}

type DeleteQueryInput

type DeleteQueryInput struct {
	OperationSlug string
	ID            int64
}

type DeleteTagInput

type DeleteTagInput struct {
	ID            int64
	OperationSlug string
}

type ListEvidenceForFindingInput

type ListEvidenceForFindingInput struct {
	OperationSlug string
	FindingUUID   string
}

type ListEvidenceForOperationInput

type ListEvidenceForOperationInput struct {
	OperationSlug string
	Filters       helpers.TimelineFilters
}

type ListFindingsForOperationInput

type ListFindingsForOperationInput struct {
	OperationSlug string
	Filters       helpers.TimelineFilters
}

type ListTagDifferenceForEvidenceInput

type ListTagDifferenceForEvidenceInput struct {
	ListTagsDifferenceInput
	SourceEvidenceUUID string
}

type ListTagsDifferenceInput

type ListTagsDifferenceInput struct {
	SourceOperationSlug      string
	DestinationOperationSlug string
}

type ListTagsForOperationInput

type ListTagsForOperationInput struct {
	OperationSlug string
}

type ListUsersForAdminInput

type ListUsersForAdminInput struct {
	UserFilter
	Pagination
	IncludeDeleted bool
}

type ListUsersForOperationInput

type ListUsersForOperationInput struct {
	Pagination
	UserFilter
	OperationSlug string
}

type ListUsersInput

type ListUsersInput struct {
	Query          string
	IncludeDeleted bool
}

type MoveEvidenceInput

type MoveEvidenceInput struct {
	SourceOperationSlug string
	EvidenceUUID        string
	TargetOperationSlug string
}

type Pagination

type Pagination struct {
	PageSize int64
	Page     int64

	TotalCount int64
	// contains filtered or unexported fields
}

func ParseRequestQueryPagination

func ParseRequestQueryPagination(dr dissectors.DissectedRequest, defaultMaxItems int64) Pagination

ParseRequestQueryPagination retreives the part of the request set aside for pagination Note that this retrieves the values and hopes for the best. Since this uses a DissectedRequest, it is the caller of the function to ensure no error occurred _after_ this has been called.

func (*Pagination) Select

func (p *Pagination) Select(ctx context.Context, db *database.Connection, resultSlice interface{}, sb sq.SelectBuilder) error

Select is a wrapper around database.Connection.Select. This performs a query that returns multiple rows. In addition, this counts the total number of rows matching this query, and saves the result inside the pagination structure.

This actually performs two queries: the intended query, plus a second query to discover the total number of matching rows. I think this works differently in other databases, but this seems to be the preferred route for mysql. See: https://dev.mysql.com/doc/refman/8.0/en/information-functions.html#function_found-rows for more details

Note: It is possible to have the initial query succeed and the count query to fail. In order to prevent odd issues, you should always do an error check before using the resulting value.

Note 2: This is really only useful for communicating size back to the enduser. For other pagination techniques, you may want to use LIMIT and OFFSET directly

func (*Pagination) SetMaxItems

func (p *Pagination) SetMaxItems(maxItems int64) *Pagination

SetMaxItems sets the maximum number of items that can be returned in a request/page. This must be called before Select to have any effect

func (*Pagination) WrapData

func (p *Pagination) WrapData(data interface{}) *dtos.PaginationWrapper

WrapData is a small helper to turn the desired content of a request into a pagination result set

type ReadEvidenceInput

type ReadEvidenceInput struct {
	OperationSlug string
	EvidenceUUID  string
	LoadPreview   bool
	LoadMedia     bool
}

type ReadEvidenceOutput

type ReadEvidenceOutput struct {
	UUID        string    `json:"uuid"`
	Description string    `json:"description"`
	ContentType string    `json:"contentType"`
	OccurredAt  time.Time `json:"occurredAt"`
	Preview     io.Reader `json:"-"`
	Media       io.Reader `json:"-"`
}

type ReadFindingInput

type ReadFindingInput struct {
	OperationSlug string
	FindingUUID   string
}

type SetUserFlagsInput

type SetUserFlagsInput struct {
	Slug     string
	Disabled *bool
	Admin    *bool
}

type SetUserOperationRoleInput

type SetUserOperationRoleInput struct {
	OperationSlug string
	UserSlug      string
	Role          policy.OperationRole
}

type UpdateEvidenceInput

type UpdateEvidenceInput struct {
	OperationSlug string
	EvidenceUUID  string
	Description   *string
	TagsToAdd     []int64
	TagsToRemove  []int64
	Content       io.Reader
}

type UpdateFindingInput

type UpdateFindingInput struct {
	OperationSlug string
	FindingUUID   string
	Category      string
	Title         string
	Description   string
	TicketLink    *string
	ReadyToReport bool
}

type UpdateOperationInput

type UpdateOperationInput struct {
	OperationSlug string
	Name          string
	Status        models.OperationStatus
}

type UpdateQueryInput

type UpdateQueryInput struct {
	OperationSlug string
	ID            int64
	Name          string
	Query         string
}

type UpdateTagInput

type UpdateTagInput struct {
	ID            int64
	OperationSlug string
	Name          string
	ColorName     string
}

type UpdateUserProfileInput

type UpdateUserProfileInput struct {
	UserSlug  string
	FirstName string
	LastName  string
	Email     string
}

type UserFilter

type UserFilter struct {
	NameParts  []string
	UsersTable string
}

UserFilter provides a mechanism to alter queries such that users are filtered

func ParseRequestQueryUserFilter

func ParseRequestQueryUserFilter(dr dissectors.DissectedRequest) UserFilter

ParseRequestQueryUserFilter generates a UserFilter object from a given request. This expects that filtering is specified by the query parameter "name"

func (*UserFilter) AddWhere

func (uf *UserFilter) AddWhere(sb *sq.SelectBuilder)

AddWhere adds to the given SelectBuilder a Where clause that will apply the filtering

Jump to

Keyboard shortcuts

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