-
Notifications
You must be signed in to change notification settings - Fork 72
/
build-configs.go
73 lines (56 loc) · 1.88 KB
/
build-configs.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
65
66
67
68
69
70
71
72
73
package generate
import (
"fmt"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/icon"
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
)
type configValues struct {
KafkaHost string
RegistryURL string
// Optional
Name string
}
// BuildConfiguration builds the configs for the service context
func BuildConfiguration(svcConfig *servicecontext.ServiceConfig, opts *options) error {
factory := &factory.Factory{
IOStreams: opts.IO,
Logger: opts.Logger,
Context: opts.Context,
Localizer: opts.localizer,
Connection: opts.Connection,
ServiceContext: opts.ServiceContext,
}
configurations := &configValues{}
var serviceAvailable bool
var err error
if svcConfig.KafkaID != "" {
kafkaInstance, newErr := contextutil.GetCurrentKafkaInstance(factory)
if newErr != nil {
return newErr
}
serviceAvailable = true
configurations.KafkaHost = kafkaInstance.GetBootstrapServerHost()
}
if svcConfig.ServiceRegistryID != "" {
registryInstance, newErr := contextutil.GetCurrentRegistryInstance(factory)
if newErr != nil {
return newErr
}
serviceAvailable = true
configurations.RegistryURL = registryInstance.GetRegistryUrl()
}
if !serviceAvailable {
return opts.localizer.MustLocalizeError("generate.log.info.noServices")
}
configInstanceName := fmt.Sprintf("%s-configuration", opts.name)
configurations.Name = configInstanceName
var fileName string
if fileName, err = WriteConfig(opts, configurations); err != nil {
return err
}
opts.Logger.Info(icon.SuccessPrefix(), opts.localizer.MustLocalize("generate.log.info.credentialsSaved", localize.NewEntry("FilePath", fileName)))
return nil
}