github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/storageprovisioner/config.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package storageprovisioner 5 6 import ( 7 "github.com/juju/clock" 8 "github.com/juju/errors" 9 "gopkg.in/juju/names.v2" 10 11 environscontext "github.com/juju/juju/environs/context" 12 "github.com/juju/juju/storage" 13 ) 14 15 // Config holds configuration and dependencies for a storageprovisioner worker. 16 type Config struct { 17 Model names.ModelTag 18 Scope names.Tag 19 StorageDir string 20 Applications ApplicationWatcher 21 Volumes VolumeAccessor 22 Filesystems FilesystemAccessor 23 Life LifecycleManager 24 Registry storage.ProviderRegistry 25 Machines MachineAccessor 26 Status StatusSetter 27 Clock clock.Clock 28 CloudCallContext environscontext.ProviderCallContext 29 } 30 31 // Validate returns an error if the config cannot be relied upon to start a worker. 32 func (config Config) Validate() error { 33 switch config.Scope.(type) { 34 case nil: 35 return errors.NotValidf("nil Scope") 36 case names.ModelTag: 37 if config.StorageDir != "" { 38 return errors.NotValidf("environ Scope with non-empty StorageDir") 39 } 40 case names.MachineTag: 41 if config.StorageDir == "" { 42 return errors.NotValidf("machine Scope with empty StorageDir") 43 } 44 if config.Machines == nil { 45 return errors.NotValidf("nil Machines") 46 } 47 case names.ApplicationTag: 48 if config.StorageDir != "" { 49 return errors.NotValidf("application Scope with StorageDir") 50 } 51 if config.Applications == nil { 52 return errors.NotValidf("nil Applications") 53 } 54 default: 55 return errors.NotValidf("%T Scope", config.Scope) 56 } 57 if config.Volumes == nil { 58 return errors.NotValidf("nil Volumes") 59 } 60 if config.Filesystems == nil { 61 return errors.NotValidf("nil Filesystems") 62 } 63 if config.Life == nil { 64 return errors.NotValidf("nil Life") 65 } 66 if config.Registry == nil { 67 return errors.NotValidf("nil Registry") 68 } 69 if config.Status == nil { 70 return errors.NotValidf("nil Status") 71 } 72 if config.Clock == nil { 73 return errors.NotValidf("nil Clock") 74 } 75 if config.CloudCallContext == nil { 76 return errors.NotValidf("nil CloudCallContext") 77 } 78 return nil 79 }