-
Notifications
You must be signed in to change notification settings - Fork 0
/
okteto.go
57 lines (47 loc) · 1.28 KB
/
okteto.go
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
50
51
52
53
54
55
56
57
package registry
import (
"context"
"fmt"
"os"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/ko/pkg/publish"
"github.com/pkg/errors"
)
type Okteto struct {
registryUrl string
namespace string
username string
token string
}
func (this *Okteto) Init(ctx context.Context) error {
registryUrl, exists := os.LookupEnv("OKTETO_REGISTRY_URL")
if !exists {
return errors.New("Failed getting Okteto's registry: OKTETO_REGISTRY_URL not set")
}
this.registryUrl = registryUrl
namespace, exists := os.LookupEnv("OKTETO_NAMESPACE")
if !exists {
return errors.New("Failed getting Okteto's registry: OKTETO_NAMESPACE not set")
}
this.namespace = namespace
username, exists := os.LookupEnv("OKTETO_USERNAME")
if !exists {
return errors.New("Failed getting Okteto's registry: OKTETO_USERNAME not set")
}
this.username = username
token, exists := os.LookupEnv("OKTETO_TOKEN")
if !exists {
return errors.New("Failed getting Okteto's registry: OKTETO_TOKEN not set")
}
this.token = token
return nil
}
func (this *Okteto) GetAuthOption() publish.Option {
return publish.WithAuth(&authn.Basic{
Username: this.username,
Password: this.token,
})
}
func (this *Okteto) URL() string {
return fmt.Sprintf("%s/%s", this.registryUrl, this.namespace)
}