Skip to content

Commit

Permalink
feature(check): add rfc3339 timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
bzarboni1 committed Jun 3, 2024
1 parent fdc33e3 commit 57d7a9b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
13 changes: 8 additions & 5 deletions internal/pkg/types/checks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import "encoding/json"
import (
"encoding/json"
)

type CheckResult uint16

Expand Down Expand Up @@ -43,10 +45,11 @@ const (
)

type CheckReport struct {
EntityType string `json:"entity_type"`
EntityId string `json:"entity_id"`
Results map[CheckType]CheckResult `json:"results"`
Errors []CheckError `json:"errors"`
EntityType string `json:"entity_type"`
EntityId string `json:"entity_id"`
Timestamp string `json:"rfc3339_timestamp"`
Results map[CheckType]CheckResult `json:"results"`
Errors []CheckError `json:"errors"`
}

type ICheckable interface {
Expand Down
8 changes: 5 additions & 3 deletions internal/pkg/types/github/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"gh_foundations/internal/pkg/types"
"slices"
"time"

"github.com/google/go-github/v61/github"
)
Expand All @@ -16,14 +17,15 @@ type Organization struct {
func (o *Organization) Check(checkTypes []types.CheckType) types.CheckReport {
report := types.CheckReport{
EntityType: "github_organization",
EntityId: o.GetName(),
EntityId: o.GetLogin(),
Timestamp: time.Now().Format(time.RFC3339), // Syslog compliant timestamp
Results: make(map[types.CheckType]types.CheckResult),
Errors: []types.CheckError{},
}
for _, t := range checkTypes {
switch t {
case types.GoCGuardrails:
r, err := o.GoCGaurdrailsCompliant()
r, err := o.GoCGuardrailsCompliant()
if err != nil {
report.Errors = append(report.Errors, *err)
}
Expand All @@ -36,7 +38,7 @@ func (o *Organization) Check(checkTypes []types.CheckType) types.CheckReport {
}

// Custom repository roles for an organization need to be accessed separately from settings
func (o *Organization) GoCGaurdrailsCompliant() (types.CheckResult, *types.CheckError) {
func (o *Organization) GoCGuardrailsCompliant() (types.CheckResult, *types.CheckError) {
var allErrors error
violations := make(map[string]string)
checks := []func(org *Organization) (string, error){
Expand Down
6 changes: 4 additions & 2 deletions internal/pkg/types/github/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"gh_foundations/internal/pkg/types"
"reflect"
"time"

"github.com/google/go-github/v61/github"
)
Expand All @@ -19,13 +20,14 @@ func (r *Repository) Check(checkTypes []types.CheckType) types.CheckReport {
report := types.CheckReport{
EntityType: "github_repository",
EntityId: r.slug,
Timestamp: time.Now().Format(time.RFC3339), // Syslog compliant timestamp
Results: make(map[types.CheckType]types.CheckResult),
Errors: []types.CheckError{},
}
for _, t := range checkTypes {
switch t {
case types.GoCGuardrails:
r, err := r.GoCGaurdrailsCompliant()
r, err := r.GoCGuardrailsCompliant()
if err != nil {
report.Errors = append(report.Errors, *err)
}
Expand All @@ -37,7 +39,7 @@ func (r *Repository) Check(checkTypes []types.CheckType) types.CheckReport {
return report
}

func (r *Repository) GoCGaurdrailsCompliant() (types.CheckResult, *types.CheckError) {
func (r *Repository) GoCGuardrailsCompliant() (types.CheckResult, *types.CheckError) {
var allErrors error
violations := make(map[string]string)
checks := []func(repo *Repository) (string, error) {
Expand Down

0 comments on commit 57d7a9b

Please sign in to comment.