/
meth_deployment_configureconvertlog2feedorganizations.go
70 lines (62 loc) · 2.81 KB
/
meth_deployment_configureconvertlog2feedorganizations.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
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the 'License');
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an 'AS IS' BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ramcli
import (
"fmt"
"log"
"os"
"github.com/BrunoReboul/ram/services/convertlog2feed"
"github.com/BrunoReboul/ram/utilities/ffo"
"github.com/BrunoReboul/ram/utilities/solution"
)
// configureConvertlog2feedOrganizations
func (deployment *Deployment) configureConvertlog2feedOrganizations() (err error) {
serviceName := "convertlog2feed"
// Case activity group
sinkNameSuffix := "activity-group"
log.Printf("configure %s %s", serviceName, sinkNameSuffix)
var convertlog2feedInstanceDeployment convertlog2feed.InstanceDeployment
convertlog2feedInstance := convertlog2feedInstanceDeployment.Settings.Instance
serviceFolderPath := fmt.Sprintf("%s/%s/%s", deployment.Core.RepositoryPath, solution.MicroserviceParentFolderName, serviceName)
if _, err := os.Stat(serviceFolderPath); os.IsNotExist(err) {
os.Mkdir(serviceFolderPath, 0755)
}
instancesFolderPath := fmt.Sprintf("%s/%s", serviceFolderPath, solution.InstancesFolderName)
if _, err := os.Stat(instancesFolderPath); os.IsNotExist(err) {
os.Mkdir(instancesFolderPath, 0755)
}
for _, organizationID := range deployment.Core.SolutionSettings.Monitoring.OrganizationIDs {
convertlog2feedInstance.GCF.TriggerTopic = fmt.Sprintf("log-org%s-%s", organizationID, sinkNameSuffix)
var directoryCustomerID string
organization, err := deployment.Core.Services.CloudresourcemanagerService.Organizations.Get(fmt.Sprintf("organizations/%s", organizationID)).Context(deployment.Core.Ctx).Do()
if err != nil {
log.Printf("WARNING - cloudresourcemanagerService.Organizations.Get %v", err)
} else {
directoryCustomerID = organization.Owner.DirectoryCustomerId
}
convertlog2feedInstance.GCI.SuperAdminEmail = deployment.Core.SolutionSettings.Monitoring.DirectoryCustomerIDs[directoryCustomerID].SuperAdminEmail
instanceFolderPath := makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_org%s_%s",
serviceName,
organizationID,
sinkNameSuffix))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
if err = ffo.MarshalYAMLWrite(fmt.Sprintf("%s/%s", instanceFolderPath, solution.InstanceSettingsFileName), convertlog2feedInstance); err != nil {
return err
}
log.Printf("done %s", instanceFolderPath)
}
return nil
}