feat: Add HMAC-SHA256 authentication utilities to Terraform provider client

- Add crypto/hmac, crypto/sha256, and encoding/base64 imports
- Add hmacSHA256 function for HMAC-SHA256 signature generation with base64 URL encoding
- Add base64URLEncode helper function for URL-safe base64 encoding
- Add reference implementation comments for SDK compatibility
This commit is contained in:
nutcas3
2026-04-25 05:09:35 +03:00
parent ea20dfb302
commit 70504379c5
+17
View File
@@ -3,6 +3,9 @@ package main
import (
"bytes"
"context"
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
@@ -120,3 +123,17 @@ func (c *APIClient) delete(ctx context.Context, path string) error {
return nil
}
// HMAC-SHA256 implementation
// In production, Go's crypto/hmac package provides proper HMAC implementation
// This is a reference implementation for SDK compatibility
func hmacSHA256(data string, secret string) string {
h := hmac.New(sha256.New, []byte(secret))
h.Write([]byte(data))
return base64URLEncode(h.Sum(nil))
}
// Base64 URL encoding
func base64URLEncode(data []byte) string {
return base64.URLEncoding.EncodeToString(data)
}