Skip to content

Commit e856460

Browse files
committed
wip
1 parent ce63909 commit e856460

File tree

4 files changed

+20
-281
lines changed

4 files changed

+20
-281
lines changed

internal/plugin/git.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ import (
2323
"go.jetpack.io/pkg/filecache"
2424
)
2525

26-
var sshCache = filecache.New[[]byte]("devbox/plugin/ssh")
2726
var gitCache = filecache.New[[]byte]("devbox/plugin/git")
28-
var githubCache = filecache.New[[]byte]("devbox/plugin/github")
29-
var gitlabCache = filecache.New[[]byte]("devbox/plugin/gitlab")
30-
var bitbucketCache = filecache.New[[]byte]("devbox/plugin/bitbucket")
3127

3228
type gitPlugin struct {
3329
ref flake.Ref
@@ -177,15 +173,7 @@ func (p *gitPlugin) FileContent(subpath string) ([]byte, error) {
177173
}
178174

179175
switch p.ref.Type {
180-
case flake.TypeSSH:
181-
return sshCache.GetOrSet(location, process)
182-
case flake.TypeGitHub:
183-
return githubCache.GetOrSet(location, process)
184-
case flake.TypeGitLab:
185-
return gitlabCache.GetOrSet(location, process)
186-
case flake.TypeBitBucket:
187-
return bitbucketCache.GetOrSet(location, process)
188-
case flake.TypeGit:
176+
case flake.TypeSSH, flake.TypeGitHub, flake.TypeGitLab, flake.TypeBitBucket, flake.TypeGit:
189177
return gitCache.GetOrSet(location, process)
190178
default:
191179
slog.Error("Unable to handle flake ref type: " + p.ref.Type)

internal/plugin/update.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
package plugin
22

3-
import "go.jetpack.io/pkg/filecache"
4-
53
func Update() error {
6-
pluginCaches := []*filecache.Cache[[]byte]{githubCache, sshCache, gitlabCache, bitbucketCache}
7-
8-
for _, cache := range pluginCaches {
9-
err := cache.Clear()
10-
11-
if err != nil {
12-
return err
13-
}
14-
15-
}
16-
4+
gitCache.Clear()
175
return nil
186
}

nix/flake/flakeref.go

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
const (
1616
TypeIndirect = "indirect"
1717
TypePath = "path"
18+
TypeHttps = "https"
1819
TypeFile = "file"
1920
TypeSSH = "ssh"
2021
TypeGitHub = "github"
@@ -77,49 +78,6 @@ type Ref struct {
7778
Port int32 `json:port,omitempty`
7879
}
7980

80-
// TODO move `ParseRef` to the unit test file. It isn't used anywhere else
81-
82-
// ParseRef parses a raw flake reference. Nix supports a variety of flake ref
83-
// formats, and isn't entirely consistent about how it parses them. ParseRef
84-
// attempts to mimic how Nix parses flake refs on the command line. The raw ref
85-
// can be one of the following:
86-
//
87-
// - Indirect reference such as "nixpkgs" or "nixpkgs/unstable".
88-
// - Path-like reference such as "./flake" or "/path/to/flake". They must
89-
// start with a '.' or '/' and not contain a '#' or '?'.
90-
// - URL-like reference which must be a valid URL with any special characters
91-
// encoded. The scheme can be any valid flake ref type except for mercurial,
92-
// gitlab, and sourcehut.
93-
//
94-
// ParseRef does not guarantee that a parsed flake ref is valid or that an
95-
// error indicates an invalid flake ref. Use the "nix flake metadata" command or
96-
// the builtins.parseFlakeRef Nix function to validate a flake ref.
97-
func ParseRef(ref string) (Ref, error) {
98-
if ref == "" {
99-
return Ref{}, redact.Errorf("empty flake reference")
100-
}
101-
102-
// Handle path-style references first.
103-
parsed := Ref{}
104-
if ref[0] == '.' || ref[0] == '/' {
105-
if strings.ContainsAny(ref, "?#") {
106-
// The Nix CLI does seem to allow paths with a '?'
107-
// (contrary to the manual) but ignores everything that
108-
// comes after it. This is a bit surprising, so we just
109-
// don't allow it at all.
110-
return Ref{}, redact.Errorf("path-style flake reference %q contains a '?' or '#'", ref)
111-
}
112-
parsed.Type = TypePath
113-
parsed.Path = ref
114-
return parsed, nil
115-
}
116-
parsed, fragment, err := parseURLRef(ref)
117-
if fragment != "" {
118-
return Ref{}, redact.Errorf("flake reference %q contains a URL fragment", ref)
119-
}
120-
return parsed, err
121-
}
122-
12381
func parseURLRef(ref string) (parsed Ref, fragment string, err error) {
12482
// A good way to test how Nix parses a flake reference is to run:
12583
//

0 commit comments

Comments
 (0)