Merge pull request #1924 from josmo/stash-rsa-string

Stash rsa string
This commit is contained in:
Brad Rydzewski 2017-02-11 16:22:58 +11:00 committed by GitHub
commit 505e36788e
3 changed files with 36 additions and 19 deletions

View file

@ -261,6 +261,11 @@ var serverCmd = cli.Command{
Name: "stash-consumer-rsa", Name: "stash-consumer-rsa",
Usage: "stash oauth1 private key file", Usage: "stash oauth1 private key file",
}, },
cli.StringFlag{
EnvVar: "DRONE_STASH_CONSUMER_RSA_STRING",
Name: "stash-consumer-rsa-string",
Usage: "stash oauth1 private key string",
},
cli.StringFlag{ cli.StringFlag{
EnvVar: "DRONE_STASH_GIT_USERNAME", EnvVar: "DRONE_STASH_GIT_USERNAME",
Name: "stash-git-username", Name: "stash-git-username",

View file

@ -27,12 +27,13 @@ const (
// Opts defines configuration options. // Opts defines configuration options.
type Opts struct { type Opts struct {
URL string // Stash server url. URL string // Stash server url.
Username string // Git machine account username. Username string // Git machine account username.
Password string // Git machine account password. Password string // Git machine account password.
ConsumerKey string // Oauth1 consumer key. ConsumerKey string // Oauth1 consumer key.
ConsumerRSA string // Oauth1 consumer key file. ConsumerRSA string // Oauth1 consumer key file.
SkipVerify bool // Skip ssl verification. ConsumerRSAString string
SkipVerify bool // Skip ssl verification.
} }
type Config struct { type Config struct {
@ -60,19 +61,29 @@ func New(opts Opts) (remote.Remote, error) {
return nil, fmt.Errorf("Must have a git machine account password") return nil, fmt.Errorf("Must have a git machine account password")
case opts.ConsumerKey == "": case opts.ConsumerKey == "":
return nil, fmt.Errorf("Must have a oauth1 consumer key") return nil, fmt.Errorf("Must have a oauth1 consumer key")
case opts.ConsumerRSA == "":
return nil, fmt.Errorf("Must have a oauth1 consumer key file")
} }
keyFile, err := ioutil.ReadFile(opts.ConsumerRSA) if opts.ConsumerRSA == "" && opts.ConsumerRSAString == "" {
if err != nil { return nil, fmt.Errorf("must have CONSUMER_RSA_KEY set to the path of a oauth1 consumer key file or CONSUMER_RSA_KEY_STRING set to the value of a oauth1 consumer key")
return nil, err
} }
block, _ := pem.Decode(keyFile)
var keyFileBytes []byte
if opts.ConsumerRSA != "" {
var err error
keyFileBytes, err = ioutil.ReadFile(opts.ConsumerRSA)
if err != nil {
return nil, err
}
} else {
keyFileBytes = []byte(opts.ConsumerRSAString)
}
block, _ := pem.Decode(keyFileBytes)
PrivateKey, err := x509.ParsePKCS1PrivateKey(block.Bytes) PrivateKey, err := x509.ParsePKCS1PrivateKey(block.Bytes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
config.Consumer = CreateConsumer(opts.URL, opts.ConsumerKey, PrivateKey) config.Consumer = CreateConsumer(opts.URL, opts.ConsumerKey, PrivateKey)
return config, nil return config, nil
} }
@ -154,7 +165,7 @@ func (c *Config) File(u *model.User, r *model.Repo, b *model.Build, f string) ([
} }
// Status is not supported by the bitbucketserver driver. // Status is not supported by the bitbucketserver driver.
func (c *Config) Status(u *model.User,r *model.Repo,b *model.Build,link string) error { func (c *Config) Status(u *model.User, r *model.Repo, b *model.Build, link string) error {
status := internal.BuildStatus{ status := internal.BuildStatus{
State: convertStatus(b.Status), State: convertStatus(b.Status),
Desc: convertDesc(b.Status), Desc: convertDesc(b.Status),

View file

@ -66,12 +66,13 @@ func setupGogs(c *cli.Context) (remote.Remote, error) {
// helper function to setup the Stash remote from the CLI arguments. // helper function to setup the Stash remote from the CLI arguments.
func setupStash(c *cli.Context) (remote.Remote, error) { func setupStash(c *cli.Context) (remote.Remote, error) {
return bitbucketserver.New(bitbucketserver.Opts{ return bitbucketserver.New(bitbucketserver.Opts{
URL: c.String("stash-server"), URL: c.String("stash-server"),
Username: c.String("stash-git-username"), Username: c.String("stash-git-username"),
Password: c.String("stash-git-password"), Password: c.String("stash-git-password"),
ConsumerKey: c.String("stash-consumer-key"), ConsumerKey: c.String("stash-consumer-key"),
ConsumerRSA: c.String("stash-consumer-rsa"), ConsumerRSA: c.String("stash-consumer-rsa"),
SkipVerify: c.Bool("stash-skip-verify"), ConsumerRSAString: c.String("stash-consumer-rsa-string"),
SkipVerify: c.Bool("stash-skip-verify"),
}) })
} }