Unverified Commit c7b94fe5 authored by Oren Shomron's avatar Oren Shomron Committed by GitHub
Browse files

Merge pull request #831 from shomron/issue-726-tls-skip-verify

Add --tls-skip-verify global option affecting outgoing HTTP requests
parents 746561a9 de033c2c
......@@ -28,8 +28,9 @@ import (
func TestRegistryDescribe(t *testing.T) {
withApp(t, func(appMock *amocks.App) {
in := map[string]interface{}{
OptionApp: appMock,
OptionName: "incubator",
OptionApp: appMock,
OptionName: "incubator",
OptionTLSSkipVerify: false,
}
a, err := NewRegistryDescribe(in)
......
......@@ -49,12 +49,15 @@ type RegistryList struct {
func NewRegistryList(m map[string]interface{}) (*RegistryList, error) {
ol := newOptionLoader(m)
httpClient := ol.LoadHTTPClient()
rl := &RegistryList{
app: ol.LoadApp(),
outputType: ol.LoadOptionalString(OptionOutput),
registryListFn: registry.List,
out: os.Stdout,
registryListFn: func(ksApp app.App) ([]registry.Registry, error) {
return registry.List(ksApp, httpClient)
},
out: os.Stdout,
}
if ol.err != nil {
......
......@@ -53,8 +53,9 @@ func TestRegistryList(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
withApp(t, func(appMock *amocks.App) {
in := map[string]interface{}{
OptionApp: appMock,
OptionOutput: tc.outputType,
OptionApp: appMock,
OptionOutput: tc.outputType,
OptionTLSSkipVerify: false,
}
a, err := NewRegistryList(in)
......
......@@ -16,6 +16,8 @@
package actions
import (
"net/http"
"github.com/ksonnet/ksonnet/pkg/app"
"github.com/ksonnet/ksonnet/pkg/registry"
"github.com/pkg/errors"
......@@ -52,9 +54,12 @@ type RegistrySet struct {
func NewRegistrySet(m map[string]interface{}) (*RegistrySet, error) {
ol := newOptionLoader(m)
httpClient := ol.LoadHTTPClient()
rs := &RegistrySet{
app: ol.LoadApp(),
locateFn: defaultLocate,
app: ol.LoadApp(),
locateFn: func(ksApp app.App, spec *app.RegistryConfig) (registry.Setter, error) {
return defaultLocate(ksApp, spec, httpClient)
},
}
if ol.err != nil {
......@@ -67,8 +72,8 @@ func NewRegistrySet(m map[string]interface{}) (*RegistrySet, error) {
// defaultLocate passes-through to registry.Locate, but constrains the interface
// to just `registry.Setter`. The concrete type of registry.Setter is determined
// by the `spec` argument. In other words, this is a factory for registry.Setter implementations.
func defaultLocate(ksApp app.App, spec *app.RegistryConfig) (registry.Setter, error) {
return registry.Locate(ksApp, spec)
func defaultLocate(ksApp app.App, spec *app.RegistryConfig, httpClient *http.Client) (registry.Setter, error) {
return registry.Locate(ksApp, spec, httpClient)
}
// registryConfig returns a registry configuration by name from the provided App.
......
......@@ -49,7 +49,8 @@ func newUpgrade(m map[string]interface{}) (*Upgrade, error) {
if ol.err != nil {
return nil, ol.err
}
pm := registry.NewPackageManager(a)
httpClientOpt := registry.HTTPClientOpt(ol.LoadHTTPClient())
pm := registry.NewPackageManager(a, httpClientOpt)
u := &Upgrade{
app: a,
......
......@@ -28,8 +28,9 @@ import (
func TestUpgrade(t *testing.T) {
withApp(t, func(appMock *amocks.App) {
in := map[string]interface{}{
OptionApp: appMock,
OptionDryRun: true,
OptionApp: appMock,
OptionDryRun: true,
OptionTLSSkipVerify: false,
}
var called bool
......
......@@ -48,6 +48,7 @@ const (
flagSkipGc = "skip-gc"
flagTlaVar = "tla-str"
flagTlaVarFile = "tla-str-file"
flagTLSSkipVerify = "tls-skip-verify"
flagOutput = "output"
flagOverride = "override"
flagUnset = "unset"
......
......@@ -21,6 +21,7 @@ import (
"github.com/ksonnet/ksonnet/pkg/actions"
"github.com/ksonnet/ksonnet/pkg/app"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var (
......@@ -54,8 +55,9 @@ func newPkgDescribeCmd(a app.App) *cobra.Command {
}
m := map[string]interface{}{
actions.OptionApp: a,
actions.OptionPackageName: args[0],
actions.OptionApp: a,
actions.OptionPackageName: args[0],
actions.OptionTLSSkipVerify: viper.GetBool(flagTLSSkipVerify),
}
return runAction(actionPkgDescribe, m)
......
......@@ -28,8 +28,9 @@ func Test_pkgDescribeCmd(t *testing.T) {
args: []string{"pkg", "describe", "package-name"},
action: actionPkgDescribe,
expected: map[string]interface{}{
actions.OptionApp: nil,
actions.OptionPackageName: "package-name",
actions.OptionApp: nil,
actions.OptionPackageName: "package-name",
actions.OptionTLSSkipVerify: false,
},
},
{
......
......@@ -79,11 +79,12 @@ func newPkgInstallCmd(a app.App) *cobra.Command {
}
m := map[string]interface{}{
actions.OptionApp: a,
actions.OptionLibName: args[0],
actions.OptionName: viper.GetString(vPkgInstallName),
actions.OptionEnvName: viper.GetString(vPkgInstallEnv),
actions.OptionForce: viper.GetBool(vPkgInstallForce),
actions.OptionApp: a,
actions.OptionLibName: args[0],
actions.OptionName: viper.GetString(vPkgInstallName),
actions.OptionEnvName: viper.GetString(vPkgInstallEnv),
actions.OptionForce: viper.GetBool(vPkgInstallForce),
actions.OptionTLSSkipVerify: viper.GetBool(flagTLSSkipVerify),
}
return runAction(actionPkgInstall, m)
......
......@@ -28,11 +28,12 @@ func Test_pkgInstallCmd(t *testing.T) {
args: []string{"pkg", "install", "package-name"},
action: actionPkgInstall,
expected: map[string]interface{}{
actions.OptionApp: nil,
actions.OptionLibName: "package-name",
actions.OptionName: "",
actions.OptionEnvName: "",
actions.OptionForce: false,
actions.OptionApp: nil,
actions.OptionLibName: "package-name",
actions.OptionName: "",
actions.OptionEnvName: "",
actions.OptionForce: false,
actions.OptionTLSSkipVerify: false,
},
},
{
......@@ -40,11 +41,12 @@ func Test_pkgInstallCmd(t *testing.T) {
args: []string{"pkg", "install", "--env", "production", "package-name"},
action: actionPkgInstall,
expected: map[string]interface{}{
actions.OptionApp: nil,
actions.OptionLibName: "package-name",
actions.OptionName: "",
actions.OptionEnvName: "production",
actions.OptionForce: false,
actions.OptionApp: nil,
actions.OptionLibName: "package-name",
actions.OptionName: "",
actions.OptionEnvName: "production",
actions.OptionForce: false,
actions.OptionTLSSkipVerify: false,
},
},
{
......@@ -52,11 +54,12 @@ func Test_pkgInstallCmd(t *testing.T) {
args: []string{"pkg", "install", "package-name", "--force"},
action: actionPkgInstall,
expected: map[string]interface{}{
actions.OptionApp: nil,
actions.OptionLibName: "package-name",
actions.OptionName: "",
actions.OptionEnvName: "",
actions.OptionForce: true,
actions.OptionApp: nil,
actions.OptionLibName: "package-name",
actions.OptionName: "",
actions.OptionEnvName: "",
actions.OptionForce: true,
actions.OptionTLSSkipVerify: false,
},
},
{
......
......@@ -61,9 +61,10 @@ func newPkgListCmd(a app.App) *cobra.Command {
}
m := map[string]interface{}{
actions.OptionApp: a,
actions.OptionInstalled: viper.GetBool(vPkgListInstalled),
actions.OptionOutput: viper.GetString(vPkgListOutput),
actions.OptionApp: a,
actions.OptionInstalled: viper.GetBool(vPkgListInstalled),
actions.OptionOutput: viper.GetString(vPkgListOutput),
actions.OptionTLSSkipVerify: viper.GetBool(flagTLSSkipVerify),
}
return runAction(actionPkgList, m)
......
......@@ -28,9 +28,10 @@ func Test_pkgListCmd(t *testing.T) {
args: []string{"pkg", "list"},
action: actionPkgList,
expected: map[string]interface{}{
actions.OptionApp: nil,
actions.OptionInstalled: false,
actions.OptionOutput: "",
actions.OptionApp: nil,
actions.OptionInstalled: false,
actions.OptionOutput: "",
actions.OptionTLSSkipVerify: false,
},
},
{
......@@ -38,9 +39,10 @@ func Test_pkgListCmd(t *testing.T) {
args: []string{"pkg", "list", "-o", "json"},
action: actionPkgList,
expected: map[string]interface{}{
actions.OptionApp: nil,
actions.OptionInstalled: false,
actions.OptionOutput: "json",
actions.OptionApp: nil,
actions.OptionInstalled: false,
actions.OptionOutput: "json",
actions.OptionTLSSkipVerify: false,
},
},
{
......
......@@ -21,6 +21,7 @@ import (
"github.com/ksonnet/ksonnet/pkg/actions"
"github.com/ksonnet/ksonnet/pkg/app"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var (
......@@ -57,8 +58,9 @@ func newPrototypeDescribeCmd(a app.App) *cobra.Command {
}
m := map[string]interface{}{
actions.OptionApp: a,
actions.OptionQuery: args[0],
actions.OptionApp: a,
actions.OptionQuery: args[0],
actions.OptionTLSSkipVerify: viper.GetBool(flagTLSSkipVerify),
}
return runAction(actionPrototypeDescribe, m)
......
......@@ -28,8 +28,9 @@ func Test_prototypeDescribeCmd(t *testing.T) {
args: []string{"prototype", "describe", "name"},
action: actionPrototypeDescribe,
expected: map[string]interface{}{
actions.OptionApp: nil,
actions.OptionQuery: "name",
actions.OptionApp: nil,
actions.OptionQuery: "name",
actions.OptionTLSSkipVerify: false,
},
},
{
......
......@@ -60,8 +60,9 @@ func newPrototypeListCmd(a app.App) *cobra.Command {
}
m := map[string]interface{}{
actions.OptionApp: a,
actions.OptionOutput: viper.GetString(vPrototypeListOutput),
actions.OptionApp: a,
actions.OptionOutput: viper.GetString(vPrototypeListOutput),
actions.OptionTLSSkipVerify: viper.GetBool(flagTLSSkipVerify),
}
return runAction(actionPrototypeList, m)
......
......@@ -28,8 +28,9 @@ func Test_prototypeListCmd(t *testing.T) {
args: []string{"prototype", "list"},
action: actionPrototypeList,
expected: map[string]interface{}{
actions.OptionApp: nil,
actions.OptionOutput: "",
actions.OptionApp: nil,
actions.OptionOutput: "",
actions.OptionTLSSkipVerify: false,
},
},
{
......@@ -37,8 +38,9 @@ func Test_prototypeListCmd(t *testing.T) {
args: []string{"prototype", "list", "-o", "json"},
action: actionPrototypeList,
expected: map[string]interface{}{
actions.OptionApp: nil,
actions.OptionOutput: "json",
actions.OptionApp: nil,
actions.OptionOutput: "json",
actions.OptionTLSSkipVerify: false,
},
},
{
......
......@@ -82,6 +82,7 @@ func newPrototypePreviewCmd(a app.App) *cobra.Command {
actions.OptionApp: a,
actions.OptionQuery: rawArgs[0],
actions.OptionArguments: rawArgs[1:],
// We don't pass flagTLSSkipVerify because flag parsing is disabled
}
return runAction(actionPrototypePreview, m)
......
......@@ -28,9 +28,10 @@ func Test_prototypePreviewCmd(t *testing.T) {
args: []string{"prototype", "preview", "name"},
action: actionPrototypePreview,
expected: map[string]interface{}{
actions.OptionApp: nil,
actions.OptionQuery: "name",
actions.OptionArguments: make([]string, 0),
actions.OptionApp: nil,
actions.OptionQuery: "name",
actions.OptionArguments: make([]string, 0),
actions.OptionTLSSkipVerify: false,
},
},
{
......
......@@ -57,9 +57,10 @@ func newPrototypeSearchCmd(a app.App) *cobra.Command {
}
m := map[string]interface{}{
actions.OptionApp: a,
actions.OptionQuery: args[0],
actions.OptionOutput: viper.GetString(vPrototypeSearchOutput),
actions.OptionApp: a,
actions.OptionQuery: args[0],
actions.OptionOutput: viper.GetString(vPrototypeSearchOutput),
actions.OptionTLSSkipVerify: viper.GetBool(flagTLSSkipVerify),
}
return runAction(actionPrototypeSearch, m)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment