Adding skip_verify flag

This commit is contained in:
eolmstead
2016-05-25 14:04:32 -07:00
parent 9f38aecb53
commit 855c36c395
2 changed files with 35 additions and 0 deletions
+6
View File
@@ -48,6 +48,11 @@ func main() {
Usage: "always authorize",
EnvVar: "PLUGIN_ALWAYS_AUTH,NPM_ALWAYS_AUTH",
},
cli.BoolFlag{
Name: "skip_verify",
Usage: "skip SSL verification",
EnvVar: "PLUGIN_SKIP_VERIFY",
},
}
app.Run(os.Args)
@@ -62,6 +67,7 @@ func run(c *cli.Context) error {
Registry: c.String("registry"),
Folder: c.String("folder"),
AlwaysAuth: c.Bool("always_auth"),
SkipVerify: c.Bool("skip_verify"),
},
}
+29
View File
@@ -1,6 +1,7 @@
package main
import (
"crypto/tls"
"encoding/base64"
"encoding/json"
"errors"
@@ -24,6 +25,7 @@ type (
Registry string
Folder string
AlwaysAuth bool
SkipVerify bool
}
NpmPackage struct {
@@ -75,6 +77,9 @@ func (p Plugin) Exec() error {
var cmds []*exec.Cmd
// write the version command
cmds = append(cmds, versionCommand())
// write registry command
if p.Config.Registry != GlobalRegistry {
cmds = append(cmds, registryCommand(p.Config.Registry))
@@ -85,6 +90,11 @@ func (p Plugin) Exec() error {
cmds = append(cmds, alwaysAuthCommand())
}
// write skip verify command
if p.Config.SkipVerify {
cmds = append(cmds, skipVerifyCommand())
}
// write the publish command
cmds = append(cmds, publishCommand())
@@ -158,6 +168,15 @@ func shouldPublishPackage(config Config, npmPackage *NpmPackage) (bool, error) {
req.SetBasicAuth(config.Username, config.Password)
}
// skip verify if necessary
if config.SkipVerify {
http.DefaultTransport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
log.Warning("Skipping SSL verification")
}
// get the response
resp, err := http.DefaultClient.Do(req)
@@ -198,6 +217,11 @@ func writeNpmrcFile(config Config) error {
return ioutil.WriteFile("/root/.npmrc", []byte(contents), 0644)
}
// Gets the npm version
func versionCommand() *exec.Cmd {
return exec.Command("npm", "--version")
}
// Sets the npm registry
func registryCommand(registry string) *exec.Cmd {
return exec.Command("npm", "config", "set", "registry", registry)
@@ -208,6 +232,11 @@ func alwaysAuthCommand() *exec.Cmd {
return exec.Command("npm", "config", "set", "always-auth", "true")
}
// Skip ssl verification
func skipVerifyCommand() *exec.Cmd {
return exec.Command("npm", "config", "set", "ca=\"\"")
}
// Publishes the package
func publishCommand() *exec.Cmd {
return exec.Command("npm", "publish")