-
Notifications
You must be signed in to change notification settings - Fork 226
feat(pqlmanifest): implement S3 polling support for PQL manifest #2726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5d0a372
feat(pqlmanifest): implement StorageFetcher for manifest retrieval an…
StarpTech 54e0f0b
Merge branch 'main' into dustin/support-s3-poling-for-pql-manifest
StarpTech c1bd70a
Merge branch 'main' into dustin/support-s3-poling-for-pql-manifest
StarpTech 590de81
feat(pqlmanifest): enhance S3 manifest fetching with conditional requ…
StarpTech 062c098
Merge branch 'main' into dustin/support-s3-poling-for-pql-manifest
StarpTech bd0c422
feat(pqlmanifest): add configurable manifest file name for S3 polling
StarpTech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| package core | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/wundergraph/cosmo/router/pkg/config" | ||
| ) | ||
|
|
||
| // ProviderRegistry indexes storage provider configurations by ID, providing | ||
| // typed lookups with clear error messages. It is built once during router | ||
| // initialization and shared across all subsystems that need to resolve a | ||
| // provider by its configured ID. | ||
| type ProviderRegistry struct { | ||
| s3 map[string]config.S3StorageProvider | ||
| cdn map[string]config.CDNStorageProvider | ||
| redis map[string]config.RedisStorageProvider | ||
| fileSystem map[string]config.FileSystemStorageProvider | ||
| } | ||
|
|
||
| // NewProviderRegistry builds lookup maps for every provider type and returns | ||
| // an error if any type contains duplicate IDs. | ||
| func NewProviderRegistry(providers config.StorageProviders) (*ProviderRegistry, error) { | ||
| r := &ProviderRegistry{ | ||
| s3: make(map[string]config.S3StorageProvider, len(providers.S3)), | ||
| cdn: make(map[string]config.CDNStorageProvider, len(providers.CDN)), | ||
| redis: make(map[string]config.RedisStorageProvider, len(providers.Redis)), | ||
| fileSystem: make(map[string]config.FileSystemStorageProvider, len(providers.FileSystem)), | ||
| } | ||
|
|
||
| for _, p := range providers.S3 { | ||
| if _, ok := r.s3[p.ID]; ok { | ||
| return nil, fmt.Errorf("duplicate s3 storage provider with id '%s'", p.ID) | ||
| } | ||
| r.s3[p.ID] = p | ||
| } | ||
| for _, p := range providers.CDN { | ||
| if _, ok := r.cdn[p.ID]; ok { | ||
| return nil, fmt.Errorf("duplicate cdn storage provider with id '%s'", p.ID) | ||
| } | ||
| r.cdn[p.ID] = p | ||
| } | ||
| for _, p := range providers.Redis { | ||
| if _, ok := r.redis[p.ID]; ok { | ||
| return nil, fmt.Errorf("duplicate Redis storage provider with id '%s'", p.ID) | ||
| } | ||
| r.redis[p.ID] = p | ||
| } | ||
| for _, p := range providers.FileSystem { | ||
| if _, ok := r.fileSystem[p.ID]; ok { | ||
| return nil, fmt.Errorf("duplicate file system storage provider with id '%s'", p.ID) | ||
| } | ||
| r.fileSystem[p.ID] = p | ||
| } | ||
|
|
||
| return r, nil | ||
StarpTech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // S3 looks up an S3 provider by ID. | ||
| func (r *ProviderRegistry) S3(id string) (config.S3StorageProvider, bool) { | ||
| p, ok := r.s3[id] | ||
| return p, ok | ||
| } | ||
|
|
||
| // CDN looks up a CDN provider by ID. | ||
| func (r *ProviderRegistry) CDN(id string) (config.CDNStorageProvider, bool) { | ||
| p, ok := r.cdn[id] | ||
| return p, ok | ||
| } | ||
|
|
||
| // Redis looks up a Redis provider by ID. | ||
| func (r *ProviderRegistry) Redis(id string) (config.RedisStorageProvider, bool) { | ||
| p, ok := r.redis[id] | ||
| return p, ok | ||
| } | ||
|
|
||
| // FileSystem looks up a filesystem provider by ID. | ||
| func (r *ProviderRegistry) FileSystem(id string) (config.FileSystemStorageProvider, bool) { | ||
| p, ok := r.fileSystem[id] | ||
| return p, ok | ||
| } | ||
|
|
||
| // IsFileSystem returns true if the given ID matches a filesystem provider. | ||
| func (r *ProviderRegistry) IsFileSystem(id string) bool { | ||
| _, ok := r.fileSystem[id] | ||
| return ok | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| package core | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "github.com/wundergraph/cosmo/router/pkg/config" | ||
| ) | ||
|
|
||
| func TestProviderRegistry(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| t.Run("successful lookups", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| reg, err := NewProviderRegistry(config.StorageProviders{ | ||
| S3: []config.S3StorageProvider{{ID: "my-s3", Bucket: "b"}}, | ||
| CDN: []config.CDNStorageProvider{{ID: "my-cdn", URL: "https://cdn"}}, | ||
| Redis: []config.RedisStorageProvider{{ID: "my-redis"}}, | ||
| FileSystem: []config.FileSystemStorageProvider{{ID: "my-fs", Path: "/tmp"}}, | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| s3, ok := reg.S3("my-s3") | ||
| require.True(t, ok) | ||
| require.Equal(t, "b", s3.Bucket) | ||
|
|
||
| cdn, ok := reg.CDN("my-cdn") | ||
| require.True(t, ok) | ||
| require.Equal(t, "https://cdn", cdn.URL) | ||
|
|
||
| redis, ok := reg.Redis("my-redis") | ||
| require.True(t, ok) | ||
| require.Equal(t, "my-redis", redis.ID) | ||
|
|
||
| fs, ok := reg.FileSystem("my-fs") | ||
| require.True(t, ok) | ||
| require.Equal(t, "/tmp", fs.Path) | ||
| }) | ||
|
|
||
| t.Run("unknown ID returns false", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| reg, err := NewProviderRegistry(config.StorageProviders{}) | ||
| require.NoError(t, err) | ||
|
|
||
| _, ok := reg.S3("nope") | ||
| require.False(t, ok) | ||
|
|
||
| _, ok = reg.CDN("nope") | ||
| require.False(t, ok) | ||
|
|
||
| _, ok = reg.Redis("nope") | ||
| require.False(t, ok) | ||
|
|
||
| _, ok = reg.FileSystem("nope") | ||
StarpTech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| require.False(t, ok) | ||
| }) | ||
|
|
||
| t.Run("duplicate S3 ID", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| _, err := NewProviderRegistry(config.StorageProviders{ | ||
| S3: []config.S3StorageProvider{{ID: "dup"}, {ID: "dup"}}, | ||
| }) | ||
| require.ErrorContains(t, err, "duplicate s3 storage provider with id 'dup'") | ||
| }) | ||
|
|
||
| t.Run("duplicate CDN ID", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| _, err := NewProviderRegistry(config.StorageProviders{ | ||
| CDN: []config.CDNStorageProvider{{ID: "dup"}, {ID: "dup"}}, | ||
| }) | ||
| require.ErrorContains(t, err, "duplicate cdn storage provider with id 'dup'") | ||
| }) | ||
|
|
||
| t.Run("duplicate Redis ID", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| _, err := NewProviderRegistry(config.StorageProviders{ | ||
| Redis: []config.RedisStorageProvider{{ID: "dup"}, {ID: "dup"}}, | ||
| }) | ||
| require.ErrorContains(t, err, "duplicate Redis storage provider with id 'dup'") | ||
| }) | ||
|
|
||
| t.Run("duplicate FileSystem ID", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| _, err := NewProviderRegistry(config.StorageProviders{ | ||
| FileSystem: []config.FileSystemStorageProvider{{ID: "dup"}, {ID: "dup"}}, | ||
| }) | ||
| require.ErrorContains(t, err, "duplicate file system storage provider with id 'dup'") | ||
| }) | ||
|
|
||
| t.Run("IsFileSystem", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| reg, err := NewProviderRegistry(config.StorageProviders{ | ||
| FileSystem: []config.FileSystemStorageProvider{{ID: "fs1"}}, | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| require.True(t, reg.IsFileSystem("fs1")) | ||
| require.False(t, reg.IsFileSystem("nope")) | ||
| }) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.