Skip to content

Commit

Permalink
fixed apps listing
Browse files Browse the repository at this point in the history
  • Loading branch information
Vivek Reddy committed Oct 15, 2024
1 parent fd1d7b8 commit 3089af4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 29 deletions.
31 changes: 7 additions & 24 deletions pkg/splunk/client/gcpbucketclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package client
import (
"context"
"strings"
//"encoding/json"
"io"
"os"

Expand Down Expand Up @@ -119,32 +118,13 @@ func InitGCSClient(ctx context.Context, gcpCredentials string) (GCSClientInterfa
if len(gcpCredentials) == 0 {
client, err = storage.NewClient(ctx)
} else {
//var creds google.Credentials
//err = json.Unmarshal([]byte(gcpCredentials), &creds)
//if err != nil {
// scopedLog.Error(err, "Secret key.json value is not parsable")
// return nil, err
//}
client, err = storage.NewClient(ctx, option.WithCredentialsJSON([]byte(gcpCredentials)))
}

if err != nil {
scopedLog.Error(err, "Failed to initialize a GCS client.")
return nil, err
}
// Test if the client can access buckets
//buckets := client.Buckets(ctx, "")
//for {
// bucketAttrs, err := buckets.Next()
// if err == iterator.Done {
// break
// }
// if err != nil {
// scopedLog.Error(err, "Failed to list buckets.")
// return nil, err
// }
// scopedLog.Info("Found bucket", "BucketName", bucketAttrs.Name)
//}

scopedLog.Info("GCS Client initialization successful.")
return &GCSClientWrapper{Client: client}, nil
Expand Down Expand Up @@ -200,6 +180,10 @@ func (gcsClient *GCSClient) GetAppsList(ctx context.Context) (RemoteDataListResp
var objects []*RemoteObject
maxKeys := 4000 // Limit the number of objects manually

if strings.HasSuffix(gcsClient.StartAfter, "/") {
startAfterFound = true
}

for count := 0; count < maxKeys; {
objAttrs, err := it.Next()
if err == iterator.Done {
Expand All @@ -212,11 +196,10 @@ func (gcsClient *GCSClient) GetAppsList(ctx context.Context) (RemoteDataListResp

// Implement "StartAfter" logic to skip objects until the desired one is found
if !startAfterFound {
if strings.HasPrefix(objAttrs.Name, gcsClient.StartAfter) {
if objAttrs.Name == gcsClient.StartAfter {
startAfterFound = true // Start adding objects after this point
} else {
continue
}
}
continue
}

// Map GCS object attributes to RemoteObject
Expand Down
2 changes: 0 additions & 2 deletions test/testenv/appframework_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,6 @@ func GenerateAppFrameworkSpec(ctx context.Context, testenvInstance *TestCaseEnv,
return appFrameworkSpec
}



// WaitforPhaseChange Wait for 2 mins or when phase change on is seen on a CR for any particular app
func WaitforPhaseChange(ctx context.Context, deployment *Deployment, testenvInstance *TestCaseEnv, name string, crKind string, appSourceName string, appList []string) {
startTime := time.Now()
Expand Down
4 changes: 1 addition & 3 deletions test/testenv/gcputils.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewGCPClient() (*GCPClient, error) {
ctx := context.Background()
var client *storage.Client
encodedString := os.Getenv("GCP_SERVICE_ACCOUNT_KEY")
gcpCredentials, err := base64.StdEncoding.DecodeString(encodedString)
gcpCredentials, err := base64.StdEncoding.DecodeString(encodedString)
if err != nil {
logf.Log.Error(err, "Error decoding GCP service account key")
return nil, err
Expand Down Expand Up @@ -391,8 +391,6 @@ func UploadFilesToGCP(bucketName, gcpTestDir string, appList []string, uploadDir
return uploadedFiles, nil
}



// DisableAppsToGCP untars apps, modifies their config files to disable them, re-tars, and uploads the disabled versions to GCP
func DisableAppsToGCP(downloadDir string, appFileList []string, gcpTestDir string) ([]string, error) {
// Create directories for untarred and disabled apps
Expand Down

0 comments on commit 3089af4

Please sign in to comment.