Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cap cloud func name length to 63 #142

Merged
merged 1 commit into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions utilities/ramcli/func_makeinstancefolderpath.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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"
"strings"
)

func makeInstanceFolderPath(instancesFolderPath, instanceName string) (instanceFolderPath string) {
r := []rune(instanceName)
if len(r) > 63 {
instanceName = string(r[0:63])
}
instanceName = strings.Replace(instanceName, "-", "_", -1)
return fmt.Sprintf("%s/%s", instancesFolderPath, instanceName)
}
45 changes: 45 additions & 0 deletions utilities/ramcli/func_makeinstancefolderpath_unit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 (
"testing"
)

func TestUnitMakeInstanceFolderPath(t *testing.T) {
var testCases = []struct {
name string
instancesFolderPath string
instanceName string
instanceFolderPath string
}{
{
name: "mixture",
instancesFolderPath: "services/mysvc/instances",
instanceName: "Joli mois de Mai-Joli mois de Juin-Joli mois de Juillet-Joli mois de Aout",
instanceFolderPath: "services/mysvc/instances/Joli mois de Mai_Joli mois de Juin_Joli mois de Juillet_Joli mo",
},
}
for _, tc := range testCases {
tc := tc // https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
instanceFolderPath := makeInstanceFolderPath(tc.instancesFolderPath, tc.instanceName)
if instanceFolderPath != tc.instanceFolderPath {
t.Errorf("Error want '%s' and got '%s'", tc.instanceFolderPath, instanceFolderPath)
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"log"
"os"
"strings"

"github.com/BrunoReboul/ram/services/convertlog2feed"
"github.com/BrunoReboul/ram/utilities/ffo"
Expand Down Expand Up @@ -55,12 +54,10 @@ func (deployment *Deployment) configureConvertlog2feedOrganizations() (err error
}
convertlog2feedInstance.GCI.SuperAdminEmail = deployment.Core.SolutionSettings.Monitoring.DirectoryCustomerIDs[directoryCustomerID].SuperAdminEmail

instanceFolderPath := strings.Replace(
fmt.Sprintf("%s/%s_org%s_%s",
instancesFolderPath,
serviceName,
organizationID,
sinkNameSuffix), "-", "_", -1)
instanceFolderPath := makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_org%s_%s",
serviceName,
organizationID,
sinkNameSuffix))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"log"
"os"
"strings"

"github.com/BrunoReboul/ram/services/dumpinventory"
"github.com/BrunoReboul/ram/utilities/cai"
Expand Down Expand Up @@ -48,7 +47,9 @@ func (deployment *Deployment) configureDumpInventoryAssetTypes() (err error) {
// one and only one iam policy feed for all asset types
dumpinventoryInstance.CAI.ContentType = "IAM_POLICY"
dumpinventoryInstance.CAI.AssetTypes = deployment.Core.SolutionSettings.Monitoring.AssetTypes.IAMPolicies
instanceFolderPath := fmt.Sprintf("%s/%s_org%s_iam_policies", instancesFolderPath, serviceName, organizationID)
instanceFolderPath := makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_org%s_iam_policies",
serviceName,
organizationID))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
Expand All @@ -61,12 +62,10 @@ func (deployment *Deployment) configureDumpInventoryAssetTypes() (err error) {
for _, assetType := range deployment.Core.SolutionSettings.Monitoring.AssetTypes.Resources {
dumpinventoryInstance.CAI.ContentType = "RESOURCE"
dumpinventoryInstance.CAI.AssetTypes = []string{assetType}
instanceFolderPath := strings.Replace(
fmt.Sprintf("%s/%s_org%s_%s",
instancesFolderPath,
serviceName,
organizationID,
cai.GetAssetShortTypeName(assetType)), "-", "_", -1)
instanceFolderPath := makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_org%s_%s",
serviceName,
organizationID,
cai.GetAssetShortTypeName(assetType)))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"log"
"os"
"strings"

"github.com/BrunoReboul/ram/services/getgroupsettings"
"github.com/BrunoReboul/ram/utilities/ffo"
Expand All @@ -44,11 +43,9 @@ func (deployment *Deployment) configureGetGroupSettingsDirectories() (err error)
getgroupsettingsInstance.GCI.SuperAdminEmail = directorySettings.SuperAdminEmail
getgroupsettingsInstance.GCF.TriggerTopic = fmt.Sprintf("gci-groups-%s", directoryCustomerID)

instanceFolderPath := strings.Replace(
fmt.Sprintf("%s/%s_directory_%s",
instancesFolderPath,
serviceName,
directoryCustomerID), "-", "_", -1)
instanceFolderPath := makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_directory_%s",
serviceName,
directoryCustomerID))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"log"
"os"
"strings"

"github.com/BrunoReboul/ram/services/listgroupmembers"
"github.com/BrunoReboul/ram/utilities/ffo"
Expand All @@ -44,11 +43,9 @@ func (deployment *Deployment) configureListGroupMembersDirectories() (err error)
listgroupmembersInstance.GCI.SuperAdminEmail = directorySettings.SuperAdminEmail
listgroupmembersInstance.GCF.TriggerTopic = fmt.Sprintf("gci-groups-%s", directoryCustomerID)

instanceFolderPath := strings.Replace(
fmt.Sprintf("%s/%s_directory_%s",
instancesFolderPath,
serviceName,
directoryCustomerID), "-", "_", -1)
instanceFolderPath := makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_directory_%s",
serviceName,
directoryCustomerID))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"log"
"os"
"strings"

"github.com/BrunoReboul/ram/services/listgroups"
"github.com/BrunoReboul/ram/utilities/ffo"
Expand All @@ -45,11 +44,9 @@ func (deployment *Deployment) configureListGroupsDirectories() (err error) {
listgroupsInstance.GCI.SuperAdminEmail = directorySettings.SuperAdminEmail
listgroupsInstance.SCH.Schedulers = deployment.Core.SolutionSettings.Monitoring.ListGroupsDefaultSchedulers

instanceFolderPath := strings.Replace(
fmt.Sprintf("%s/%s_directory_%s",
instancesFolderPath,
serviceName,
directoryCustomerID), "-", "_", -1)
instanceFolderPath := makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_directory_%s",
serviceName,
directoryCustomerID))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
Expand Down
33 changes: 11 additions & 22 deletions utilities/ramcli/meth_deployment_configurepublish2fsinstances.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"log"
"os"
"strings"

"github.com/BrunoReboul/ram/services/publish2fs"
"github.com/BrunoReboul/ram/utilities/ffo"
Expand All @@ -41,10 +40,8 @@ func (deployment *Deployment) configurePublish2fsInstances() (err error) {
}

publish2fsInstance.GCF.TriggerTopic = "cai-rces-cloudresourcemanager-Organization"
instanceFolderPath := strings.Replace(
fmt.Sprintf("%s/%s_cloudresourcemanager_Organization",
instancesFolderPath,
serviceName), "-", "_", -1)
instanceFolderPath := makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_cloudresourcemanager_Organization",
serviceName))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
Expand All @@ -54,10 +51,8 @@ func (deployment *Deployment) configurePublish2fsInstances() (err error) {
log.Printf("done %s", instanceFolderPath)

publish2fsInstance.GCF.TriggerTopic = "cai-rces-cloudresourcemanager-Folder"
instanceFolderPath = strings.Replace(
fmt.Sprintf("%s/%s_cloudresourcemanager_Folder",
instancesFolderPath,
serviceName), "-", "_", -1)
instanceFolderPath = makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_cloudresourcemanager_Folder",
serviceName))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
Expand All @@ -67,10 +62,8 @@ func (deployment *Deployment) configurePublish2fsInstances() (err error) {
log.Printf("done %s", instanceFolderPath)

publish2fsInstance.GCF.TriggerTopic = "cai-rces-cloudresourcemanager-Project"
instanceFolderPath = strings.Replace(
fmt.Sprintf("%s/%s_cloudresourcemanager_Project",
instancesFolderPath,
serviceName), "-", "_", -1)
instanceFolderPath = makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_cloudresourcemanager_Project",
serviceName))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
Expand All @@ -80,10 +73,8 @@ func (deployment *Deployment) configurePublish2fsInstances() (err error) {
log.Printf("done %s", instanceFolderPath)

publish2fsInstance.GCF.TriggerTopic = "gci-groupMembers"
instanceFolderPath = strings.Replace(
fmt.Sprintf("%s/%s_gci_groupMembers",
instancesFolderPath,
serviceName), "-", "_", -1)
instanceFolderPath = makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_gci_groupMembers",
serviceName))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
Expand All @@ -94,11 +85,9 @@ func (deployment *Deployment) configurePublish2fsInstances() (err error) {

for directoryCustomerID := range deployment.Core.SolutionSettings.Monitoring.DirectoryCustomerIDs {
publish2fsInstance.GCF.TriggerTopic = fmt.Sprintf("gci-groups-%s", directoryCustomerID)
instanceFolderPath = strings.Replace(
fmt.Sprintf("%s/%s_gci_groups_%s",
instancesFolderPath,
serviceName,
directoryCustomerID), "-", "_", -1)
instanceFolderPath = makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_gci_groups_%s",
serviceName,
directoryCustomerID))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
Expand Down
5 changes: 2 additions & 3 deletions utilities/ramcli/meth_deployment_configuresetdashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ func (deployment *Deployment) configureSetDashboards() (err error) {
setDashboardsInstance.MON.Columns = dashboard.columns
setDashboardsInstance.MON.WidgetTypeList = dashboard.widgetTypeList
setDashboardsInstance.MON.MicroServiceNameList = dashboard.microServiceNameList
instanceFolderPath := fmt.Sprintf("%s/%s_%s",
instancesFolderPath,
instanceFolderPath := makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_%s",
serviceName,
strings.ToLower(strings.Replace(displayName, " ", "_", -1)))
strings.ToLower(strings.Replace(displayName, " ", "_", -1))))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
Expand Down
15 changes: 7 additions & 8 deletions utilities/ramcli/meth_deployment_configuresetfeedsassettypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"log"
"os"
"strings"

"github.com/BrunoReboul/ram/services/setfeeds"
"github.com/BrunoReboul/ram/utilities/cai"
Expand Down Expand Up @@ -47,7 +46,9 @@ func (deployment *Deployment) configureSetFeedsAssetTypes() (err error) {
// one and only one iam policy feed for all asset types
setfeedsInstance.CAI.ContentType = "IAM_POLICY"
setfeedsInstance.CAI.AssetTypes = deployment.Core.SolutionSettings.Monitoring.AssetTypes.IAMPolicies
instanceFolderPath := fmt.Sprintf("%s/%s_org%s_iam_policies", instancesFolderPath, serviceName, organizationID)
instanceFolderPath := makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_org%s_iam_policies",
serviceName,
organizationID))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
Expand All @@ -60,12 +61,10 @@ func (deployment *Deployment) configureSetFeedsAssetTypes() (err error) {
for _, assetType := range deployment.Core.SolutionSettings.Monitoring.AssetTypes.Resources {
setfeedsInstance.CAI.ContentType = "RESOURCE"
setfeedsInstance.CAI.AssetTypes = []string{assetType}
instanceFolderPath := strings.Replace(
fmt.Sprintf("%s/%s_org%s_%s",
instancesFolderPath,
serviceName,
organizationID,
cai.GetAssetShortTypeName(assetType)), "-", "_", -1)
instanceFolderPath := makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_org%s_%s",
serviceName,
organizationID,
cai.GetAssetShortTypeName(assetType)))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
Expand Down
5 changes: 2 additions & 3 deletions utilities/ramcli/meth_deployment_configuresetlogmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,9 @@ func (deployment *Deployment) configureSetLogMetrics() (err error) {
}

for _, logMetric := range logMetricList {
instanceFolderPath := fmt.Sprintf("%s/%s_%s",
instancesFolderPath,
instanceFolderPath := makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_%s",
serviceName,
strings.ToLower(strings.Replace(logMetric.GLO.MetricID, " ", "_", -1)))
strings.ToLower(logMetric.GLO.MetricID)))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"log"
"os"
"strings"

"github.com/BrunoReboul/ram/services/setlogsinks"
"github.com/BrunoReboul/ram/utilities/ffo"
Expand Down Expand Up @@ -50,12 +49,10 @@ func (deployment *Deployment) configureLogSinksOrganizations() (err error) {
setlogsinksInstance.LSK.Filter = filter
setlogsinksInstance.LSK.TopicName = fmt.Sprintf("log-org%s-%s", organizationID, sinkNameSuffix)

instanceFolderPath := strings.Replace(
fmt.Sprintf("%s/%s_org%s_%s",
instancesFolderPath,
serviceName,
organizationID,
sinkNameSuffix), "-", "_", -1)
instanceFolderPath := makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_org%s_%s",
serviceName,
organizationID,
sinkNameSuffix))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"log"
"os"
"strings"

"github.com/BrunoReboul/ram/services/splitdump"
"github.com/BrunoReboul/ram/utilities/ffo"
Expand All @@ -44,10 +43,8 @@ func (deployment *Deployment) configureSplitDumpSingleInstance() (err error) {
splitdumpInstance.SplitThresholdLineNumber = 1000
splitdumpInstance.ScannerBufferSizeKiloBytes = 128

instanceFolderPath := strings.Replace(
fmt.Sprintf("%s/%s_single_instance",
instancesFolderPath,
serviceName), "-", "_", -1)
instanceFolderPath := makeInstanceFolderPath(instancesFolderPath, fmt.Sprintf("%s_single_instance",
serviceName))
if _, err := os.Stat(instanceFolderPath); os.IsNotExist(err) {
os.Mkdir(instanceFolderPath, 0755)
}
Expand Down