github.com/cloudfoundry-incubator/stembuild@v0.0.0-20211223202937-5b61d62226c6/package_stemcell/config/source_config.go (about) 1 package config 2 3 import "errors" 4 5 type SourceConfig struct { 6 Vmdk string 7 URL string 8 Username string 9 Password string 10 VmInventoryPath string 11 CaCertFile string 12 } 13 14 type Source int 15 16 const ( 17 VMDK Source = iota 18 VCENTER 19 NIL 20 ) 21 22 func (c SourceConfig) GetSource() (Source, error) { 23 if c.vmdkProvided() && c.partialvCenterProvided() { 24 return NIL, errors.New("configuration provided for VMDK & vCenter sources") 25 } 26 27 if c.vmdkProvided() { 28 return VMDK, nil 29 } 30 31 if c.vcenterProvided() { 32 return VCENTER, nil 33 } 34 35 if c.partialvCenterProvided() { 36 return NIL, errors.New("missing vCenter configurations") 37 } 38 39 return NIL, errors.New("no configuration was provided") 40 } 41 42 func (c SourceConfig) vmdkProvided() bool { 43 return c.Vmdk != "" 44 } 45 46 func (c SourceConfig) vcenterProvided() bool { 47 if c.VmInventoryPath != "" && c.Username != "" && c.Password != "" && c.URL != "" { 48 return true 49 } 50 return false 51 } 52 53 //At least one vCenter configuration given 54 func (c SourceConfig) partialvCenterProvided() bool { 55 if c.VmInventoryPath != "" || c.Username != "" || c.Password != "" || c.URL != "" { 56 return true 57 } 58 return false 59 }