Skip to content

Allow git for snmp config file#877

Open
i3149 wants to merge 2 commits intomainfrom
allow-git-clone-ssh
Open

Allow git for snmp config file#877
i3149 wants to merge 2 commits intomainfrom
allow-git-clone-ssh

Conversation

@i3149
Copy link
Contributor

@i3149 i3149 commented Feb 17, 2026

KT_GITHUB_ACCESS_TOKEN=$PERSONAL_ACCESS_TOKEN ./bin/ktranslate -snmp git://Users/pye/src/configtest/foo/snmp.yaml

Allow a system like this where the snmp.yaml file is pulled from a remote git repo. No need to have KT_GITHUB_ACCESS_TOKEN defined if not needed.

Also allows KT_GITHUB_ACCESS_TOKEN to be defined when pulling snmp profiles from a private repo.

Closes #875 #869

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for loading SNMP config (and MIB profiles) from git-backed sources, including optional GitHub token auth via KT_GITHUB_ACCESS_TOKEN.

Changes:

  • Add git:// scheme handling to SNMP util LoadFile/WriteFile.
  • Add BasicAuth support for cloning MIB profiles from git when a token is present.
  • Update Go module dependencies (notably introducing go-git/v6 and related transitive bumps).

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 8 comments.

File Description
pkg/inputs/snmp/util/file.go Adds git scheme support for config load/write via cloning a repo and reading a file.
pkg/inputs/snmp/mibs/git.go Adds token-based auth for cloning profile repositories.
go.mod Adds go-git/v6 and updates several dependency versions.
go.sum Updates dependency checksums in line with go.mod changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 32 to 43
switch u.Scheme {
case "http", "https":
return loadFromHttp(ctx, file)
case "s3":
return loadFromS3(ctx, u, getS3Downloader())
case "s3m":
return loadFromS3(ctx, u, getMockS3Client())
case "git":
return loadFromGit(ctx, u)
default:
return ioutil.ReadFile(file)
}
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding git support introduces new behavior in LoadFile/WriteFile, but the existing unit tests in file_test.go don’t cover the git:// scheme. Please add tests covering at least the URL parsing behavior and the expected write semantics (read-only error vs. commit).

Copilot uses AI. Check for mistakes.

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
githttp "github.com/go-git/go-git/v6/plumbing/transport/http"
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file uses go-git/v5 (git.PlainCloneContext) but imports plumbing/transport/http from go-git/v6. The BasicAuth type won’t satisfy the v5 transport.AuthMethod interface due to different module paths, so this will not compile. Import the v5 transport/http package (or migrate fully to v6).

Suggested change
githttp "github.com/go-git/go-git/v6/plumbing/transport/http"
githttp "github.com/go-git/go-git/v5/plumbing/transport/http"

Copilot uses AI. Check for mistakes.
github.com/elliotchance/orderedmap v1.4.0
github.com/fsnotify/fsnotify v1.6.0
github.com/go-git/go-git/v5 v5.16.5
github.com/go-git/go-git/v6 v6.0.0-20260216160506-e6a3f881772f
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

github.com/go-git/go-git/v6 is added as a direct dependency, but the code in this PR still uses go-git/v5 APIs. Mixing v5 and v6 will either fail to compile (auth types) or bloat deps; prefer sticking to v5 everywhere here or doing a dedicated migration PR to v6.

Suggested change
github.com/go-git/go-git/v6 v6.0.0-20260216160506-e6a3f881772f

Copilot uses AI. Check for mistakes.
Comment on lines +171 to +172
file := path.Join(dir, filePath)
return ioutil.ReadFile(file)
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filePath comes from the URL and is joined directly; values like ../.. can escape the temp clone directory and read arbitrary files. Use a secure join (e.g. filepath-securejoin) or clean+validate the path stays within dir before reading.

Copilot uses AI. Check for mistakes.
_, err = git.PlainCloneContext(ctx, dir, false, &git.CloneOptions{
URL: gitRepo,
Auth: auth,
Progress: os.Stdout,
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cloning with Progress: os.Stdout will emit noisy output in library/daemon contexts and can interfere with CLI output. Prefer wiring this to your logger, making it configurable, or using io.Discard by default.

Suggested change
Progress: os.Stdout,
Progress: io.Discard,

Copilot uses AI. Check for mistakes.
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/go-git/go-git/v5"
githttp "github.com/go-git/go-git/v6/plumbing/transport/http"
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git.CloneOptions.Auth comes from go-git/v5, but this file imports plumbing/transport/http from go-git/v6. Those types are not assignment-compatible, so this won’t compile. Use the v5 plumbing/transport/http package (or upgrade all go-git imports consistently to v6).

Suggested change
githttp "github.com/go-git/go-git/v6/plumbing/transport/http"
githttp "github.com/go-git/go-git/v5/plumbing/transport/http"

Copilot uses AI. Check for mistakes.
// noop, assume that file is not to be changed.
// @todo, allow a commit after disco?
func writeToGit(ctx context.Context, url *url.URL, payload []byte) error {
return nil
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writeToGit is wired into WriteFile for the git:// scheme but always returns nil without persisting anything. This makes callers believe the config was saved when it wasn’t; return an explicit error (e.g. “git scheme is read-only”) or implement the write+commit behavior.

Suggested change
return nil
return fmt.Errorf("git scheme is read-only: cannot write to %s", url.String())

Copilot uses AI. Check for mistakes.
Comment on lines +144 to +152
pts := strings.Split(url.String(), "/")
gitRepo := ""
filePath := ""
if len(pts) >= 6 {
gitRepo = "https://" + strings.Join(pts[2:5], "/") + ".git"
filePath = strings.Join(pts[5:], "/")
} else {
return nil, fmt.Errorf("Invalid git url path: %s", url.String())
}
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Git URL parsing here doesn’t match the PR description example (git://Users/... local path). With the current split logic this becomes https://Users/pye/src.git, which is invalid for a local repo. Consider using url.Host + url.Path (or supporting git:///absolute/path/... for local), and document the expected git URL format.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow snmp config file to be downloaded from a remote location.

1 participant