-
Notifications
You must be signed in to change notification settings - Fork 894
fix: use authenticated urls for pubsub #14261
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 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b89ff23
fix: use authenticated urls for pubsub
f0ssel 88d50b8
comments
f0ssel 8be0524
flake
f0ssel 3be05c2
fmt
f0ssel c7964e4
temp add personal fork
f0ssel 6ff2ec7
update coder fork
f0ssel 02258ee
test pubsub
f0ssel 9d8681b
test pubsub
f0ssel 85f6cfe
t log
f0ssel dae69c7
add customer driver tests
f0ssel 55df464
merge main
f0ssel 2019fec
update flake
f0ssel ff2784c
lint
f0ssel c18963b
move to defer
f0ssel 1600abf
fix tests
f0ssel 839a52e
remove log
f0ssel 428f3f5
merge main
f0ssel cd61cc7
update flake
f0ssel c946cdd
fmt
f0ssel 1b139e4
close chan
f0ssel 8c96f6e
use pq
f0ssel a645a76
merge main
f0ssel ed009f7
update flake
f0ssel c8a7c9a
fix flake
f0ssel 05cbc3c
sleep to prevent flake
f0ssel 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
Next
Next commit
fix: use authenticated urls for pubsub
- Loading branch information
commit b89ff23d1fbcf036b722022c37c5a61b3ad4b5b3
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
"database/sql/driver" | ||
|
||
"github.com/lib/pq" | ||
) | ||
|
||
type ConnectorCreator interface { | ||
Connector(name string) (driver.Connector, error) | ||
} | ||
|
||
type DialerConnector interface { | ||
Connect(context.Context) (driver.Conn, error) | ||
Dialer(dialer pq.Dialer) | ||
} |
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ package pubsub | |
import ( | ||
"context" | ||
"database/sql" | ||
"database/sql/driver" | ||
"errors" | ||
"io" | ||
"net" | ||
|
@@ -15,6 +16,8 @@ import ( | |
"github.com/prometheus/client_golang/prometheus" | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/coder/coder/v2/coderd/database" | ||
|
||
"cdr.dev/slog" | ||
) | ||
|
||
|
@@ -432,9 +435,31 @@ func (p *PGPubsub) startListener(ctx context.Context, connectURL string) error { | |
// pq.defaultDialer uses a zero net.Dialer as well. | ||
d: net.Dialer{}, | ||
} | ||
connector driver.Connector | ||
err error | ||
) | ||
|
||
// Create a custom connector if the database driver supports it. | ||
connectorCreator, ok := p.db.Driver().(database.ConnectorCreator) | ||
if !ok { | ||
connector, err = pq.NewConnector(connectURL) | ||
if err != nil { | ||
return xerrors.Errorf("create pq connector: %w", err) | ||
} | ||
} else { | ||
connector, err = connectorCreator.Connector(connectURL) | ||
if err != nil { | ||
return xerrors.Errorf("create custom connector: %w", err) | ||
} | ||
} | ||
|
||
// Set the dialer if the connector supports it. | ||
if dc, ok := connector.(database.DialerConnector); ok { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to drop a CRITICAL log if this type assertion fails, since it means we've introduced a new driver that doesn't support a Dialer and our logs will be incomplete. |
||
dc.Dialer(dialer) | ||
} | ||
|
||
p.pgListener = pqListenerShim{ | ||
Listener: pq.NewDialListener(dialer, connectURL, time.Second, time.Minute, func(t pq.ListenerEventType, err error) { | ||
Listener: pq.NewConnectorListener(connector, connectURL, time.Second, time.Minute, func(t pq.ListenerEventType, err error) { | ||
switch t { | ||
case pq.ListenerEventConnected: | ||
p.logger.Info(ctx, "pubsub connected to postgres") | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍