-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
87 lines (74 loc) · 1.49 KB
/
config.go
File metadata and controls
87 lines (74 loc) · 1.49 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"gopkg.in/yaml.v2"
)
type Config struct {
APIVersion string `yaml:"apiVersion"`
Kind string
CurrentContext string `yaml:"current-context"`
Clusters []*ClusterEntry
Contexts []*ContextEntry
Users []*UserEntry
}
type UserEntry struct {
User *User
Name string
}
type User struct {
ClientCertificateData string `yaml:"client-certificate-data"`
ClientKeyData string `yaml:"client-key-data"`
}
type ContextEntry struct {
Context *Context
Name string
}
type Context struct {
Cluster string
User string
}
type ClusterEntry struct {
Cluster *Cluster
Name string
}
type Cluster struct {
CAData string `yaml:"certificate-authority-data"`
Server string
}
func Unmarshal(data []byte) (*Config, error) {
config := &Config{}
err := yaml.Unmarshal(data, &config)
if err != nil {
return nil, err
}
return config, nil
}
func NewConfig() *Config {
return &Config{
APIVersion: "v1",
Kind: "Config",
}
}
func (c *Config) GetClusterEntry(clusterName string) *ClusterEntry {
for _, cluster := range c.Clusters {
if cluster.Name == clusterName {
return cluster
}
}
return nil
}
func (c *Config) GetUserEntry(userName string) *UserEntry {
for _, user := range c.Users {
if user.Name == userName {
return user
}
}
return nil
}
func (c *Config) GetContextEntry(contextName string) *ContextEntry {
for _, context := range c.Contexts {
if context.Name == contextName {
return context
}
}
return nil
}