github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/config/remote.go (about) 1 package config 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/qri-io/jsonschema" 8 ) 9 10 // Remotes is a named set of remote locations 11 type Remotes map[string]string 12 13 // SetArbitrary is for implementing the ArbitrarySetter interface defined by 14 // base/fill_struct.go 15 func (r *Remotes) SetArbitrary(key string, val interface{}) (err error) { 16 str, ok := val.(string) 17 if !ok { 18 return fmt.Errorf("invalid remote value: %s", val) 19 } 20 (*r)[key] = str 21 return nil 22 } 23 24 // Get retrieves an address from the name of remote 25 func (r *Remotes) Get(name string) (string, bool) { 26 if r == nil { 27 return "", false 28 } 29 addr, ok := (*r)[name] 30 return addr, ok 31 } 32 33 // Copy creates a copy of a Remotes struct 34 func (r *Remotes) Copy() *Remotes { 35 c := make(map[string]string) 36 for k, v := range *r { 37 c[k] = v 38 } 39 return (*Remotes)(&c) 40 } 41 42 // RemoteServer configures Qri to optionally accept requests from clients via 43 // network calls 44 type RemoteServer struct { 45 // remote mode 46 Enabled bool `json:"enabled"` 47 // maximum size of dataset to accept for remote mode 48 AcceptSizeMax int64 `json:"acceptsizemax"` 49 // timeout for remote sessions, in milliseconds 50 AcceptTimeoutMs time.Duration `json:"accepttimeoutms"` 51 // require clients pushing blocks to send all blocks 52 RequireAllBlocks bool `json:"requireallblocks"` 53 // allow clients to request unpins for their own pushes 54 AllowRemoves bool `json:"allowremoves"` 55 } 56 57 // SetArbitrary is an interface implementation of base/fill/struct in order to safely 58 // consume config files that have definitions beyond those specified in the struct. 59 // This simply ignores all additional fields at read time. 60 func (cfg *RemoteServer) SetArbitrary(key string, val interface{}) error { 61 return nil 62 } 63 64 // Validate validates all fields of render returning all errors found. 65 func (cfg RemoteServer) Validate() error { 66 schema := jsonschema.Must(`{ 67 "$schema": "http://json-schema.org/draft-06/schema#", 68 "title": "RemoteServer", 69 "description": "Configure Qri for control over the network", 70 "type": "object", 71 "properties": { 72 "templateUpdateAddress": { 73 "description": "address to check for app updates", 74 "type": "string" 75 }, 76 "defaultTemplateHash": { 77 "description": "A hash of the compiled render. This is fetched and replaced via dsnlink when the render server starts. The value provided here is just a sensible fallback for when dnslink lookup fails.", 78 "type": "string" 79 } 80 } 81 }`) 82 return validate(schema, &cfg) 83 } 84 85 // Copy returns a deep copy of the RemoteServer struct 86 func (cfg *RemoteServer) Copy() *RemoteServer { 87 res := &RemoteServer{ 88 Enabled: cfg.Enabled, 89 AcceptSizeMax: cfg.AcceptSizeMax, 90 AcceptTimeoutMs: cfg.AcceptTimeoutMs, 91 RequireAllBlocks: cfg.RequireAllBlocks, 92 AllowRemoves: cfg.AllowRemoves, 93 } 94 95 return res 96 }