Skip to content
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

feat: support openfail by default #125

Merged
merged 5 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions cmd/xmidt-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,14 @@ func onStart(cred *credentials.Credentials, ws *websocket.Websocket, qos *qos.Ha
return nil
}

ctx, cancel := context.WithTimeout(ctx, waitUntilFetched)
defer cancel()
// blocks until an attempt to fetch the credentials has been made or the context is canceled
cred.WaitUntilFetched(ctx)
// in case of openfail, cred will be nil
if cred != nil {
ctx, cancel := context.WithTimeout(ctx, waitUntilFetched)
defer cancel()
// blocks until an attempt to fetch the credentials has been made or the context is canceled
cred.WaitUntilFetched(ctx)
}

ws.Start()
qos.Start()

Expand Down
10 changes: 9 additions & 1 deletion cmd/xmidt-agent/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"context"
"errors"
"net/http"
"net/url"
"time"

Expand Down Expand Up @@ -58,6 +59,13 @@ func provideWS(in wsIn) (wsOut, error) {
fetchURLFunc = in.JWTXT.Endpoint
}

credDecorator := func(http.Header) error { return nil }
denopink marked this conversation as resolved.
Show resolved Hide resolved
// Cred is not required
// credDecorator() will default to openfail if in.Cred is nil
if in.Cred != nil {
credDecorator = in.Cred.Decorate
}

client, err := in.Websocket.HTTPClient.NewClient()
if err != nil {
return wsOut{}, err
Expand All @@ -76,7 +84,7 @@ func provideWS(in wsIn) (wsOut, error) {
websocket.KeepAliveInterval(in.Websocket.KeepAliveInterval),
websocket.HTTPClient(client),
websocket.MaxMessageBytes(in.Websocket.MaxMessageBytes),
websocket.CredentialsDecorator(in.Cred.Decorate),
websocket.CredentialsDecorator(credDecorator),
websocket.ConveyDecorator(in.Metadata.Decorate),
websocket.AdditionalHeaders(in.Websocket.AdditionalHeaders),
websocket.NowFunc(time.Now),
Expand Down
Loading