forked from openshift/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
platformcredscheck.go
64 lines (55 loc) · 1.76 KB
/
platformcredscheck.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
58
59
60
61
62
63
64
package installconfig
import (
"fmt"
"github.com/gophercloud/utils/openstack/clientconfig"
"github.com/openshift/installer/pkg/asset"
awsconfig "github.com/openshift/installer/pkg/asset/installconfig/aws"
"github.com/openshift/installer/pkg/types/aws"
"github.com/openshift/installer/pkg/types/libvirt"
"github.com/openshift/installer/pkg/types/none"
"github.com/openshift/installer/pkg/types/openstack"
"github.com/openshift/installer/pkg/types/vsphere"
"github.com/pkg/errors"
)
// PlatformCredsCheck is an asset that checks the platform credentials, asks for them or errors out if invalid
// the cluster.
type PlatformCredsCheck struct {
}
var _ asset.Asset = (*PlatformCredsCheck)(nil)
// Dependencies returns the dependencies for PlatformCredsCheck
func (a *PlatformCredsCheck) Dependencies() []asset.Asset {
return []asset.Asset{
&InstallConfig{},
}
}
// Generate queries for input from the user.
func (a *PlatformCredsCheck) Generate(dependencies asset.Parents) error {
ic := &InstallConfig{}
dependencies.Get(ic)
var err error
platform := ic.Config.Platform.Name()
switch platform {
case aws.Name:
ssn, err := awsconfig.GetSession()
if err != nil {
return errors.Wrap(err, "creating AWS session")
}
err = awsconfig.ValidateCreds(ssn)
if err != nil {
return errors.Wrap(err, "validate AWS credentials")
}
case openstack.Name:
opts := new(clientconfig.ClientOpts)
opts.Cloud = ic.Config.Platform.OpenStack.Cloud
_, err = clientconfig.GetCloudFromYAML(opts)
case libvirt.Name, none.Name, vsphere.Name:
// no creds to check
default:
err = fmt.Errorf("unknown platform type %q", platform)
}
return err
}
// Name returns the human-friendly name of the asset.
func (a *PlatformCredsCheck) Name() string {
return "Platform Credentials Check"
}