Skip to content

Commit 5fe6840

Browse files
author
igor.grzankowski
committed
Refactor
1 parent 17c9e09 commit 5fe6840

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

pkg/splunk/enterprise/util.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,25 +1185,15 @@ 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+
validExtensions := []string{".spl", ".tgz", ".tar.gz"}
11971190

1198-
case "tgz":
1199-
return true
1200-
1201-
case "tar.gz":
1202-
return true
1203-
1204-
default:
1205-
return false
1191+
for _, ext := range validExtensions {
1192+
if strings.HasSuffix(receivedKey, ext) {
1193+
return true
1194+
}
12061195
}
1196+
return false
12071197
}
12081198

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

12201210
for _, remoteObj := range remoteS3ObjList {
12211211
receivedKey := *remoteObj.Key
1222-
if !isAppExtentionValid(receivedKey) {
1212+
if !isAppExtensionValid(receivedKey) {
12231213
scopedLog.Error(nil, "App name Parsing: Ignoring the key with invalid extension", "receivedKey", receivedKey)
12241214
continue
12251215
}

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)