From 394ac1ae2c9fd10a19d1d5f7978a853fd3d14804 Mon Sep 17 00:00:00 2001 From: shubhamvernekar Date: Thu, 9 Nov 2023 08:30:26 +0530 Subject: [PATCH] formating fix --- client/client.go | 2 +- client/gcs_service.go | 4 ++-- client/service_test.go | 10 +++++----- secrets/manager.go | 13 +++++++++---- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/client/client.go b/client/client.go index 978233d..10b2a57 100644 --- a/client/client.go +++ b/client/client.go @@ -94,7 +94,7 @@ type SecretListResponse struct { } func (c *Client) GetSecretList(_ SecretListConfig) ([]SecretObject, error) { - resp, err := c.Service.GetObjList(c.ctx, c.bucket, c.prefix) + resp, err := c.Service.ListObject(c.ctx, c.bucket, c.prefix) if err != nil { return nil, err } diff --git a/client/gcs_service.go b/client/gcs_service.go index 00238c3..1301390 100644 --- a/client/gcs_service.go +++ b/client/gcs_service.go @@ -78,7 +78,7 @@ func (s Service) GetOrgPublicKeys(ctx context.Context, env, bucketName, path str if pubKey != "" { return []string{pubKey}, nil } - resp, err := s.GetObjList(ctx, bucketName, path) + resp, err := s.ListObject(ctx, bucketName, path) if err != nil { return nil, fmt.Errorf("error listing objects: %w", err) } @@ -138,7 +138,7 @@ func (s Service) saveObject(ctx context.Context, bucket, fname string, md any) e return s.store.WriteToObject(ctx, bucket, fname, data) } -func (s Service) GetObjList(ctx context.Context, bucket, path string) ([]google.Object, error) { +func (s Service) ListObject(ctx context.Context, bucket, path string) ([]google.Object, error) { resp, err := s.store.ListObject(ctx, bucket, path) if err != nil { return nil, err diff --git a/client/service_test.go b/client/service_test.go index 986830f..dbf4d7f 100644 --- a/client/service_test.go +++ b/client/service_test.go @@ -39,9 +39,9 @@ func (m *mockGCS) ReadObject(ctx context.Context, bucketName, fileName string) ( return args.Get(0).([]byte), args.Error(1) } -func (m *mockGCS) ListObject(ctx context.Context, bucketName, path string) ([]google.SecretObject, error) { +func (m *mockGCS) ListObject(ctx context.Context, bucketName, path string) ([]google.Object, error) { args := m.Called(ctx, bucketName, path) - return args.Get(0).([]google.SecretObject), args.Error(1) + return args.Get(0).([]google.Object), args.Error(1) } func (m *mockGCS) ExistsObject(ctx context.Context, bucketName, fileName string) (bool, error) { @@ -53,7 +53,7 @@ func (s *serviceSuite) TestShouldWritePlainKeySuccessfully() { name := "keyfile" data := config.Metadata{Environment: "production"} expData, err := json.Marshal(data) - s.gcs.On("ExistsObject", mock.AnythingOfType("*context.emptyCtx"), s.bucket, "dolores.md").Return(false, nil).Once() + s.gcs.On("ExistsObject", mock.AnythingOfType("*context.emptyCtx"), s.bucket, "dolores.md").Return(false, nil) s.gcs.On("WriteToObject", mock.AnythingOfType("*context.emptyCtx"), s.bucket, name, expData).Return(nil) s.gcs.On("WriteToObject", mock.AnythingOfType("*context.emptyCtx"), s.bucket, "dolores.md", mock.AnythingOfType("[]uint8")).Return(nil).Once() require.NoError(s.T(), err) @@ -70,8 +70,8 @@ func (s *serviceSuite) TestShouldNotOverwriteMetadata() { PublicKey: "public_key", Metadata: config.Metadata{Location: "secrets"}, UserID: "test_user"} - s.gcs.On("ExistsObject", mock.AnythingOfType("*context.emptyCtx"), s.bucket, name).Return(true, nil).Once() - s.gcs.On("WriteToObject", mock.AnythingOfType("*context.emptyCtx"), s.bucket, "secrets/keys/test_user.key", []byte(cfg.PublicKey)).Return(nil).Once() + s.gcs.On("ExistsObject", mock.AnythingOfType("context.backgroundCtx"), s.bucket, name).Return(true, nil).Once() + s.gcs.On("WriteToObject", mock.AnythingOfType("context.backgroundCtx"), s.bucket, "secrets/keys/test_user.key", []byte(cfg.PublicKey)).Return(nil).Once() err := s.Service.Init(s.ctx, s.bucket, cfg) diff --git a/secrets/manager.go b/secrets/manager.go index 7b8c476..ba0106d 100644 --- a/secrets/manager.go +++ b/secrets/manager.go @@ -7,6 +7,7 @@ import ( "io" "os" "strings" + "time" "github.com/rs/zerolog" "github.com/scalescape/dolores" @@ -160,7 +161,10 @@ func (sm SecretManager) ListSecret(cfg ListSecretConfig) error { if err != nil { return fmt.Errorf("failed to get secrets: %w", err) } - if _, err := cfg.output().Write([]byte(fmt.Sprintf("%-10s %-50s %-30s %-30s\n", "Name", "Location", "Created At UTC", "Updated At UTC"))); err != nil { + + lineFormat := "%-10s %-65s %-30s %-30s\n" + header := []byte(fmt.Sprintf(lineFormat, "Name", "Location", "Created At (UTC)", "Updated At (UTC)")) + if _, err := cfg.output().Write(header); err != nil { return err } for _, obj := range resp { @@ -170,9 +174,10 @@ func (sm SecretManager) ListSecret(cfg ListSecretConfig) error { if len(arr) == 2 { name = arr[1] } - createdAt := obj.CreatedAt.Format("2000-01-02 15:04:05.999") - updatedAt := obj.UpdatedAt.Format("2000-01-02 15:04:05.999") - if _, err := cfg.output().Write([]byte(fmt.Sprintf("%-10s %-50s %-30s %-30s\n", name, obj.Location, createdAt, updatedAt))); err != nil { + createdAt := obj.CreatedAt.Format(time.DateTime) + updatedAt := obj.UpdatedAt.Format(time.DateTime) + line := []byte(fmt.Sprintf(lineFormat, name, obj.Location, createdAt, updatedAt)) + if _, err := cfg.output().Write(line); err != nil { return err } }