12 "git.curoverse.com/arvados.git/sdk/go/arvados"
24 BlobSignatureTTL arvados.Duration
25 BlobSigningKeyFile string
26 RequireSignatures bool
27 SystemAuthTokenFile string
29 TrashLifetime arvados.Duration
30 TrashCheckInterval arvados.Duration
35 systemAuthToken string
36 debugLogf func(string, ...interface{})
39 var theConfig = DefaultConfig()
41 // DefaultConfig returns the default configuration.
42 func DefaultConfig() *Config {
46 RequireSignatures: true,
47 BlobSignatureTTL: arvados.Duration(14 * 24 * time.Hour),
48 TrashLifetime: arvados.Duration(14 * 24 * time.Hour),
49 TrashCheckInterval: arvados.Duration(24 * time.Hour),
54 // Start should be called exactly once: after setting all public
55 // fields, and before using the config.
56 func (cfg *Config) Start() error {
58 cfg.debugLogf = log.Printf
59 cfg.debugLogf("debugging enabled")
61 cfg.debugLogf = func(string, ...interface{}) {}
64 if cfg.MaxBuffers < 0 {
65 return fmt.Errorf("MaxBuffers must be greater than zero")
67 bufs = newBufferPool(cfg.MaxBuffers, BlockSize)
69 if cfg.MaxRequests < 1 {
70 cfg.MaxRequests = cfg.MaxBuffers * 2
71 log.Printf("MaxRequests <1 or not specified; defaulting to MaxBuffers * 2 == %d", cfg.MaxRequests)
74 if cfg.BlobSigningKeyFile != "" {
75 buf, err := ioutil.ReadFile(cfg.BlobSigningKeyFile)
77 return fmt.Errorf("reading blob signing key file: %s", err)
79 cfg.blobSigningKey = bytes.TrimSpace(buf)
80 if len(cfg.blobSigningKey) == 0 {
81 return fmt.Errorf("blob signing key file %q is empty", cfg.BlobSigningKeyFile)
83 } else if cfg.RequireSignatures {
84 return fmt.Errorf("cannot enable RequireSignatures (-enforce-permissions) without a blob signing key")
86 log.Println("Running without a blob signing key. Block locators " +
87 "returned by this server will not be signed, and will be rejected " +
88 "by a server that enforces permissions.")
89 log.Println("To fix this, use the BlobSigningKeyFile config entry.")
92 if fn := cfg.SystemAuthTokenFile; fn != "" {
93 buf, err := ioutil.ReadFile(fn)
95 return fmt.Errorf("cannot read system auth token file %q: %s", fn, err)
97 cfg.systemAuthToken = strings.TrimSpace(string(buf))
100 if cfg.EnableDelete {
101 log.Print("Trash/delete features are enabled. WARNING: this has not " +
102 "been extensively tested. You should disable this unless you can afford to lose data.")
105 if len(cfg.Volumes) == 0 {
106 if (&unixVolumeAdder{cfg}).Discover() == 0 {
107 return fmt.Errorf("no volumes found")
110 for _, v := range cfg.Volumes {
111 if err := v.Start(); err != nil {
112 return fmt.Errorf("volume %s: %s", v, err)
114 log.Printf("Using volume %v (writable=%v)", v, v.Writable())
119 // VolumeTypes is built up by init() funcs in the source files that
120 // define the volume types.
121 var VolumeTypes = []func() VolumeWithExamples{}
123 type VolumeList []Volume
125 // UnmarshalJSON, given an array of objects, deserializes each object
126 // as the volume type indicated by the object's Type field.
127 func (vols *VolumeList) UnmarshalJSON(data []byte) error {
128 typeMap := map[string]func() VolumeWithExamples{}
129 for _, factory := range VolumeTypes {
130 t := factory().Type()
131 if _, ok := typeMap[t]; ok {
132 log.Fatal("volume type %+q is claimed by multiple VolumeTypes")
137 var mapList []map[string]interface{}
138 err := json.Unmarshal(data, &mapList)
142 for _, mapIn := range mapList {
143 typeIn, ok := mapIn["Type"].(string)
145 return fmt.Errorf("invalid volume type %+v", mapIn["Type"])
147 factory, ok := typeMap[typeIn]
149 return fmt.Errorf("unsupported volume type %+q", typeIn)
151 data, err := json.Marshal(mapIn)
156 err = json.Unmarshal(data, vol)
160 *vols = append(*vols, vol)
165 // MarshalJSON adds a "Type" field to each volume corresponding to its
167 func (vl *VolumeList) MarshalJSON() ([]byte, error) {
169 for _, vs := range *vl {
170 j, err := json.Marshal(vs)
175 data = append(data, byte(','))
177 t, err := json.Marshal(vs.Type())
181 data = append(data, j[0])
182 data = append(data, []byte(`"Type":`)...)
183 data = append(data, t...)
184 data = append(data, byte(','))
185 data = append(data, j[1:]...)
187 return append(data, byte(']')), nil