github.com/wrgl/wrgl@v0.14.0/pkg/conf/config.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright © 2022 Wrangle Ltd 3 4 package conf 5 6 import ( 7 "time" 8 ) 9 10 const ( 11 DefaultTransactionTTL Duration = Duration(time.Hour * 24 * 30) 12 ) 13 14 type User struct { 15 // Email is the current user's email. Just like 16 // with Git, most operations that alter data record the user's 17 // email. Unlike Git however, email is always required. 18 Email string `yaml:"email,omitempty" json:"email,omitempty"` 19 20 // Name is the current user's name. 21 Name string `yaml:"name,omitempty" json:"name,omitempty"` 22 } 23 24 type Receive struct { 25 // DenyNonFastForwards, when set to `true`, during push, Wrgld denies all updates that 26 // are not fast-forwards. 27 DenyNonFastForwards *bool `yaml:"denyNonFastForwards,omitempty" json:"denyNonFastForwards,omitempty"` 28 29 // DenyDeletes, when set to `true`, during push, Wrgld denies all reference deletes. 30 DenyDeletes *bool `yaml:"denyDeletes,omitempty" json:"denyDeletes,omitempty"` 31 } 32 33 type Branch struct { 34 // Remote is the upstream remote of this branch. When both this setting and Merge is set, 35 // user can run `wrgl pull <branch>` without specifying remote and refspec. 36 Remote string `yaml:"remote,omitempty" json:"remote,omitempty"` 37 38 // Merge is the upstream destination of this branch. When both this setting and Remote is 39 // set, user can run `wrgl pull <branch>` without specifying remote and refspec. 40 Merge string `yaml:"merge,omitempty" json:"merge,omitempty"` 41 42 // File is the path of a file to diff against, or commit to this branch if no file is specified. 43 File string `yaml:"file,omitempty" json:"file,omitempty"` 44 45 // PrimaryKey is the primary key used in addition to branch.file during diff or commit if 46 // no file is specified. 47 PrimaryKey []string `yaml:"primaryKey,omitempty" json:"primaryKey,omitempty"` 48 49 // Delimiter is the CSV delimiter of File. Defaults to comma. 50 Delimiter rune `yaml:"delimiter,omitempty" json:"delimiter,omitempty"` 51 } 52 53 type AuthKeycloak struct { 54 Issuer string `json:"issuer,omitempty" yaml:"issuer,omitempty"` 55 ExternalURL string `json:"externalUrl,omitempty" yaml:"externalUrl,omitempty"` 56 ClientID string `json:"clientId,omitempty" yaml:"clientId,omitempty"` 57 ClientSecret string `json:"clientSecret,omitempty" yaml:"clientSecret,omitempty"` 58 ResourceID string `json:"resourceId,omitempty" yaml:"resourceId,omitempty"` 59 } 60 61 type Auth struct { 62 // AnonymousRead when set to true, gives anonymous users "read" scope 63 AnonymousRead bool `yaml:"anonymousRead,omitempty" json:"anonymousRead,omitempty"` 64 65 // Keycloak contains Keycloak credentials of this repo as a resource server 66 Keycloak *AuthKeycloak `json:"keycloak,omitempty" yaml:"keycloak,omitempty"` 67 68 // RepositoryName is the UMA resource name of this repo 69 RepositoryName string `json:"repositoryName,omitempty" yaml:"repositoryName,omitempty"` 70 } 71 72 type Pack struct { 73 // MaxFileSize is the maximum packfile size in bytes. Note that unlike in Git, pack format 74 // is only used as a transport format during fetch and push. This size is pre-compression. 75 MaxFileSize uint64 `yaml:"maxFileSize,omitempty" json:"maxFileSize,omitempty"` 76 } 77 78 type FastForward string 79 80 func (s FastForward) String() string { 81 return string(s) 82 } 83 84 const ( 85 FF_Default FastForward = "" 86 FF_Only FastForward = "only" 87 FF_Never FastForward = "never" 88 ) 89 90 type Merge struct { 91 // FastForward controls how merge operations create new commit. By default, Wrgl will not 92 // create an extra merge commit when merging a commit that is a descendant of the latest commit. 93 // Instead, the tip of the branch is fast-forwarded. When set to FF_Never, this tells Wrgl 94 // to always create an extra merge commit in such a case. When set to FF_Only, this tells 95 // Wrgl to allow only fast-forward merges. 96 FastForward FastForward `yaml:"fastForward,omitempty" json:"fastForward,omitempty"` 97 } 98 99 type Cors struct { 100 AllowedOrigins []string `yaml:"allowedOrigins,omitempty" json:"allowedOrigins,omitempty"` 101 } 102 103 type Config struct { 104 User *User `yaml:"user,omitempty" json:"user,omitempty"` 105 Remote map[string]*Remote `yaml:"remote,omitempty" json:"remote,omitempty"` 106 Receive *Receive `yaml:"receive,omitempty" json:"receive,omitempty"` 107 Branch map[string]*Branch `yaml:"branch,omitempty" json:"branch,omitempty"` 108 Auth *Auth `yaml:"auth,omitempty" json:"auth,omitempty"` 109 Pack *Pack `yaml:"pack,omitempty" json:"pack,omitempty"` 110 Merge *Merge `yaml:"merge,omitempty" json:"merge,omitempty"` 111 BaseURL string `json:"baseUrl,omitempty" yaml:"baseUrl,omitempty"` 112 113 // TransactionTTL is the maximum amount of time a transaction can exist before 114 // being garbage-collected. Defaults to 30 days 115 TransactionTTL Duration `yaml:"transactionTTL,omitempty" json:"transactionTTL,omitempty"` 116 117 // wrgld send events to Webhooks according to registered event types 118 Webhooks []Webhook `yaml:"webhooks,omitempty" json:"webhooks,omitempty"` 119 120 // CORS settings 121 Cors *Cors `yaml:"cors,omitempty" json:"cors,omitempty"` 122 } 123 124 func (c *Config) MaxPackFileSize() uint64 { 125 if c.Pack != nil { 126 return c.Pack.MaxFileSize 127 } 128 return 0 129 } 130 131 func (c *Config) GetTransactionTTL() time.Duration { 132 if c.TransactionTTL != 0 { 133 return time.Duration(c.TransactionTTL) 134 } 135 return time.Duration(DefaultTransactionTTL) 136 } 137 138 func (c *Config) MergeFastForward() FastForward { 139 if c.Merge != nil && c.Merge.FastForward != "" { 140 return c.Merge.FastForward 141 } 142 return FF_Default 143 }