Skip to content

Commit 2bc114f

Browse files
author
igor.grzankowski
committed
Refactor
1 parent 17c9e09 commit 2bc114f

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

pkg/splunk/enterprise/util.go

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,25 +1185,17 @@ func handleAppRepoChanges(ctx context.Context, client splcommon.ControllerClient
11851185
}
11861186

11871187
// isAppExtentionValid checks if an app extention is supported or not
1188-
func isAppExtentionValid(receivedKey string) bool {
1189-
appExtIdx := strings.LastIndex(receivedKey, ".")
1190-
if appExtIdx < 0 {
1191-
return false
1192-
}
1193-
1194-
switch appExt := receivedKey[appExtIdx+1:]; appExt {
1195-
case "spl":
1196-
return true
1188+
func isAppExtensionValid(receivedKey string) bool {
1189+
// List of valid extensions
1190+
validExtensions := []string{".spl", ".tgz", ".tar.gz"}
11971191

1198-
case "tgz":
1199-
return true
1200-
1201-
case "tar.gz":
1202-
return true
1203-
1204-
default:
1205-
return false
1192+
// Iterate over the list and check if the receivedKey ends with any valid extension
1193+
for _, ext := range validExtensions {
1194+
if strings.HasSuffix(receivedKey, ext) {
1195+
return true
1196+
}
12061197
}
1198+
return false
12071199
}
12081200

12091201
// AddOrUpdateAppSrcDeploymentInfoList modifies the App deployment status as perceived from the remote object listing
@@ -1219,7 +1211,7 @@ func AddOrUpdateAppSrcDeploymentInfoList(ctx context.Context, appSrcDeploymentIn
12191211

12201212
for _, remoteObj := range remoteS3ObjList {
12211213
receivedKey := *remoteObj.Key
1222-
if !isAppExtentionValid(receivedKey) {
1214+
if !isAppExtensionValid(receivedKey) {
12231215
scopedLog.Error(nil, "App name Parsing: Ignoring the key with invalid extension", "receivedKey", receivedKey)
12241216
continue
12251217
}

pkg/splunk/enterprise/util_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,12 +1175,12 @@ func TestGetAvailableDiskSpaceShouldFail(t *testing.T) {
11751175
}
11761176
}
11771177

1178-
func TestIsAppExtentionValid(t *testing.T) {
1179-
if !isAppExtentionValid("testapp.spl") || !isAppExtentionValid("testapp.tgz") || !isAppExtentionValid("testapp.tar.gz") {
1178+
func TestIsAppExtensionValid(t *testing.T) {
1179+
if !isAppExtensionValid("testapp.spl") || !isAppExtensionValid("testapp.tgz") || !isAppExtensionValid("testapp.tar.gz") {
11801180
t.Errorf("failed to detect valid app extension")
11811181
}
11821182

1183-
if isAppExtentionValid("testapp.aspl") || isAppExtentionValid("testapp.ttgz") {
1183+
if isAppExtensionValid("testapp.aspl") || isAppExtensionValid("testapp.ttgz") {
11841184
t.Errorf("failed to detect invalid app extension")
11851185
}
11861186
}

0 commit comments

Comments
 (0)