Return errors for Go Local Vault marshal failures
This commit is contained in:
@@ -431,13 +431,17 @@ func (c *Client) RevokeLocalVaultInstallation(ctx context.Context, installationI
|
||||
|
||||
func (c *Client) RelayLocalVaultEvent(ctx context.Context, installationID string, envelope M, payload M, envelopeHash, signatureHex, publicKeyHex string) (*EventReceipt, error) {
|
||||
body := M{"envelope": envelope, "payload": payload}
|
||||
raw, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("marshal local vault event: %w", err)
|
||||
}
|
||||
headers := map[string]string{
|
||||
"X-Attesto-Local-Vault-Envelope-Hash": envelopeHash,
|
||||
"X-Attesto-Local-Vault-Signature": signatureHex,
|
||||
"X-Attesto-Local-Vault-Public-Key": publicKeyHex,
|
||||
}
|
||||
var out EventReceipt
|
||||
err := c.requestRaw(ctx, http.MethodPost, "/v2/local-vault/installations/"+url.PathEscape(installationID)+"/events", nil, mustJSON(body), headers, "", &out)
|
||||
err = c.requestRaw(ctx, http.MethodPost, "/v2/local-vault/installations/"+url.PathEscape(installationID)+"/events", nil, raw, headers, "", &out)
|
||||
return &out, err
|
||||
}
|
||||
|
||||
@@ -650,14 +654,6 @@ func sleep(attempt int) {
|
||||
time.Sleep(time.Duration(100*attempt) * time.Millisecond)
|
||||
}
|
||||
|
||||
func mustJSON(value any) []byte {
|
||||
raw, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return raw
|
||||
}
|
||||
|
||||
func sanitizeMessage(message string) string {
|
||||
for _, marker := range []string{"sk_live_", "sk_test_", "pk_live_", "pk_test_", "npm_", "pypi-", "atto_live_", "atto_test_"} {
|
||||
if strings.Contains(message, marker) {
|
||||
|
||||
Reference in New Issue
Block a user