feat: add online payment management and checkout
Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
@@ -11,15 +11,16 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
HTTPAddr string
|
||||
TrustedProxies []string
|
||||
ReadHeaderTimeout time.Duration
|
||||
ReadTimeout time.Duration
|
||||
WriteTimeout time.Duration
|
||||
IdleTimeout time.Duration
|
||||
ShutdownTimeout time.Duration
|
||||
SigningPrivateKeyPEM string
|
||||
CredentialEncryptionKey []byte
|
||||
HTTPAddr string
|
||||
TrustedProxies []string
|
||||
ReadHeaderTimeout time.Duration
|
||||
ReadTimeout time.Duration
|
||||
WriteTimeout time.Duration
|
||||
IdleTimeout time.Duration
|
||||
ShutdownTimeout time.Duration
|
||||
SigningPrivateKeyPEM string
|
||||
CredentialEncryptionKey []byte
|
||||
PaymentConfigEncryptionKey []byte
|
||||
}
|
||||
|
||||
func Load(getenv func(string) string) (Config, error) {
|
||||
@@ -96,6 +97,16 @@ func Load(getenv func(string) string) (Config, error) {
|
||||
}
|
||||
c.CredentialEncryptionKey = data
|
||||
}
|
||||
if path := getenv("PAYMENT_CONFIG_ENCRYPTION_KEY_FILE"); path != "" {
|
||||
if !filepath.IsAbs(path) {
|
||||
return Config{}, fmt.Errorf("PAYMENT_CONFIG_ENCRYPTION_KEY_FILE must be absolute")
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil || len(data) != 32 {
|
||||
return Config{}, fmt.Errorf("payment config encryption key must be exactly 32 raw bytes")
|
||||
}
|
||||
c.PaymentConfigEncryptionKey = data
|
||||
}
|
||||
if root := getenv("PACKAGE_STORAGE_ROOT"); root != "" {
|
||||
if !filepath.IsAbs(root) {
|
||||
return Config{}, fmt.Errorf("PACKAGE_STORAGE_ROOT must be absolute")
|
||||
|
||||
@@ -63,6 +63,36 @@ func TestLoadRejectsInvalid(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPaymentConfigKeyFile(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "payments.key")
|
||||
for _, size := range []int{31, 32, 33} {
|
||||
if err := os.WriteFile(path, make([]byte, size), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c, err := Load(func(name string) string {
|
||||
if name == "PAYMENT_CONFIG_ENCRYPTION_KEY_FILE" {
|
||||
return path
|
||||
}
|
||||
return ""
|
||||
})
|
||||
if size == 32 {
|
||||
if err != nil || len(c.PaymentConfigEncryptionKey) != 32 || len(c.CredentialEncryptionKey) != 0 {
|
||||
t.Fatal("independent payment key loading failed")
|
||||
}
|
||||
} else if err == nil {
|
||||
t.Fatal("invalid payment key length accepted")
|
||||
}
|
||||
}
|
||||
if _, err := Load(func(name string) string {
|
||||
if name == "PAYMENT_CONFIG_ENCRYPTION_KEY_FILE" {
|
||||
return "relative/payments.key"
|
||||
}
|
||||
return ""
|
||||
}); err == nil {
|
||||
t.Fatal("relative payment key accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCredentialKeyFile(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "credentials.key")
|
||||
for _, size := range []int{31, 32, 33} {
|
||||
|
||||
Reference in New Issue
Block a user