Skip to content

Commit

Permalink
[GCS] expose get spec path
Browse files Browse the repository at this point in the history
  • Loading branch information
effoeffi committed Nov 12, 2023
1 parent 97a00d9 commit 7112261
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions gcs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

type Client interface {
UploadSpec(tenantId string, name string, file []byte) error
Upload(path string, file []byte) error
Read(path string) ([]byte, error)
Close() error
}
Expand Down Expand Up @@ -53,29 +53,25 @@ func NewStore() Client {
return &Store{client: client, bucket: env.GetGCPStorageBucket()}
}

// Buckets/syncc/{tenant-id}/spec/[]spec
func (store *Store) UploadSpec(tenantId string, name string, file []byte) error {
func (store *Store) Upload(path string, file []byte) error {

w := store.client.Bucket(store.bucket).
Object(fmt.Sprintf("%s/spec/%s", tenantId, name)).
NewWriter(context.Background())
w := store.client.Bucket(store.bucket).Object(path).NewWriter(context.Background())
defer func() {
if err := w.Close(); err != nil {
logrus.Errorf("failed to close gcs bucket '%s' writer file '%s' with '%v'",
store.bucket, name, err)
store.bucket, path, err)
}
}()

if _, err := w.Write(file); err != nil {
logrus.Errorf("failed to create file in GCS bucket '%s' file '%s' with '%v'",
store.bucket, name, err)
store.bucket, path, err)
return err
}

return nil
}

// path should look like this: {tenant-id}/spec/1685962955
func (store *Store) Read(path string) ([]byte, error) {

rc, err := store.client.Bucket(store.bucket).
Expand Down Expand Up @@ -107,3 +103,9 @@ func (store *Store) Close() error {

return store.client.Close()
}

// Buckets/syncc/[]{tenant-id}/spec/[]{webhook-id}/[]spec
func GetSpecPath(tenant, webhook, name string) string {

return fmt.Sprintf("%s/spec/%s/%s", tenant, webhook, name)
}
2 changes: 1 addition & 1 deletion gcs/client_inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ func NewInMemoryStore(pathToFile map[string][]byte) Client {
return &InMemoryStore{pathToFile: pathToFile}
}

func (m *InMemoryStore) UploadSpec(string, string, []byte) error { return nil }
func (m *InMemoryStore) Upload(string, []byte) error { return nil }

func (m *InMemoryStore) Read(path string) ([]byte, error) {

Expand Down

0 comments on commit 7112261

Please sign in to comment.