Skip to content

Commit

Permalink
Merge pull request #125 from xmidt-org/denopink/feat/support-openfail…
Browse files Browse the repository at this point in the history
…-by-default

feat: support openfail by default
  • Loading branch information
schmidtw authored May 15, 2024
2 parents 8323541 + a9f666f commit 201d84e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
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)
// Allow operations where no credentials are desired (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
11 changes: 8 additions & 3 deletions cmd/xmidt-agent/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,14 @@ func provideWS(in wsIn) (wsOut, error) {
return wsOut{}, err
}

var opts []websocket.Option
// Allow operations where no credentials are desired (in.Cred will be nil).
if in.Cred != nil {
opts = append(opts, websocket.CredentialsDecorator(in.Cred.Decorate))
}

// Configuration options
opts := []websocket.Option{
opts = append(opts,
websocket.DeviceID(in.Identity.DeviceID),
websocket.FetchURLTimeout(in.Websocket.FetchURLTimeout),
websocket.FetchURL(
Expand All @@ -76,15 +82,14 @@ 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.ConveyDecorator(in.Metadata.Decorate),
websocket.AdditionalHeaders(in.Websocket.AdditionalHeaders),
websocket.NowFunc(time.Now),
websocket.WithIPv6(!in.Websocket.DisableV6),
websocket.WithIPv4(!in.Websocket.DisableV4),
websocket.Once(in.Websocket.Once),
websocket.RetryPolicy(in.Websocket.RetryPolicy),
}
)

// Listener options
var (
Expand Down
2 changes: 1 addition & 1 deletion internal/websocket/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (ws *Websocket) run(ctx context.Context) {
Mode: mode.ToEvent(),
}

// If auth fails, then continue with openfail xmidt connection
// If auth fails, then continue with no credentials.
ws.credDecorator(ws.additionalHeaders)

ws.conveyDecorator(ws.additionalHeaders)
Expand Down

0 comments on commit 201d84e

Please sign in to comment.