github.com/kvattikuti/drone@v0.2.1-0.20140603034306-d400229a327a/pkg/plugin/publish/swift.go (about)

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