mirror of
https://github.com/outbackdingo/proxmox-cloud-controller-manager.git
synced 2026-01-27 10:20:13 +00:00
feat: can use user/password
Some method in Proxmox required root permissions (account). So we can pass it through cluster config. Signed-off-by: Serge Logvinov <serge.logvinov@sinextra.dev>
This commit is contained in:
@@ -50,7 +50,13 @@ func NewCluster(config *ClustersConfig, hclient *http.Client) (*Cluster, error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
client.SetAPIToken(cfg.TokenID, cfg.TokenSecret)
|
if cfg.Username != "" && cfg.Password != "" {
|
||||||
|
if err := client.Login(cfg.Username, cfg.Password, ""); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
client.SetAPIToken(cfg.TokenID, cfg.TokenSecret)
|
||||||
|
}
|
||||||
|
|
||||||
proxmox[cfg.Region] = client
|
proxmox[cfg.Region] = client
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ type ClustersConfig struct {
|
|||||||
Insecure bool `yaml:"insecure,omitempty"`
|
Insecure bool `yaml:"insecure,omitempty"`
|
||||||
TokenID string `yaml:"token_id,omitempty"`
|
TokenID string `yaml:"token_id,omitempty"`
|
||||||
TokenSecret string `yaml:"token_secret,omitempty"`
|
TokenSecret string `yaml:"token_secret,omitempty"`
|
||||||
|
Username string `yaml:"username,omitempty"`
|
||||||
|
Password string `yaml:"password,omitempty"`
|
||||||
Region string `yaml:"region,omitempty"`
|
Region string `yaml:"region,omitempty"`
|
||||||
} `yaml:"clusters,omitempty"`
|
} `yaml:"clusters,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -48,12 +50,12 @@ func ReadCloudConfig(config io.Reader) (ClustersConfig, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for idx, c := range cfg.Clusters {
|
for idx, c := range cfg.Clusters {
|
||||||
if c.TokenID == "" {
|
if c.Username != "" && c.Password != "" {
|
||||||
return ClustersConfig{}, fmt.Errorf("cluster #%d: token_id is required", idx+1)
|
if c.TokenID != "" || c.TokenSecret != "" {
|
||||||
}
|
return ClustersConfig{}, fmt.Errorf("cluster #%d: token_id and token_secret are not allowed when username and password are set", idx+1)
|
||||||
|
}
|
||||||
if c.TokenSecret == "" {
|
} else if c.TokenID == "" || c.TokenSecret == "" {
|
||||||
return ClustersConfig{}, fmt.Errorf("cluster #%d: token_secret is required", idx+1)
|
return ClustersConfig{}, fmt.Errorf("cluster #%d: either username and password or token_id and token_secret are required", idx+1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Region == "" {
|
if c.Region == "" {
|
||||||
|
|||||||
@@ -64,6 +64,19 @@ clusters:
|
|||||||
token_id: "user!token-id"
|
token_id: "user!token-id"
|
||||||
token_secret: "secret"
|
token_secret: "secret"
|
||||||
region: cluster-1
|
region: cluster-1
|
||||||
|
`))
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.NotNil(t, cfg)
|
||||||
|
assert.Equal(t, 1, len(cfg.Clusters))
|
||||||
|
|
||||||
|
// Valid config with one cluster (username/password)
|
||||||
|
cfg, err = cluster.ReadCloudConfig(strings.NewReader(`
|
||||||
|
clusters:
|
||||||
|
- url: https://example.com
|
||||||
|
insecure: false
|
||||||
|
username: "user@pam"
|
||||||
|
password: "secret"
|
||||||
|
region: cluster-1
|
||||||
`))
|
`))
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.NotNil(t, cfg)
|
assert.NotNil(t, cfg)
|
||||||
|
|||||||
Reference in New Issue
Block a user