Skip to content

Commit

Permalink
formating fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamvernekar committed Nov 9, 2023
1 parent 16b46d5 commit 394ac1a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions client/gcs_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions client/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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)

Expand Down
13 changes: 9 additions & 4 deletions secrets/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"os"
"strings"
"time"

"github.com/rs/zerolog"
"github.com/scalescape/dolores"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)

Check failure on line 177 in secrets/manager.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: time.DateTime

Check failure on line 177 in secrets/manager.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: time.DateTime

Check failure on line 177 in secrets/manager.go

View workflow job for this annotation

GitHub Actions / Build app

undefined: time.DateTime
updatedAt := obj.UpdatedAt.Format(time.DateTime)

Check failure on line 178 in secrets/manager.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: time.DateTime (typecheck)

Check failure on line 178 in secrets/manager.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: time.DateTime) (typecheck)

Check failure on line 178 in secrets/manager.go

View workflow job for this annotation

GitHub Actions / Build app

undefined: time.DateTime
line := []byte(fmt.Sprintf(lineFormat, name, obj.Location, createdAt, updatedAt))
if _, err := cfg.output().Write(line); err != nil {
return err
}
}
Expand Down

0 comments on commit 394ac1a

Please sign in to comment.