diff --git a/main.go b/main.go index 2257c6f..681d429 100644 --- a/main.go +++ b/main.go @@ -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"), }, } diff --git a/plugin.go b/plugin.go index a16e185..1db6a74 100644 --- a/plugin.go +++ b/plugin.go @@ -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")