lib

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Answer

type Answer struct {
	Answer AnswerVal `json:"answer"`
	Notes  string    `json:"notes"`
}

Answer holds the 'hard' answer and any notes for a response to a question

func (*Answer) Validate

func (a *Answer) Validate(formats interface{}) error

Validate checks the answer value is valid

type AnswerVal

type AnswerVal string

AnswerVal defines possible answers to questions

const (
	No         AnswerVal = "No"
	Yes        AnswerVal = "Yes"
	NA         AnswerVal = "N/A"
	Unanswered AnswerVal = "Unanswered"
)

Possible values for AnswerVal

func (*AnswerVal) MarshalJSON

func (a *AnswerVal) MarshalJSON() ([]byte, error)

MarshalJSON serialises a AnswerVal to JSON

func (*AnswerVal) UnmarshalJSON

func (a *AnswerVal) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON creates a AnswerVal from JSON source

func (*AnswerVal) UnmarshalYAML

func (a *AnswerVal) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML creates an AnswerVal from YAML

type Level0

type Level0 struct {
	Short string `json:"short"`
	Long  string `json:"long"`
}

Level0 describes the state of a project that has not met Level 1 for the practice

type Plan

type Plan struct {
	Details   PlanDetails   `json:"details"`
	Responses PlanResponses `json:"responses"`
}

Plan captures the results of a questionnaire

func NewPlan

func NewPlan(details PlanDetails, responses PlanResponses, practices []Practice) Plan

NewPlan returns a Plan with its calculated maturity

func (*Plan) CalculateMaturity

func (plan *Plan) CalculateMaturity()

CalculateMaturity sets the plan's maturity based on its answers Only sets a maturity level for practices that apply and are fully answered

type PlanDetails

type PlanDetails struct {
	Projects  []string       `json:"projects"`
	Date      string         `json:"date"`
	Notes     string         `json:"notes"`
	Committed bool           `json:"committed"`
	Maturity  map[string]int `json:"maturity"` // keyed on practice ID, only practices with a calculable maturity are present
}

PlanDetails captures the high level responses

func (*PlanDetails) ContextValidate

func (pd *PlanDetails) ContextValidate(ctx context.Context, formats strfmt.Registry) error

ContextValidate is required for the generated API code, but the goswagger docs don't describe its purpose. It is related to validating read-only properties, see https://github.com/go-swagger/go-swagger/issues/2648

func (*PlanDetails) Validate

func (pd *PlanDetails) Validate(formats interface{}) error

Validate that the date is in YYYY-MM-DD format and at least one project ID is supplied.

type PlanResponses

type PlanResponses struct {
	PracticesVersion  string                      `json:"practicesVersion" yaml:"practicesVersion"`
	PracticeResponses map[string]PracticeResponse `json:"practiceResponses" yaml:"practiceResponses"` // keyed on practiceID
	// contains filtered or unexported fields
}

PlanResponses captures the responses to the practices

func (*PlanResponses) ContextValidate

func (responses *PlanResponses) ContextValidate(ctx context.Context, formats strfmt.Registry) error

ContextValidate is required for the generated API code, but the goswagger docs don't describe its purpose. It is related to validating read-only properties, see https://github.com/go-swagger/go-swagger/issues/2648

func (*PlanResponses) MissingAnswers

func (responses *PlanResponses) MissingAnswers(ignoreUnanswered bool) []string

MissingAnswers returns a list of task IDs in practices that don't have answers to all their questions in this plan ignoreUnanswered controls whether to count answers with a value of Unanswered as missing (if false) or only to report syntactically invalid responses that don't have any value for a task (if true).

func (*PlanResponses) MissingAnswersForPractice

func (responses *PlanResponses) MissingAnswersForPractice(practice Practice, ignoreUnanswered bool) (missing []string)

MissingAnswersForPractice returns a list of task IDs in practice that don't have answers to all their questions in this plan ignoreUnanswered controls whether to count answers with a value of Unanswered as missing (if false) or only to report syntactically invalid responses that don't have any value for a task (if true).

func (*PlanResponses) MissingPracticeAnswers

func (responses *PlanResponses) MissingPracticeAnswers() []string

MissingPracticeAnswers returns a list of practice IDs which are missing responses to practice-level questions

func (*PlanResponses) PracticeApplies

func (responses *PlanResponses) PracticeApplies(practice Practice) (bool, error)

PracticeApplies returns true if the plan indicates this practice applies If there is a missing or invalid response to a question, return an error

func (*PlanResponses) PracticeLevel

func (responses *PlanResponses) PracticeLevel(practice Practice) (int, error)

PracticeLevel returns the highest level in the given practice for which all tasks of the same or lower level are answered Yes or N/A It only considers answers in the response - if an answer is missing, it will be as if the task doesn't exist (or didn't have that question where they have multiple qs) Returns an error if there are unanswered questions.

func (*PlanResponses) ReadyToCommit

func (responses *PlanResponses) ReadyToCommit() (bool, []string)

ReadyToCommit return (true,[]) if all practice-level questions have been answered and applicable practices have answers to all of their task questions. Otherwise it returns false and a list of issues. Depends on the global Practices array being populated

func (*PlanResponses) TaskResult

func (responses *PlanResponses) TaskResult(practiceID string, taskID string) (AnswerVal, error)

TaskResult returns No if any answer for the task is No, N/A if all are N/A, Unanswered if any answer is such, and Yes otherwise (i.e. at least one Yes and the rest Yes or N/A)

func (*PlanResponses) Validate

func (responses *PlanResponses) Validate(formats interface{}) error

Validate that the responses to this Plan have answers to all questions. Note practice-applicability isn't considered: all questions need a response, even if it is "Unanswered" If the response doesn't have practices populated, no validation is done

type Practice

type Practice struct {
	ID        string     `json:"id"`
	Name      string     `json:"name"`
	Questions []Question `json:"questions"`
	Tasks     []Task     `json:"tasks"`
	Level0    Level0     `json:"level0"`
	Page      string     `json:"page"`      // Practice page URL
	Condition string     `json:"condition"` // how to interpret a practice's qualifying questions
	Notes     string     `json:"notes"`
}

Practice is the internal representation of a BeSec practice, including all of its tasks and questions

func (*Practice) CheckConstraints

func (p *Practice) CheckConstraints() error

CheckConstraints checks additional constraints on:

  • practice conditions
  • task and question IDs
  • task maturity levels

and also populates implicit question IDs

func (*Practice) ContextValidate

func (p *Practice) ContextValidate(ctx context.Context, formats strfmt.Registry) error

ContextValidate is a dummy function, required for the generated API code. Internally, practices are always valid, so we don't need to validate them prior to sending them.

func (Practice) EvaluateCondition

func (p Practice) EvaluateCondition(parameters map[string]interface{}) (bool, error)

EvaluateCondition evaluates the practice's condition with the provided named values

func (*Practice) FromDef

func (p *Practice) FromDef(md practiceDef) error

FromDef converts the file representation of a practice into the internal/API representation

func (Practice) TaskFromID

func (p Practice) TaskFromID(id string) (task Task, found bool)

TaskFromID returns the task with the corresponding id and true, or false if it wasn't found

func (Practice) TasksByLevel

func (p Practice) TasksByLevel() map[uint8][]Task

TasksByLevel returns all of the tasks in the practice indexed by their maturity level

func (*Practice) Validate

func (p *Practice) Validate(formats interface{}) error

Validate is a dummy function, required for the generated API code. Internally, practices are always valid, so we don't need to validate them prior to sending them.

type PracticeParser

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

PracticeParser parses practices within a specific directory

func NewPracticeParser

func NewPracticeParser(practicesDir string, schemaPath string, fs afero.Fs) PracticeParser

NewPracticeParser creates a PracticeParser for the specified directory if fs is nil, the OS fs is used

func (*PracticeParser) ParsePracticesDir

func (pp *PracticeParser) ParsePracticesDir() ([]Practice, error)

ParsePracticesDir parses all of the yaml files in the parser's practices dir

type PracticeResponse

type PracticeResponse struct {
	Practice map[string]Answer       `json:"practice"` // keyed on question ID
	Tasks    map[string]TaskResponse `json:"tasks"`    // keyed on task ID
}

PracticeResponse holds the responses to the practice and task questions

func (*PracticeResponse) Validate

func (mr *PracticeResponse) Validate(formats interface{}) error

Validate is a dummy function - we rely on the Plan being validated

type Question

type Question struct {
	ID    string `json:"id"` // mandatory for qualifying questions
	Text  string `json:"text"`
	NA    bool   `json:"na"`
	Other bool   `json:"other"`
}

Question represents both maturity questions and qualifying questions

type Task

type Task struct {
	ID          string     `json:"id"`
	Title       string     `json:"title"`
	Description string     `json:"description"`
	Level       uint8      `json:"level"`
	Questions   []Question `json:"questions"`
}

Task represents an individual task within a Practice

type TaskResponse

type TaskResponse struct {
	Answers    map[string]Answer `json:"answers"`
	Priority   bool              `json:"priority"`
	Issues     []string          `json:"issues"`
	References string            `json:"references"`
}

TaskResponse holds the answers to a task's questions and the optional extra info about a task's implementation

Jump to

Keyboard shortcuts

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