Files
CrimsonandGitHub 61cae8af0a chore: Move all CE plugins to own go modules (#780)
* Move all public connectors to ce/plugins

* Update tooling to account for new go modules under ce

* Ensure we test all CE plugins in CI

* Move Dummypay to ce/plugins for simplicity's sake in the generation scripts

* Use versioned pkg/domain in plugins

* Ensure that renovate updates all CE plugins in a single PR when pkg/domain tags are pushed to github

* Ensure Justfile commands work over all CE plugins

* Copy ce plugin go.mods in dev.Dockerfile

* Only add a go.mod for new plugins if they are ce

* Ensure generated generic client structs are named correctly for submodule

* Add coverprofile for each ce plugin

* Add set -e for Justfile for loops over plugins

* Infer go version from flake.nix in connector template tool
2026-07-01 14:53:02 +00:00

60 lines
1.3 KiB
Go

package hmac
import (
"time"
"github.com/google/uuid"
"github.com/pkg/errors"
)
const (
authorizationHeader = "Authorization"
dateHeader = "Date"
emptyString = ""
nonceHeader = "x-mod-nonce"
retry = "x-mod-retry"
retryTrue = "true"
retryFalse = "false"
)
var ErrInvalidCredentials = errors.New("invalid api credentials")
func GenerateHeaders(apiKey, apiSecret, nonce string, hasRetry bool) (map[string]string, error) {
if apiKey == "" || apiSecret == "" {
return nil, ErrInvalidCredentials
}
return constructHeadersMap(apiKey, apiSecret, nonce, hasRetry, time.Now()), nil
}
func constructHeadersMap(apiKey, apiSecret, nonce string, hasRetry bool,
timestamp time.Time,
) map[string]string {
headers := make(map[string]string)
date := timestamp.Format(time.RFC1123)
nonce = generateNonceIfEmpty(nonce)
headers[dateHeader] = date
headers[authorizationHeader] = buildSignature(apiKey, apiSecret, nonce, date)
headers[nonceHeader] = nonce
headers[retry] = parseRetryBool(hasRetry)
return headers
}
func generateNonceIfEmpty(nonce string) string {
if nonce == emptyString {
nonce = uuid.New().String()
}
return nonce
}
func parseRetryBool(hasRetry bool) string {
if hasRetry {
return retryTrue
}
return retryFalse
}