Skip to content

Commit

Permalink
fixup! provisioning: use structured logging
Browse files Browse the repository at this point in the history
Signed-off-by: Sumner Evans <[email protected]>
  • Loading branch information
sumnerevans committed Dec 31, 2023
1 parent 00b53ea commit 0d5d400
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions pkg/signalmeow/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ func PerformProvisioning(incomingCtx context.Context, deviceStore DeviceStore, d

ctx, cancel := context.WithTimeout(incomingCtx, 2*time.Minute)
defer cancel()
ws, err := openProvisioningWebsocket(ctx)
ws, resp, err := web.OpenWebsocket(ctx, web.WebsocketProvisioningPath)
if err != nil {
zlog.Err(err).Msg("openProvisioningWebsocket error")
zlog.Err(err).Any("resp", resp).Msg("error opening provisioning websocket")
c <- ProvisioningResponse{State: StateProvisioningError, Err: err}
return
}
Expand Down Expand Up @@ -243,15 +243,6 @@ func PerformProvisioning(incomingCtx context.Context, deviceStore DeviceStore, d
return c
}

func openProvisioningWebsocket(ctx context.Context) (*websocket.Conn, error) {
ws, resp, err := web.OpenWebsocket(ctx, web.WebsocketProvisioningPath)
if err != nil {
zlog.Err(err).Msgf("openWebsocket error, resp : %v", resp)
return nil, err
}
return ws, nil
}

// Returns the provisioningUrl and an error
func startProvisioning(ctx context.Context, ws *websocket.Conn, provisioningCipher *ProvisioningCipher) (string, error) {
pubKey := provisioningCipher.GetPublicKey()
Expand Down Expand Up @@ -347,7 +338,7 @@ func confirmDevice(

ws, resp, err := web.OpenWebsocket(ctx, web.WebsocketPath)
if err != nil {
zlog.Err(err).Msgf("openWebsocket error, resp : %v", resp)
zlog.Err(err).Any("resp", resp).Msg("error opening websocket")
return nil, err
}
defer ws.Close(websocket.StatusInternalError, "Websocket StatusInternalError")
Expand Down Expand Up @@ -379,7 +370,7 @@ func confirmDevice(

jsonBytes, err := json.Marshal(data)
if err != nil {
zlog.Err(err).Msgf("failed to marshal json: %v", resp)
zlog.Err(err).Msg("failed to marshal JSON")
return nil, err
}

Expand All @@ -394,29 +385,29 @@ func confirmDevice(
}
err = wspb.Write(ctx, ws, message)
if err != nil {
zlog.Err(err).Msgf("failed on write %v", resp)
zlog.Err(err).Msg("failed on write protobuf data to websocket")
return nil, err
}

receivedMsg := &signalpb.WebSocketMessage{}
err = wspb.Read(ctx, ws, receivedMsg)
if err != nil {
zlog.Err(err).Msgf("failed to read after devices call: %v", resp)
zlog.Err(err).Msg("failed to read from websocket after devices call")
return nil, err
}

status := int(*receivedMsg.Response.Status)
if status < 200 || status >= 300 {
err := fmt.Errorf("problem with devices response - status: %d, message: %s", status, *receivedMsg.Response.Message)
zlog.Err(err).Msg("")
zlog.Err(err).Msg("non-200 status code from devices response")
return nil, err
}

// unmarshal JSON response into ConfirmDeviceResponse
deviceResp := ConfirmDeviceResponse{}
err = json.Unmarshal(receivedMsg.Response.Body, &deviceResp)
if err != nil {
zlog.Err(err).Msgf("failed to unmarshal json: %v", receivedMsg.Response.Body)
zlog.Err(err).Msg("failed to unmarshal JSON")
return nil, err
}

Expand Down

0 comments on commit 0d5d400

Please sign in to comment.