2023-09-12 04:16:35 +01:00
// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
package console
import (
"encoding/json"
"time"
"github.com/spf13/pflag"
"storj.io/common/storj"
)
// Config keeps track of core console service configuration parameters.
type Config struct {
2023-10-17 11:08:19 +01:00
PasswordCost int ` help:"password hashing cost (0=automatic)" testDefault:"4" default:"0" `
OpenRegistrationEnabled bool ` help:"enable open registration" default:"false" testDefault:"true" `
DefaultProjectLimit int ` help:"default project limits for users" default:"1" testDefault:"5" `
AsOfSystemTimeDuration time . Duration ` help:"default duration for AS OF SYSTEM TIME" devDefault:"-5m" releaseDefault:"-5m" testDefault:"0" `
LoginAttemptsWithoutPenalty int ` help:"number of times user can try to login without penalty" default:"3" `
FailedLoginPenalty float64 ` help:"incremental duration of penalty for failed login attempts in minutes" default:"2.0" `
ProjectInvitationExpiration time . Duration ` help:"duration that project member invitations are valid for" default:"168h" `
UnregisteredInviteEmailsEnabled bool ` help:"indicates whether invitation emails can be sent to unregistered email addresses" default:"false" `
2023-10-18 20:19:40 +01:00
FreeTierInvitesEnabled bool ` help:"indicates whether free tier users can send project invitations" default:"false" `
2023-10-17 11:08:19 +01:00
UserBalanceForUpgrade int64 ` help:"amount of base units of US micro dollars needed to upgrade user's tier status" default:"10000000" `
PlacementEdgeURLOverrides PlacementEdgeURLOverrides ` help:"placement-specific edge service URL overrides in the format { \"placementID\": { \"authService\": \"...\", \"publicLinksharing\": \"...\", \"internalLinksharing\": \"...\"}, \"placementID2\": ...}" `
BlockExplorerURL string ` help:"url of the transaction block explorer" default:"https://etherscan.io/" `
2023-10-18 23:10:23 +01:00
BillingFeaturesEnabled bool ` help:"indicates if billing features should be enabled" default:"true" `
2023-11-10 17:21:56 +00:00
StripePaymentElementEnabled bool ` help:"indicates whether the stripe payment element should be used to collect card info" default:"true" `
2023-10-17 11:08:19 +01:00
UsageLimits UsageLimitsConfig
Captcha CaptchaConfig
Session SessionConfig
2023-10-19 16:57:01 +01:00
AccountFreeze AccountFreezeConfig
2023-09-12 04:16:35 +01:00
}
// CaptchaConfig contains configurations for login/registration captcha system.
type CaptchaConfig struct {
Login MultiCaptchaConfig ` json:"login" `
Registration MultiCaptchaConfig ` json:"registration" `
}
// MultiCaptchaConfig contains configurations for Recaptcha and Hcaptcha systems.
type MultiCaptchaConfig struct {
Recaptcha SingleCaptchaConfig ` json:"recaptcha" `
Hcaptcha SingleCaptchaConfig ` json:"hcaptcha" `
}
// SingleCaptchaConfig contains configurations abstract captcha system.
type SingleCaptchaConfig struct {
Enabled bool ` help:"whether or not captcha is enabled" default:"false" json:"enabled" `
SiteKey string ` help:"captcha site key" json:"siteKey" `
SecretKey string ` help:"captcha secret key" json:"-" `
}
// SessionConfig contains configurations for session management.
type SessionConfig struct {
InactivityTimerEnabled bool ` help:"indicates if session can be timed out due inactivity" default:"true" `
InactivityTimerDuration int ` help:"inactivity timer delay in seconds" default:"600" `
InactivityTimerViewerEnabled bool ` help:"indicates whether remaining session time is shown for debugging" default:"false" `
Duration time . Duration ` help:"duration a session is valid for (superseded by inactivity timer delay if inactivity timer is enabled)" default:"168h" `
}
// EdgeURLOverrides contains edge service URL overrides.
type EdgeURLOverrides struct {
AuthService string ` json:"authService,omitempty" `
PublicLinksharing string ` json:"publicLinksharing,omitempty" `
InternalLinksharing string ` json:"internalLinksharing,omitempty" `
}
// PlacementEdgeURLOverrides represents a mapping between placement IDs and edge service URL overrides.
type PlacementEdgeURLOverrides struct {
overrideMap map [ storj . PlacementConstraint ] EdgeURLOverrides
}
// Ensure that PlacementEdgeOverrides implements pflag.Value.
var _ pflag . Value = ( * PlacementEdgeURLOverrides ) ( nil )
// Type implements pflag.Value.
func ( PlacementEdgeURLOverrides ) Type ( ) string { return "console.PlacementEdgeURLOverrides" }
// String implements pflag.Value.
func ( ov * PlacementEdgeURLOverrides ) String ( ) string {
if ov == nil || len ( ov . overrideMap ) == 0 {
return ""
}
overrides , err := json . Marshal ( ov . overrideMap )
if err != nil {
return ""
}
return string ( overrides )
}
// Set implements pflag.Value.
func ( ov * PlacementEdgeURLOverrides ) Set ( s string ) error {
if s == "" {
return nil
}
overrides := make ( map [ storj . PlacementConstraint ] EdgeURLOverrides )
err := json . Unmarshal ( [ ] byte ( s ) , & overrides )
if err != nil {
return err
}
ov . overrideMap = overrides
return nil
}
// Get returns the edge service URL overrides for the given placement ID.
func ( ov * PlacementEdgeURLOverrides ) Get ( placement storj . PlacementConstraint ) ( overrides EdgeURLOverrides , ok bool ) {
if ov == nil {
return EdgeURLOverrides { } , false
}
overrides , ok = ov . overrideMap [ placement ]
return overrides , ok
}