github.com/robryk/drone@v0.2.1-0.20140602202253-40fe4305815d/pkg/plugin/publish/swift.go (about) 1 package publish 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/drone/drone/pkg/build/buildfile" 8 ) 9 10 type Swift struct { 11 // Username for authentication 12 Username string `yaml:"username,omitempty"` 13 14 // Password for authentication 15 // With Rackspace this is usually an API Key 16 Password string `yaml:"password,omitempty"` 17 18 // Container to upload files to 19 Container string `yaml:"container,omitempty"` 20 21 // Base API version URL to authenticate against 22 // Rackspace: https://identity.api.rackspacecloud.com/v2.0 23 AuthURL string `yaml:"auth_url,omitempty"` 24 25 // Region to communicate with, in a generic OpenStack install 26 // this may be RegionOne 27 Region string `yaml:"region,omitempty"` 28 29 // Source file or directory to upload, if source is a directory, 30 // upload the contents of the directory 31 Source string `yaml:"source,omitempty"` 32 33 // Destination to write the file(s) to. Should contain the full 34 // object name if source is a file 35 Target string `yaml:"target,omitempty"` 36 37 Branch string `yaml:"branch,omitempty"` 38 } 39 40 func (s *Swift) Write(f *buildfile.Buildfile) { 41 var target string 42 // All options are required, so ensure they are present 43 if len(s.Username) == 0 || len(s.Password) == 0 || len(s.AuthURL) == 0 || len(s.Region) == 0 || len(s.Source) == 0 || len(s.Container) == 0 { 44 f.WriteCmdSilent(`echo "Swift: Missing argument(s)"`) 45 return 46 } 47 48 // If a target was provided, prefix it with a / 49 if len(s.Target) > 0 { 50 target = fmt.Sprintf("/%s", strings.TrimPrefix(s.Target, "/")) 51 } 52 53 // debugging purposes so we can see if / where something is failing 54 f.WriteCmdSilent(`echo "Swift: Publishing..."`) 55 56 // install swiftly using PIP 57 f.WriteCmdSilent("[ -f /usr/bin/sudo ] || pip install swiftly 1> /dev/null 2> /dev/null") 58 f.WriteCmdSilent("[ -f /usr/bin/sudo ] && sudo pip install swiftly 1> /dev/null 2> /dev/null") 59 60 // Write out environment variables 61 f.WriteEnv("SWIFTLY_AUTH_URL", s.AuthURL) 62 f.WriteEnv("SWIFTLY_AUTH_USER", s.Username) 63 f.WriteEnv("SWIFTLY_AUTH_KEY", s.Password) 64 f.WriteEnv("SWIFTLY_REGION", s.Region) 65 66 f.WriteCmd(fmt.Sprintf(`swiftly put -i %s %s%s`, s.Source, s.Container, target)) 67 }