Skip to content

Commit

Permalink
Cleanup the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Yevhen Zavhorodnii committed Mar 31, 2024
1 parent 3a2528d commit b081d5b
Show file tree
Hide file tree
Showing 21 changed files with 0 additions and 841 deletions.
36 changes: 0 additions & 36 deletions pkg/security/types/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ Copyright © 2023 NAME HERE <EMAIL ADDRESS>
package types

import (
"encoding/json"
"fmt"
"gopkg.in/yaml.v3"
"strings"
)

Expand Down Expand Up @@ -59,40 +57,6 @@ func (what Authentication) Explain() string {
return AuthenticationTypeDescription[what].Description
}

func (what Authentication) MarshalJSON() ([]byte, error) {
return json.Marshal(what.String())
}

func (what *Authentication) UnmarshalJSON(data []byte) error {
var text string
unmarshalError := json.Unmarshal(data, &text)
if unmarshalError != nil {
return unmarshalError
}

value, findError := what.Find(text)
if findError != nil {
return findError
}

*what = value
return nil
}

func (what Authentication) MarshalYAML() (interface{}, error) {
return what.String(), nil
}

func (what *Authentication) UnmarshalYAML(node *yaml.Node) error {
value, findError := what.Find(node.Value)
if findError != nil {
return findError
}

*what = value
return nil
}

func (what Authentication) Find(value string) (Authentication, error) {
for index, description := range AuthenticationTypeDescription {
if strings.EqualFold(value, description.Name) {
Expand Down
36 changes: 0 additions & 36 deletions pkg/security/types/authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ Copyright © 2023 NAME HERE <EMAIL ADDRESS>
package types

import (
"encoding/json"
"fmt"
"gopkg.in/yaml.v3"
"strings"
)

Expand Down Expand Up @@ -46,40 +44,6 @@ func (what Authorization) Explain() string {
return AuthorizationTypeDescription[what].Description
}

func (what Authorization) MarshalJSON() ([]byte, error) {
return json.Marshal(what.String())
}

func (what *Authorization) UnmarshalJSON(data []byte) error {
var text string
unmarshalError := json.Unmarshal(data, &text)
if unmarshalError != nil {
return unmarshalError
}

value, findError := what.Find(text)
if findError != nil {
return findError
}

*what = value
return nil
}

func (what Authorization) MarshalYAML() (interface{}, error) {
return what.String(), nil
}

func (what *Authorization) UnmarshalYAML(node *yaml.Node) error {
value, findError := what.Find(node.Value)
if findError != nil {
return findError
}

*what = value
return nil
}

func (what Authorization) Find(value string) (Authorization, error) {
for index, description := range AuthorizationTypeDescription {
if strings.EqualFold(value, description.Name) {
Expand Down
36 changes: 0 additions & 36 deletions pkg/security/types/confidentiality.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ Copyright © 2023 NAME HERE <EMAIL ADDRESS>
package types

import (
"encoding/json"
"fmt"
"gopkg.in/yaml.v3"
"strings"
)

Expand Down Expand Up @@ -86,40 +84,6 @@ func (what Confidentiality) RatingStringInScale() string {
return result
}

func (what Confidentiality) MarshalJSON() ([]byte, error) {
return json.Marshal(what.String())
}

func (what *Confidentiality) UnmarshalJSON(data []byte) error {
var text string
unmarshalError := json.Unmarshal(data, &text)
if unmarshalError != nil {
return unmarshalError
}

value, findError := what.Find(text)
if findError != nil {
return findError
}

*what = value
return nil
}

func (what Confidentiality) MarshalYAML() (interface{}, error) {
return what.String(), nil
}

func (what *Confidentiality) UnmarshalYAML(node *yaml.Node) error {
value, findError := what.Find(node.Value)
if findError != nil {
return findError
}

*what = value
return nil
}

func (what Confidentiality) Find(value string) (Confidentiality, error) {
for index, description := range ConfidentialityTypeDescription {
if strings.EqualFold(value, description.Name) {
Expand Down
36 changes: 0 additions & 36 deletions pkg/security/types/criticality.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ Copyright © 2023 NAME HERE <EMAIL ADDRESS>
package types

import (
"encoding/json"
"fmt"
"gopkg.in/yaml.v3"
"strings"
)

Expand Down Expand Up @@ -86,40 +84,6 @@ func (what Criticality) RatingStringInScale() string {
return result
}

func (what Criticality) MarshalJSON() ([]byte, error) {
return json.Marshal(what.String())
}

func (what *Criticality) UnmarshalJSON(data []byte) error {
var text string
unmarshalError := json.Unmarshal(data, &text)
if unmarshalError != nil {
return unmarshalError
}

value, findError := what.Find(text)
if findError != nil {
return findError
}

*what = value
return nil
}

func (what Criticality) MarshalYAML() (interface{}, error) {
return what.String(), nil
}

func (what *Criticality) UnmarshalYAML(node *yaml.Node) error {
value, findError := what.Find(node.Value)
if findError != nil {
return findError
}

*what = value
return nil
}

func (what Criticality) Find(value string) (Criticality, error) {
for index, description := range CriticalityTypeDescription {
if strings.EqualFold(value, description.Name) {
Expand Down
36 changes: 0 additions & 36 deletions pkg/security/types/data_breach_probability.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ Copyright © 2023 NAME HERE <EMAIL ADDRESS>
package types

import (
"encoding/json"
"fmt"
"gopkg.in/yaml.v3"
"strings"
)

Expand Down Expand Up @@ -50,40 +48,6 @@ func (what DataBreachProbability) Title() string {
return [...]string{"Improbable", "Possible", "Probable"}[what]
}

func (what DataBreachProbability) MarshalJSON() ([]byte, error) {
return json.Marshal(what.String())
}

func (what *DataBreachProbability) UnmarshalJSON(data []byte) error {
var text string
unmarshalError := json.Unmarshal(data, &text)
if unmarshalError != nil {
return unmarshalError
}

value, findError := what.Find(text)
if findError != nil {
return findError
}

*what = value
return nil
}

func (what DataBreachProbability) MarshalYAML() (interface{}, error) {
return what.String(), nil
}

func (what *DataBreachProbability) UnmarshalYAML(node *yaml.Node) error {
value, findError := what.Find(node.Value)
if findError != nil {
return findError
}

*what = value
return nil
}

func (what DataBreachProbability) Find(value string) (DataBreachProbability, error) {
if len(value) == 0 {
return Possible, nil
Expand Down
46 changes: 0 additions & 46 deletions pkg/security/types/data_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ Copyright © 2023 NAME HERE <EMAIL ADDRESS>
package types

import (
"encoding/json"
"fmt"
"gopkg.in/yaml.v3"
"strings"
)

Expand Down Expand Up @@ -67,50 +65,6 @@ func (what DataFormat) Description() string {
"File input/uploads", "CSV tabular data"}[what]
}

func (what DataFormat) MarshalJSON() ([]byte, error) {
return json.Marshal(what.String())
}

func (what *DataFormat) UnmarshalJSON(data []byte) error {
var text string
unmarshalError := json.Unmarshal(data, &text)
if unmarshalError != nil {
return unmarshalError
}

value, findError := what.find(text)
if findError != nil {
return findError
}

*what = value
return nil
}

func (what DataFormat) MarshalYAML() (interface{}, error) {
return what.String(), nil
}

func (what *DataFormat) UnmarshalYAML(node *yaml.Node) error {
value, findError := what.find(node.Value)
if findError != nil {
return findError
}

*what = value
return nil
}

func (what DataFormat) find(value string) (DataFormat, error) {
for index, description := range DataFormatTypeDescription {
if strings.EqualFold(value, description.Name) {
return DataFormat(index), nil
}
}

return DataFormat(0), fmt.Errorf("unknown data format value %q", value)
}

type ByDataFormatAcceptedSort []DataFormat

func (what ByDataFormatAcceptedSort) Len() int { return len(what) }
Expand Down
31 changes: 0 additions & 31 deletions pkg/security/types/date.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,9 @@
package types

import (
"gopkg.in/yaml.v3"
"time"
)

type Date struct {
time.Time
}

func (what Date) MarshalJSON() ([]byte, error) {
return []byte(what.Format(`"2006-01-02"`)), nil
}

func (what *Date) UnmarshalJSON(bytes []byte) error {
date, parseError := time.Parse(`"2006-01-02"`, string(bytes))
if parseError != nil {
return parseError
}

what.Time = date

return nil
}

func (what Date) MarshalYAML() (interface{}, error) {
return what.Format(`2006-01-02`), nil
}

func (what *Date) UnmarshalYAML(node *yaml.Node) error {
date, parseError := time.Parse(`2006-01-02`, node.Value)
if parseError != nil {
return parseError
}

what.Time = date

return nil
}
Loading

0 comments on commit b081d5b

Please sign in to comment.