Skip to content

Commit 7f58caf

Browse files
serdarozerrstephanme
authored andcommitted
feat: loggin added for gcs client
- log.Printf statements are added into all operations - logs in gcs_encryption_tests are suppressed to keep output clean
1 parent 505aaf6 commit 7f58caf

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

gcs/client/client.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ func New(ctx context.Context, cfg *config.GCSCli) (*GCSBlobstore, error) {
105105
// Get fetches a blob from the GCS blobstore.
106106
// Destination will be overwritten if it already exists.
107107
func (client *GCSBlobstore) Get(src string, dest string) error {
108+
log.Printf("Getting object from '%s/%s' into file '%s'\n", client.config.BucketName, src, dest)
109+
108110
dstFile, err := os.Create(dest)
109111
if err != nil {
110112
return err
@@ -137,6 +139,8 @@ func (client *GCSBlobstore) getReader(gcs *storage.Client, src string) (*storage
137139
const retryAttempts = 3
138140

139141
func (client *GCSBlobstore) Put(sourceFilePath string, dest string) error {
142+
log.Printf("Putting file '%s' into '%s/%s'\n", sourceFilePath, client.config.BucketName, dest)
143+
140144
src, err := os.Open(sourceFilePath)
141145
if err != nil {
142146
return err
@@ -193,6 +197,8 @@ func (client *GCSBlobstore) putOnce(src io.ReadSeeker, dest string) error {
193197
//
194198
// If the object does not exist, Delete returns a nil error.
195199
func (client *GCSBlobstore) Delete(dest string) error {
200+
log.Printf("Deleting object '%s' in bucket '%s' \n", dest, client.config.BucketName)
201+
196202
if client.readOnly() {
197203
return ErrInvalidROWriteOperation
198204
}
@@ -206,6 +212,8 @@ func (client *GCSBlobstore) Delete(dest string) error {
206212

207213
// Exists checks if a blob exists in the GCS blobstore.
208214
func (client *GCSBlobstore) Exists(dest string) (exists bool, err error) {
215+
log.Printf("Checking object '%s' exist in bucket '%s'\n", dest, client.config.BucketName)
216+
209217
if exists, err = client.exists(client.publicGCS, dest); err == nil {
210218
return exists, nil
211219
}
@@ -235,6 +243,8 @@ func (client *GCSBlobstore) readOnly() bool {
235243
}
236244

237245
func (client *GCSBlobstore) Sign(id string, action string, expiry time.Duration) (string, error) {
246+
log.Printf("Signing object '%s' with method '%s' for '%s' minutes\n", id, action, expiry.String())
247+
238248
action = strings.ToUpper(action)
239249
token, err := google.JWTConfigFromJSON([]byte(client.config.ServiceAccountFile), storage.ScopeFullControl)
240250
if err != nil {
@@ -263,9 +273,9 @@ func (client *GCSBlobstore) Sign(id string, action string, expiry time.Duration)
263273

264274
func (client *GCSBlobstore) List(prefix string) ([]string, error) {
265275
if prefix != "" {
266-
log.Printf("Listing objects in bucket %s with prefix '%s'\n", client.config.BucketName, prefix)
276+
log.Printf("Listing objects in bucket '%s' with prefix '%s'\n", client.config.BucketName, prefix)
267277
} else {
268-
log.Printf("Listing objects in bucket %s\n", client.config.BucketName)
278+
log.Printf("Listing objects in bucket '%s'\n", client.config.BucketName)
269279
}
270280
if client.readOnly() {
271281
return nil, ErrInvalidROWriteOperation
@@ -294,7 +304,7 @@ func (client *GCSBlobstore) List(prefix string) ([]string, error) {
294304
}
295305

296306
func (client *GCSBlobstore) Copy(srcBlob string, dstBlob string) error {
297-
log.Printf("copying an object from %s to %s\n", srcBlob, dstBlob)
307+
log.Printf("Copying an object from '%s/%s' to '%s/%s'\n", srcBlob, client.config.BucketName, dstBlob, client.config.BucketName)
298308
if client.readOnly() {
299309
return ErrInvalidROWriteOperation
300310
}
@@ -310,7 +320,7 @@ func (client *GCSBlobstore) Copy(srcBlob string, dstBlob string) error {
310320
}
311321

312322
func (client *GCSBlobstore) Properties(dest string) error {
313-
log.Printf("Getting properties for object %s/%s\n", client.config.BucketName, dest)
323+
log.Printf("Getting properties for object '%s' in bucket '%s'\n", dest, client.config.BucketName)
314324
if client.readOnly() {
315325
return ErrInvalidROWriteOperation
316326
}
@@ -375,10 +385,10 @@ func (client *GCSBlobstore) EnsureStorageExists() error {
375385

376386
func (client *GCSBlobstore) DeleteRecursive(prefix string) error {
377387
if prefix != "" {
378-
log.Printf("Deleting all objects in bucket %s with prefix '%s'\n",
388+
log.Printf("Deleting all objects in bucket '%s' with prefix '%s'\n",
379389
client.config.BucketName, prefix)
380390
} else {
381-
log.Printf("Deleting all objects in bucket %s\n", client.config.BucketName)
391+
log.Printf("Deleting all objects in bucket '%s'\n", client.config.BucketName)
382392
}
383393

384394
if client.readOnly() {

gcs/integration/gcs_encryption_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package integration
1818

1919
import (
2020
"crypto/sha256"
21+
"io"
22+
"log"
2123
"os"
2224

2325
"github.com/cloudfoundry/storage-cli/gcs/client"
@@ -42,6 +44,7 @@ var _ = Describe("Integration", func() {
4244
cfg *config.GCSCli
4345
)
4446
BeforeEach(func() {
47+
log.SetOutput(io.Discard) // Suppress all log output
4548
cfg = getMultiRegionConfig()
4649
cfg.EncryptionKey = encryptionKeyBytes
4750

0 commit comments

Comments
 (0)