-
Notifications
You must be signed in to change notification settings - Fork 311
Expand file tree
/
Copy pathrunx.go
More file actions
49 lines (41 loc) · 973 Bytes
/
runx.go
File metadata and controls
49 lines (41 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package pkgtype
import (
"context"
"os"
"strings"
"go.jetify.com/pkg/runx/impl/registry"
"go.jetify.com/pkg/runx/impl/runx"
)
const (
RunXScheme = "runx"
RunXPrefix = RunXScheme + ":"
githubAPITokenVarName = "GITHUB_TOKEN"
// Keep for backwards compatibility
oldGithubAPITokenVarName = "DEVBOX_GITHUB_API_TOKEN"
)
var cachedRegistry *registry.Registry
func IsRunX(s string) bool {
return strings.HasPrefix(s, RunXPrefix)
}
func RunXClient() *runx.RunX {
return &runx.RunX{
GithubAPIToken: getGithubToken(),
}
}
func RunXRegistry(ctx context.Context) (*registry.Registry, error) {
if cachedRegistry == nil {
var err error
cachedRegistry, err = registry.NewLocalRegistry(ctx, getGithubToken())
if err != nil {
return nil, err
}
}
return cachedRegistry, nil
}
func getGithubToken() string {
token := os.Getenv(githubAPITokenVarName)
if token == "" {
token = os.Getenv(oldGithubAPITokenVarName)
}
return token
}