Skip to content

Commit

Permalink
Don't allow certain values to be an import.git revision
Browse files Browse the repository at this point in the history
  • Loading branch information
ptodev committed Sep 10, 2024
1 parent fefafa8 commit 9126f5a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions internal/runtime/internal/importsource/import_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/grafana/alloy/internal/component"
"github.com/grafana/alloy/internal/runtime/logging/level"
"github.com/grafana/alloy/internal/vcs"
"github.com/grafana/alloy/syntax"
"github.com/grafana/alloy/syntax/vm"
)

Expand Down Expand Up @@ -55,6 +56,21 @@ var DefaultGitArguments = GitArguments{
PullFrequency: time.Minute,
}

var (
_ syntax.Validator = (*GitArguments)(nil)
_ syntax.Defaulter = (*GitArguments)(nil)
)

// Validate implements syntax.Validator.
func (args *GitArguments) Validate() error {
switch args.Revision {
case "HEAD", "FETCH_HEAD", "ORIG_HEAD", "MERGE_HEAD", "CHERRY_PICK_HEAD":
return fmt.Errorf("revision cannot be a special git reference such as HEAD, FETCH_HEAD, ORIG_HEAD, MERGE_HEAD, or CHERRY_PICK_HEAD")
}

return nil
}

// SetToDefault implements syntax.Defaulter.
func (args *GitArguments) SetToDefault() {
*args = DefaultGitArguments
Expand Down

0 comments on commit 9126f5a

Please sign in to comment.