Documentation
¶
Overview ¶
Package controls provides functions for working with controls and subcontrols, including cloning and updating controls based on a standard set of controls.
Index ¶
- Variables
- func CleanImplementationGuidance(input *string) *models.ImplementationGuidance
- func CloneTrustCenterControls(ctx context.Context, m *generated.TrustCenterMutation) error
- func ControlFilterByStandard(ctx context.Context, opts CloneFilterOptions, std *generated.Standard) ([]predicate.Control, error)
- func CreateCloneControlInput(c *generated.Control, programID *string, orgID string) (generated.CreateControlInput, bool)
- func CreateCloneSubcontrolInput(subcontrol *generated.Subcontrol, orgID string, clone SubcontrolToCreate) *generated.CreateSubcontrolInput
- func CreateRevisionUpdateInput(c *generated.Control) generated.UpdateControlInput
- func CreateSubcontrolRevisionUpdateInput(sc *generated.Subcontrol, standardRevision *string) generated.UpdateSubcontrolInput
- func FilterByStandard(opts CloneFilterOptions) bool
- func GetControlIDFromRefCode(refCode string, controls []*generated.Control) (*string, bool)
- func HasRevisionChanged(existingRevision *string, standardRevision string) bool
- func StandardFilter(opts CloneFilterOptions) []predicate.Standard
- type CloneFilterOptions
- type CloneOption
- type CloneOptions
- type Cloner
- type ControlToUpdate
- type SubcontrolToCreate
Constants ¶
This section is empty.
Variables ¶
var ( // TrustCenterFrameworkName is the name of the framework the trust center standard belongs to, used in conjunction with trustCenterStandardShortName to identify controls that should be flagged as trust center controls during clone TrustCenterFrameworkName = "openlane-trust-center" // StandardTrustCenterFrameworkName is the name of the fremework the default standards go to StandardTrustCenterFrameworkName = "openlane-standard" )
var ( // ErrStandardNotFound is the error message returned when a standard cannot be found based on the provided filter options during control cloning ErrStandardNotFound = errors.New("standard not found, unable to clone controls") )
Functions ¶
func CleanImplementationGuidance ¶
func CleanImplementationGuidance(input *string) *models.ImplementationGuidance
CleanImplementationGuidance cleans and formats the implementation guidance input by splitting on new lines and trimming spaces
func CloneTrustCenterControls ¶
func CloneTrustCenterControls(ctx context.Context, m *generated.TrustCenterMutation) error
CloneTrustCenterControl clones the trust center controls and assumes the the user has the trust center module already this is intended to be called from an internal-hook when a trust center is created
func ControlFilterByStandard ¶
func ControlFilterByStandard(ctx context.Context, opts CloneFilterOptions, std *generated.Standard) ([]predicate.Control, error)
ControlFilterByStandard returns the predicate to filter controls by standard and other filter options to return the correct controls to clone
func CreateCloneControlInput ¶
func CreateCloneControlInput(c *generated.Control, programID *string, orgID string) (generated.CreateControlInput, bool)
CreateCloneControlInput creates a CreateControlInput from the given control that is being cloned and returns the input, the standard ID that was set, and whether the control is a trust center control
func CreateCloneSubcontrolInput ¶
func CreateCloneSubcontrolInput(subcontrol *generated.Subcontrol, orgID string, clone SubcontrolToCreate) *generated.CreateSubcontrolInput
CreateCloneSubcontrolInput creates a CreateSubcontrolInput from the given subcontrol that is being cloned
func CreateRevisionUpdateInput ¶
func CreateRevisionUpdateInput(c *generated.Control) generated.UpdateControlInput
CreateRevisionUpdateInput creates an UpdateControlInput from the given control that is being updated for a revision change
func CreateSubcontrolRevisionUpdateInput ¶
func CreateSubcontrolRevisionUpdateInput(sc *generated.Subcontrol, standardRevision *string) generated.UpdateSubcontrolInput
CreateSubcontrolRevisionUpdateInput creates an UpdateSubcontrolInput from the given subcontrol that is being updated for a revision change
func FilterByStandard ¶
func FilterByStandard(opts CloneFilterOptions) bool
FilterByStandard returns true if the filter options contain a standardID or standardShortName
func GetControlIDFromRefCode ¶
GetControlIDFromRefCode searches for a control ID by ref code or alias in the provided controls returns the control ID and a boolean indicating if it is a subcontrol or not
func HasRevisionChanged ¶
HasRevisionChanged checks if the revision of the control has changed compared to the standard revision
func StandardFilter ¶
func StandardFilter(opts CloneFilterOptions) []predicate.Standard
StandardFilter returns the predicate to filter by standard based on the filter options
Types ¶
type CloneFilterOptions ¶
type CloneFilterOptions struct {
// StandardID of the standard to filter the controls by
StandardID *string
// StandardShortName is the short name of the standard to filter the controls by
StandardShortName *string
// StandardFrameworkName is the name of the framework the standard belongs to, used in conjunction with StandardShortName to filter controls by standard when cloning
StandardFrameworkName *string
// StandardVersion is the revision of the standard to filter the controls by, this is optional, if more than one revision exists and this is not provided, the most recent revision will be used
StandardVersion *string
// RefCodes is a list of RefCodes to filter the controls by
RefCodes []string
// Categories is a list of Categories to filter the controls by
Categories []string
}
CloneFilterOptions holds the filter options for cloning controls
type CloneOption ¶
type CloneOption func(*CloneOptions)
CloneOption is a function type that modifies the CloneOptions
func WithOrgID ¶
func WithOrgID(orgID string) CloneOption
WithOrgID sets the OrgID in the CloneOptions
func WithPool ¶
func WithPool(pool *gala.Pool) CloneOption
WithPool clones the controls in parallel on the pool, a nil pool clones them one at a time for callers inside a transaction
func WithProgramID ¶
func WithProgramID(programID string) CloneOption
WithProgramID sets the ProgramID in the CloneOptions
type CloneOptions ¶
type CloneOptions struct {
// contains filtered or unexported fields
}
CloneOptions holds the options for cloning controls
type Cloner ¶
type Cloner struct {
// DB reads existing rows and creates the copies
DB *generated.Client
// Pool creates the copies in parallel, nil creates them one at a time for callers inside a transaction
Pool *gala.Pool
// OrgID is the organization the controls are copied into, empty uses the organization on the context
OrgID string
// RequiredModules are the modules the organization needs for control operations, nil skips the check
RequiredModules []models.OrgModule
// SkipProgramAccess skips the caller's edit check on the program, for callers that created the program themselves
SkipProgramAccess bool
}
Cloner copies controls into an organization, skipping controls the organization already has, linking them to the program instead, and refreshing those whose standard revision changed
func (Cloner) Controls ¶
func (c Cloner) Controls(ctx context.Context, controlsToClone []*generated.Control, programID *string) ([]*generated.Control, error)
Controls clones the given controls into the organization in the context and optionally links them to a program if programID is given if the controls already exist in the organization, they will not be cloned again but will be updated to link to the program if needed
func (Cloner) FromStandard ¶
func (c Cloner) FromStandard(ctx context.Context, filters CloneFilterOptions, programID *string) ([]*generated.Control, error)
FromStandard clones all controls from a standard into an organization if the controls already exist in the organization, they will not be cloned again
type ControlToUpdate ¶
ControlToUpdate is used to track existing controls that need to be updated due to changes in the revision of their connected standards
type SubcontrolToCreate ¶
type SubcontrolToCreate struct {
NewControlID string
RefControl *generated.Control
// contains filtered or unexported fields
}
SubcontrolToCreate is used to track which subcontrols need to be created for a given control
func CloneControls ¶
func CloneControls(ctx context.Context, client *generated.Client, controlsToClone []*generated.Control, opts ...CloneOption) ([]string, []SubcontrolToCreate, error)
CloneControls clones the given controls with the provided options and returns the IDs of the created controls, the subcontrols to create, and any errors that occurred during cloning