未验证 提交 f0c329b5 编写于 作者: LinuxSuRen's avatar LinuxSuRen 提交者: GitHub

Add support take url from cmd line options (#291)

* Add support take url from cmd line options

* Add test cases for executePostCmd
上级 f44ffd5f
...@@ -263,6 +263,7 @@ func getCurrentJenkinsAndClient(jClient *client.JenkinsCore) (jenkins *JenkinsSe ...@@ -263,6 +263,7 @@ func getCurrentJenkinsAndClient(jClient *client.JenkinsCore) (jenkins *JenkinsSe
jClient.Token = jenkins.Token jClient.Token = jenkins.Token
jClient.Proxy = jenkins.Proxy jClient.Proxy = jenkins.Proxy
jClient.ProxyAuth = jenkins.ProxyAuth jClient.ProxyAuth = jenkins.ProxyAuth
jClient.InsecureSkipVerify = jenkins.InsecureSkipVerify
} }
return return
} }
......
...@@ -2,6 +2,7 @@ package cmd ...@@ -2,6 +2,7 @@ package cmd
import ( import (
"github.com/jenkins-zh/jenkins-cli/app/i18n" "github.com/jenkins-zh/jenkins-cli/app/i18n"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
...@@ -15,3 +16,13 @@ var computerCmd = &cobra.Command{ ...@@ -15,3 +16,13 @@ var computerCmd = &cobra.Command{
Short: i18n.T("Manage the computers of your Jenkins"), Short: i18n.T("Manage the computers of your Jenkins"),
Long: i18n.T(`Manage the computers of your Jenkins`), Long: i18n.T(`Manage the computers of your Jenkins`),
} }
// GetComputerClient returns the client of computer
func GetComputerClient(option CommonOption) (*client.ComputerClient, *JenkinsServer) {
jClient := &client.ComputerClient{
JenkinsCore: client.JenkinsCore{
RoundTripper: option.RoundTripper,
},
}
return jClient, getCurrentJenkinsAndClient(&(jClient.JenkinsCore))
}
package cmd package cmd
import ( import (
"net/http"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/jenkins-zh/jenkins-cli/app/i18n" "github.com/jenkins-zh/jenkins-cli/app/i18n"
"github.com/spf13/cobra" "github.com/spf13/cobra"
...@@ -12,9 +8,8 @@ import ( ...@@ -12,9 +8,8 @@ import (
// ComputerCreateOption option for config list command // ComputerCreateOption option for config list command
type ComputerCreateOption struct { type ComputerCreateOption struct {
CommonOption
OutputOption OutputOption
RoundTripper http.RoundTripper
} }
var computerCreateOption ComputerCreateOption var computerCreateOption ComputerCreateOption
...@@ -31,15 +26,8 @@ It can only create a JNLP agent.`), ...@@ -31,15 +26,8 @@ It can only create a JNLP agent.`),
Example: `jcli agent create agent-name`, Example: `jcli agent create agent-name`,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) { RunE: func(cmd *cobra.Command, args []string) (err error) {
jClient := &client.ComputerClient{ jClient, _ := GetComputerClient(computerCreateOption.CommonOption)
JenkinsCore: client.JenkinsCore{ return jClient.Create(args[0])
RoundTripper: computerCreateOption.RoundTripper,
},
}
getCurrentJenkinsAndClient(&(jClient.JenkinsCore))
err = jClient.Create(args[0])
return
}, },
Annotations: map[string]string{ Annotations: map[string]string{
since: "v0.0.24", since: "v0.0.24",
......
package cmd package cmd
import ( import (
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/jenkins-zh/jenkins-cli/app/i18n" "github.com/jenkins-zh/jenkins-cli/app/i18n"
"github.com/spf13/cobra" "github.com/spf13/cobra"
...@@ -27,15 +25,8 @@ var computerDeleteCmd = &cobra.Command{ ...@@ -27,15 +25,8 @@ var computerDeleteCmd = &cobra.Command{
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
Example: `jcli agent delete agent-name`, Example: `jcli agent delete agent-name`,
RunE: func(cmd *cobra.Command, args []string) (err error) { RunE: func(cmd *cobra.Command, args []string) (err error) {
jClient := &client.ComputerClient{ jClient, _ := GetComputerClient(computerDeleteOption.CommonOption)
JenkinsCore: client.JenkinsCore{ return jClient.Delete(args[0])
RoundTripper: computerDeleteOption.RoundTripper,
},
}
getCurrentJenkinsAndClient(&(jClient.JenkinsCore))
err = jClient.Delete(args[0])
return
}, },
Annotations: map[string]string{ Annotations: map[string]string{
since: "v0.0.24", since: "v0.0.24",
......
...@@ -45,6 +45,9 @@ var computerLaunchCmd = &cobra.Command{ ...@@ -45,6 +45,9 @@ var computerLaunchCmd = &cobra.Command{
Example: `jcli agent launch agent-name Example: `jcli agent launch agent-name
jcli agent launch agent-name --type jnlp`, jcli agent launch agent-name --type jnlp`,
PreRunE: func(_ *cobra.Command, args []string) (err error) { PreRunE: func(_ *cobra.Command, args []string) (err error) {
computerLaunchOption.ComputerClient, computerLaunchOption.CurrentJenkins =
GetComputerClient(computerLaunchOption.CommonOption)
if computerLaunchOption.Type != "jnlp" { if computerLaunchOption.Type != "jnlp" {
return return
} }
...@@ -64,15 +67,6 @@ jcli agent launch agent-name --type jnlp`, ...@@ -64,15 +67,6 @@ jcli agent launch agent-name --type jnlp`,
}, },
RunE: func(_ *cobra.Command, args []string) (err error) { RunE: func(_ *cobra.Command, args []string) (err error) {
name := args[0] name := args[0]
jClient := &client.ComputerClient{
JenkinsCore: client.JenkinsCore{
RoundTripper: computerLaunchOption.RoundTripper,
},
}
computerLaunchOption.ComputerClient = jClient
computerLaunchOption.CurrentJenkins = getCurrentJenkinsAndClient(&(jClient.JenkinsCore))
switch computerLaunchOption.Type { switch computerLaunchOption.Type {
case "": case "":
err = computerLaunchOption.Launch(name) err = computerLaunchOption.Launch(name)
......
package cmd package cmd
import ( import (
"net/http"
"github.com/jenkins-zh/jenkins-cli/client" "github.com/jenkins-zh/jenkins-cli/client"
"github.com/jenkins-zh/jenkins-cli/app/i18n" "github.com/jenkins-zh/jenkins-cli/app/i18n"
...@@ -13,9 +11,8 @@ import ( ...@@ -13,9 +11,8 @@ import (
// ComputerListOption option for config list command // ComputerListOption option for config list command
type ComputerListOption struct { type ComputerListOption struct {
CommonOption
OutputOption OutputOption
RoundTripper http.RoundTripper
} }
var computerListOption ComputerListOption var computerListOption ComputerListOption
...@@ -30,12 +27,7 @@ var computerListCmd = &cobra.Command{ ...@@ -30,12 +27,7 @@ var computerListCmd = &cobra.Command{
Short: i18n.T("List all Jenkins agents"), Short: i18n.T("List all Jenkins agents"),
Long: i18n.T("List all Jenkins agents"), Long: i18n.T("List all Jenkins agents"),
RunE: func(cmd *cobra.Command, _ []string) (err error) { RunE: func(cmd *cobra.Command, _ []string) (err error) {
jClient := &client.ComputerClient{ jClient, _ := GetComputerClient(computerListOption.CommonOption)
JenkinsCore: client.JenkinsCore{
RoundTripper: computerListOption.RoundTripper,
},
}
getCurrentJenkinsAndClient(&(jClient.JenkinsCore))
var computers client.ComputerList var computers client.ComputerList
if computers, err = jClient.List(); err == nil { if computers, err = jClient.List(); err == nil {
......
package cmd package cmd
import ( import (
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/jenkins-zh/jenkins-cli/app/i18n" "github.com/jenkins-zh/jenkins-cli/app/i18n"
"github.com/spf13/cobra" "github.com/spf13/cobra"
...@@ -25,12 +23,7 @@ var computerLogCmd = &cobra.Command{ ...@@ -25,12 +23,7 @@ var computerLogCmd = &cobra.Command{
Long: i18n.T("Output the log of the agent"), Long: i18n.T("Output the log of the agent"),
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) { RunE: func(cmd *cobra.Command, args []string) (err error) {
jClient := &client.ComputerClient{ jClient, _ := GetComputerClient(computerLogOption.CommonOption)
JenkinsCore: client.JenkinsCore{
RoundTripper: computerLogOption.RoundTripper,
},
}
getCurrentJenkinsAndClient(&(jClient.JenkinsCore))
var log string var log string
if log, err = jClient.GetLog(args[0]); err == nil { if log, err = jClient.GetLog(args[0]); err == nil {
......
...@@ -51,17 +51,18 @@ var configCmd = &cobra.Command{ ...@@ -51,17 +51,18 @@ var configCmd = &cobra.Command{
// JenkinsServer holds the configuration of your Jenkins // JenkinsServer holds the configuration of your Jenkins
type JenkinsServer struct { type JenkinsServer struct {
Name string `yaml:"name"` Name string `yaml:"name"`
URL string `yaml:"url"` URL string `yaml:"url"`
UserName string `yaml:"username"` UserName string `yaml:"username"`
Token string `yaml:"token"` Token string `yaml:"token"`
Proxy string `yaml:"proxy"` Proxy string `yaml:"proxy"`
ProxyAuth string `yaml:"proxyAuth"` ProxyAuth string `yaml:"proxyAuth"`
Description string `yaml:"description"` InsecureSkipVerify bool `yaml:"insecureSkipVerify"`
} Description string `yaml:"description"`
}
// CommndHook is a hook
type CommndHook struct { // CommandHook is a hook
type CommandHook struct {
Path string `yaml:"path"` Path string `yaml:"path"`
Command string `yaml:"cmd"` Command string `yaml:"cmd"`
} }
...@@ -84,8 +85,8 @@ type Config struct { ...@@ -84,8 +85,8 @@ type Config struct {
Current string `yaml:"current"` Current string `yaml:"current"`
Language string `yaml:"language"` Language string `yaml:"language"`
JenkinsServers []JenkinsServer `yaml:"jenkins_servers"` JenkinsServers []JenkinsServer `yaml:"jenkins_servers"`
PreHooks []CommndHook `yaml:"preHooks"` PreHooks []CommandHook `yaml:"preHooks"`
PostHooks []CommndHook `yaml:"postHooks"` PostHooks []CommandHook `yaml:"postHooks"`
PluginSuites []PluginSuite `yaml:"pluginSuites"` PluginSuites []PluginSuite `yaml:"pluginSuites"`
Mirrors []JenkinsMirror `yaml:"mirrors"` Mirrors []JenkinsMirror `yaml:"mirrors"`
} }
......
...@@ -96,10 +96,11 @@ func getSampleConfig() (sampleConfig Config) { ...@@ -96,10 +96,11 @@ func getSampleConfig() (sampleConfig Config) {
Current: "yourServer", Current: "yourServer",
JenkinsServers: []JenkinsServer{ JenkinsServers: []JenkinsServer{
{ {
Name: "yourServer", Name: "yourServer",
URL: "http://localhost:8080/jenkins", URL: "http://localhost:8080/jenkins",
UserName: "admin", UserName: "admin",
Token: "111e3a2f0231198855dceaff96f20540a9", Token: "111e3a2f0231198855dceaff96f20540a9",
InsecureSkipVerify: true,
}, },
}, },
Mirrors: []JenkinsMirror{ Mirrors: []JenkinsMirror{
......
...@@ -45,6 +45,7 @@ jenkins_servers: ...@@ -45,6 +45,7 @@ jenkins_servers:
token: 111e3a2f0231198855dceaff96f20540a9 token: 111e3a2f0231198855dceaff96f20540a9
proxy: "" proxy: ""
proxyAuth: "" proxyAuth: ""
insecureSkipVerify: true
description: "" description: ""
preHooks: [] preHooks: []
postHooks: [] postHooks: []
......
...@@ -30,6 +30,13 @@ type RootOptions struct { ...@@ -30,6 +30,13 @@ type RootOptions struct {
Version bool Version bool
Debug bool Debug bool
URL string
Username string
Token string
InsecureSkipVerify bool
Proxy string
ProxyAuth string
Doctor bool Doctor bool
LoggerLevel string LoggerLevel string
...@@ -71,9 +78,9 @@ More information could found at https://jenkins-zh.cn`, ...@@ -71,9 +78,9 @@ More information could found at https://jenkins-zh.cn`,
} }
} }
// set Header Accept-Language
config = getConfig() config = getConfig()
if config != nil { if config != nil {
// set Header Accept-Language
client.SetLanguage(config.Language) client.SetLanguage(config.Language)
} }
...@@ -81,20 +88,21 @@ More information could found at https://jenkins-zh.cn`, ...@@ -81,20 +88,21 @@ More information could found at https://jenkins-zh.cn`,
return return
}, },
BashCompletionFunction: jcliBashCompletionFunc, BashCompletionFunction: jcliBashCompletionFunc,
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) (err error) {
cmd.Println(i18n.T("Jenkins CLI (jcli) manage your Jenkins")) cmd.Println(i18n.T("Jenkins CLI (jcli) manage your Jenkins"))
if rootOptions.Version { if rootOptions.Version {
cmd.Printf("Version: %s\n", app.GetVersion()) cmd.Printf("Version: %s\n", app.GetVersion())
cmd.Printf("Commit: %s\n", app.GetCommit()) cmd.Printf("Commit: %s\n", app.GetCommit())
} }
if rootOptions.Jenkins != "" { if rootOptions.Jenkins != "" {
current := getCurrentJenkinsFromOptionsOrDie() current := getCurrentJenkinsFromOptions()
if current != nil { if current != nil {
cmd.Println("Current Jenkins is:", current.Name) cmd.Println("Current Jenkins is:", current.Name)
} else { } else {
cmd.Println("Cannot found the configuration") err = fmt.Errorf("cannot found the configuration: %s", rootOptions.Jenkins)
} }
} }
return
}, },
} }
...@@ -137,6 +145,20 @@ func init() { ...@@ -137,6 +145,20 @@ func init() {
i18n.T("Run the diagnose for current command")) i18n.T("Run the diagnose for current command"))
rootCmd.Flags().BoolVarP(&rootOptions.Version, "version", "v", false, rootCmd.Flags().BoolVarP(&rootOptions.Version, "version", "v", false,
i18n.T("Print the version of Jenkins CLI")) i18n.T("Print the version of Jenkins CLI"))
rootCmd.PersistentFlags().StringVarP(&rootOptions.URL, "url", "", "",
i18n.T("The URL of Jenkins"))
rootCmd.PersistentFlags().StringVarP(&rootOptions.Username, "username", "", "",
i18n.T("The username of Jenkins"))
rootCmd.PersistentFlags().StringVarP(&rootOptions.Token, "token", "", "",
i18n.T("The token of Jenkins"))
rootCmd.PersistentFlags().BoolVarP(&rootOptions.InsecureSkipVerify, "insecureSkipVerify", "", true,
i18n.T("If skip insecure skip verify"))
rootCmd.PersistentFlags().StringVarP(&rootOptions.Proxy, "proxy", "", "",
i18n.T("The proxy of connection to Jenkins"))
rootCmd.PersistentFlags().StringVarP(&rootOptions.ProxyAuth, "proxy-auth", "", "",
i18n.T("The auth of proxy of connection to Jenkins"))
rootCmd.SetOut(os.Stdout) rootCmd.SetOut(os.Stdout)
} }
...@@ -157,9 +179,29 @@ func getCurrentJenkinsFromOptions() (jenkinsServer *JenkinsServer) { ...@@ -157,9 +179,29 @@ func getCurrentJenkinsFromOptions() (jenkinsServer *JenkinsServer) {
} else { } else {
jenkinsServer = findJenkinsByName(jenkinsOpt) jenkinsServer = findJenkinsByName(jenkinsOpt)
} }
// take URL from options if it's not empty
if jenkinsServer == nil && rootOptions.URL != "" {
jenkinsServer = &JenkinsServer{}
}
if jenkinsServer != nil {
if rootOptions.URL != "" {
jenkinsServer.URL = rootOptions.URL
}
if rootOptions.Username != "" {
jenkinsServer.UserName = rootOptions.Username
}
if rootOptions.Token != "" {
jenkinsServer.Token = rootOptions.Token
}
}
return return
} }
// Deprecated, please use getCurrentJenkinsFromOptions instead of it
func getCurrentJenkinsFromOptionsOrDie() (jenkinsServer *JenkinsServer) { func getCurrentJenkinsFromOptionsOrDie() (jenkinsServer *JenkinsServer) {
if jenkinsServer = getCurrentJenkinsFromOptions(); jenkinsServer == nil { if jenkinsServer = getCurrentJenkinsFromOptions(); jenkinsServer == nil {
log.Fatal("Cannot found Jenkins by", rootOptions.Jenkins) log.Fatal("Cannot found Jenkins by", rootOptions.Jenkins)
...@@ -204,7 +246,7 @@ func executePreCmd(cmd *cobra.Command, _ []string, writer io.Writer) (err error) ...@@ -204,7 +246,7 @@ func executePreCmd(cmd *cobra.Command, _ []string, writer io.Writer) (err error)
func executePostCmd(cmd *cobra.Command, _ []string, writer io.Writer) (err error) { func executePostCmd(cmd *cobra.Command, _ []string, writer io.Writer) (err error) {
config := getConfig() config := getConfig()
if config == nil { if config == nil {
err = fmt.Errorf("Cannot find config file") err = fmt.Errorf("cannot find config file")
return return
} }
......
...@@ -2,11 +2,12 @@ package cmd ...@@ -2,11 +2,12 @@ package cmd
import ( import (
"bytes" "bytes"
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"io/ioutil"
"os"
) )
var _ = Describe("Root cmd test", func() { var _ = Describe("Root cmd test", func() {
...@@ -98,7 +99,7 @@ var _ = Describe("Root cmd test", func() { ...@@ -98,7 +99,7 @@ var _ = Describe("Root cmd test", func() {
It("basic use case with one preHook, should success", func() { It("basic use case with one preHook, should success", func() {
config = &Config{ config = &Config{
PreHooks: []CommndHook{CommndHook{ PreHooks: []CommandHook{CommandHook{
Path: "test", Path: "test",
Command: successCmd, Command: successCmd,
}}, }},
...@@ -118,13 +119,13 @@ var _ = Describe("Root cmd test", func() { ...@@ -118,13 +119,13 @@ var _ = Describe("Root cmd test", func() {
It("basic use case with many preHooks, should success", func() { It("basic use case with many preHooks, should success", func() {
config = &Config{ config = &Config{
PreHooks: []CommndHook{CommndHook{ PreHooks: []CommandHook{CommandHook{
Path: "test", Path: "test",
Command: successCmd, Command: successCmd,
}, CommndHook{ }, CommandHook{
Path: "test", Path: "test",
Command: "echo 2", Command: "echo 2",
}, CommndHook{ }, CommandHook{
Path: "fake", Path: "fake",
Command: successCmd, Command: successCmd,
}}, }},
...@@ -159,7 +160,7 @@ var _ = Describe("Root cmd test", func() { ...@@ -159,7 +160,7 @@ var _ = Describe("Root cmd test", func() {
It("basic use case with error command, should success", func() { It("basic use case with error command, should success", func() {
config = &Config{ config = &Config{
PreHooks: []CommndHook{CommndHook{ PreHooks: []CommandHook{CommandHook{
Path: "test", Path: "test",
Command: errorCmd, Command: errorCmd,
}}, }},
...@@ -176,6 +177,162 @@ var _ = Describe("Root cmd test", func() { ...@@ -176,6 +177,162 @@ var _ = Describe("Root cmd test", func() {
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
}) })
}) })
Context("execute post cmd", func() {
It("should error", func() {
err := executePostCmd(nil, nil, nil)
Expect(err).To(HaveOccurred())
})
It("basic use case with one postHook, should success", func() {
config = &Config{
PostHooks: []CommandHook{CommandHook{
Path: "test",
Command: successCmd,
}},
}
rootCmd := &cobra.Command{}
subCmd := &cobra.Command{
Use: "test",
}
rootCmd.AddCommand(subCmd)
var buf bytes.Buffer
err := executePostCmd(subCmd, nil, &buf)
Expect(err).To(BeNil())
Expect(buf.String()).To(Equal("1\n"))
})
It("basic use case with many postHooks, should success", func() {
config = &Config{
PostHooks: []CommandHook{CommandHook{
Path: "test",
Command: successCmd,
}, CommandHook{
Path: "test",
Command: "echo 2",
}, CommandHook{
Path: "fake",
Command: successCmd,
}},
}
rootCmd := &cobra.Command{}
subCmd := &cobra.Command{
Use: "test",
}
rootCmd.AddCommand(subCmd)
var buf bytes.Buffer
err := executePostCmd(subCmd, nil, &buf)
Expect(err).To(BeNil())
Expect(buf.String()).To(Equal("1\n2\n"))
})
It("basic use case without postHooks, should success", func() {
config = &Config{}
rootCmd := &cobra.Command{}
subCmd := &cobra.Command{
Use: "test",
}
rootCmd.AddCommand(subCmd)
var buf bytes.Buffer
err := executePostCmd(subCmd, nil, &buf)
Expect(err).To(BeNil())
Expect(buf.String()).To(Equal(""))
})
It("basic use case with error command, should success", func() {
config = &Config{
PostHooks: []CommandHook{CommandHook{
Path: "test",
Command: errorCmd,
}},
}
rootCmd := &cobra.Command{}
subCmd := &cobra.Command{
Use: "test",
}
rootCmd.AddCommand(subCmd)
var buf bytes.Buffer
err := executePostCmd(subCmd, nil, &buf)
Expect(err).To(HaveOccurred())
})
})
Context("basic root command test", func() {
var (
buf *bytes.Buffer
)
BeforeEach(func() {
rootOptions = RootOptions{}
buf = new(bytes.Buffer)
rootCmd.SetOut(buf)
})
It("should contain substring Version:", func() {
rootCmd.SetArgs([]string{"--version"})
_, err := rootCmd.ExecuteC()
Expect(err).NotTo(HaveOccurred())
Expect(buf.String()).To(ContainSubstring("Version:"))
})
It("with a fake jenkins as option", func() {
rootCmd.SetArgs([]string{"--jenkins", "fake"})
_, err := rootCmd.ExecuteC()
Expect(err).To(HaveOccurred())
Expect(buf.String()).To(ContainSubstring("cannot found the configuration:"))
})
It("with an exists jenkins as option", func() {
configFile, err := ioutil.TempFile("/tmp", ".yaml")
Expect(err).NotTo(HaveOccurred())
defer os.Remove(configFile.Name())
data, err := generateSampleConfig()
Expect(err).To(BeNil())
err = ioutil.WriteFile(configFile.Name(), data, 0664)
Expect(err).To(BeNil())
rootCmd.SetArgs([]string{"--jenkins", "yourServer", "--configFile", configFile.Name()})
_, err = rootCmd.ExecuteC()
Expect(err).NotTo(HaveOccurred())
Expect(buf.String()).To(ContainSubstring("Current Jenkins is:"))
})
})
Context("use connection from options", func() {
var (
err error
)
BeforeEach(func() {
rootOptions = RootOptions{}
})
AfterEach(func() {
rootOptions = RootOptions{}
})
It("fake jenkins, but with URL from option", func() {
rootCmd.SetArgs([]string{"--configFile", "fake", "--url", "fake-url",
"--username", "fake-user", "--token", "fake-token"})
_, err = rootCmd.ExecuteC()
Expect(err).NotTo(HaveOccurred())
jenkins := getCurrentJenkinsFromOptions()
Expect(jenkins.URL).To(Equal("fake-url"))
Expect(jenkins.UserName).To(Equal("fake-user"))
Expect(jenkins.Token).To(Equal("fake-token"))
})
})
}) })
// FakeOpt only for test // FakeOpt only for test
......
...@@ -22,14 +22,15 @@ func SetLanguage(lan string) { ...@@ -22,14 +22,15 @@ func SetLanguage(lan string) {
language = lan language = lan
} }
// JenkinsCore core informations of Jenkins // JenkinsCore core information of Jenkins
type JenkinsCore struct { type JenkinsCore struct {
JenkinsCrumb JenkinsCrumb
URL string URL string
UserName string InsecureSkipVerify bool
Token string UserName string
Proxy string Token string
ProxyAuth string Proxy string
ProxyAuth string
Debug bool Debug bool
Output io.Writer Output io.Writer
...@@ -49,7 +50,7 @@ func (j *JenkinsCore) GetClient() (client *http.Client) { ...@@ -49,7 +50,7 @@ func (j *JenkinsCore) GetClient() (client *http.Client) {
roundTripper = j.RoundTripper roundTripper = j.RoundTripper
} else { } else {
tr := &http.Transport{ tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, TLSClientConfig: &tls.Config{InsecureSkipVerify: j.InsecureSkipVerify},
} }
if err := util.SetProxy(j.Proxy, j.ProxyAuth, tr); err != nil { if err := util.SetProxy(j.Proxy, j.ProxyAuth, tr); err != nil {
log.Fatal(err) log.Fatal(err)
......
...@@ -23,9 +23,10 @@ const ( ...@@ -23,9 +23,10 @@ const (
// HTTPDownloader is the downloader for http request // HTTPDownloader is the downloader for http request
type HTTPDownloader struct { type HTTPDownloader struct {
TargetFilePath string TargetFilePath string
URL string URL string
ShowProgress bool ShowProgress bool
InsecureSkipVerify bool
UserName string UserName string
Password string Password string
...@@ -75,7 +76,7 @@ func (h *HTTPDownloader) DownloadFile() error { ...@@ -75,7 +76,7 @@ func (h *HTTPDownloader) DownloadFile() error {
tr = h.RoundTripper tr = h.RoundTripper
} else { } else {
trp := &http.Transport{ trp := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, TLSClientConfig: &tls.Config{InsecureSkipVerify: h.InsecureSkipVerify},
} }
tr = trp tr = trp
if err = SetProxy(h.Proxy, h.ProxyAuth, trp); err != nil { if err = SetProxy(h.Proxy, h.ProxyAuth, trp); err != nil {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册