-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support multiple locations for schemas and policies
also check and enforce linting
- Loading branch information
Showing
238 changed files
with
235 additions
and
51,555 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[*.go] | ||
ij_any_blank_lines_after_imports = 1 | ||
ij_go_add_parentheses_for_single_import = true | ||
ij_go_GROUP_CURRENT_PROJECT_IMPORTS = true | ||
ij_go_group_stdlib_imports = true | ||
ij_go_import_sorting = gofmt | ||
ij_go_move_all_imports_in_one_declaration = true | ||
ij_go_move_all_stdlib_imports_in_one_group = true | ||
ij_go_remove_redundant_import_aliases = true | ||
ij_go_use_back_quotes_for_imports = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
exitCode=0 | ||
message=$1 | ||
|
||
# Log the actual diff for debugging purposes | ||
git diff --name-only | cat | ||
if ! git diff --exit-code --quiet; then | ||
echo "$message" | ||
exitCode=1 | ||
fi | ||
|
||
exit $exitCode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package gitlab_client | ||
|
||
import ( | ||
|
||
"github.com/rs/zerolog/log" | ||
"github.com/xanzy/go-gitlab" | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package local | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/rs/zerolog/log" | ||
|
||
"github.com/zapier/kubechecks/pkg/repo" | ||
) | ||
|
||
type ReposDirectory struct { | ||
paths map[string]string | ||
|
||
mutex sync.Mutex | ||
} | ||
|
||
func NewReposDirectory() *ReposDirectory { | ||
rd := &ReposDirectory{ | ||
paths: make(map[string]string), | ||
} | ||
|
||
return rd | ||
} | ||
|
||
func (rd *ReposDirectory) EnsurePath(ctx context.Context, tempRepoPath, location string) string { | ||
if location == "" { | ||
return "" | ||
} | ||
|
||
if strings.HasPrefix(location, "https://") || strings.HasPrefix(location, "http://") || strings.HasPrefix(location, "git@") { | ||
log.Debug().Str("location", location).Msg("registering remote repository") | ||
localPath := rd.Register(ctx, location) | ||
return localPath | ||
} | ||
|
||
schemaPath := filepath.Join(tempRepoPath, location) | ||
if stat, err := os.Stat(schemaPath); err == nil && stat.IsDir() { | ||
log.Debug().Str("location", location).Msg("registering in-repo path") | ||
return schemaPath | ||
} else { | ||
log.Warn().Str("location", location).Err(err).Msg("failed to find in-repo path") | ||
} | ||
|
||
return "" | ||
} | ||
|
||
func (rd *ReposDirectory) Register(ctx context.Context, cloneUrl string) string { | ||
var ( | ||
ok bool | ||
repoDir string | ||
) | ||
|
||
rd.mutex.Lock() | ||
defer rd.mutex.Unlock() | ||
|
||
repoDir, ok = rd.paths[cloneUrl] | ||
if ok { | ||
rd.fetchLatest() | ||
return repoDir | ||
} | ||
|
||
return rd.clone(ctx, cloneUrl) | ||
} | ||
|
||
func (rd *ReposDirectory) fetchLatest() { | ||
cmd := exec.Command("git", "pull") | ||
err := cmd.Run() | ||
if err != nil { | ||
log.Err(err).Msg("failed to pull latest") | ||
} | ||
} | ||
|
||
func (rd *ReposDirectory) clone(ctx context.Context, cloneUrl string) string { | ||
repoDir, err := os.MkdirTemp("/tmp", "schemas") | ||
if err != nil { | ||
log.Err(err).Msg("failed to make temp dir") | ||
return "" | ||
} | ||
|
||
r := repo.Repo{CloneURL: cloneUrl} | ||
err = r.CloneRepoLocal(ctx, repoDir) | ||
if err != nil { | ||
log.Err(err).Str("clone-url", cloneUrl).Msg("failed to clone repository") | ||
return "" | ||
} | ||
|
||
rd.paths[cloneUrl] = repoDir | ||
return repoDir | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.