mirror of
https://github.com/drone-plugins/drone-npm.git
synced 2026-06-04 18:23:52 +08:00
Adding skip_verify flag
This commit is contained in:
@@ -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"),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user