mirror of https://github.com/helm/helm
Merge pull request #2352 from technosophos/ref/getter
ref(getter): flatten the getter package treepull/2370/head
commit
e66cdcd1f3
@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package defaultgetters
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"k8s.io/helm/pkg/getter"
|
|
||||||
"k8s.io/helm/pkg/getter/http"
|
|
||||||
"k8s.io/helm/pkg/getter/plugin"
|
|
||||||
"k8s.io/helm/pkg/helm/environment"
|
|
||||||
"k8s.io/helm/pkg/helm/helmpath"
|
|
||||||
"k8s.io/helm/pkg/plugin"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get gathers the getter constructors for the downloaders.
|
|
||||||
// Currently the build-in http getter and the discovered
|
|
||||||
// plugins with downloader notations are collected.
|
|
||||||
func Get(settings environment.EnvSettings) []getter.Prop {
|
|
||||||
result := []getter.Prop{
|
|
||||||
{
|
|
||||||
Schemes: getter.Schemes{"http", "https"},
|
|
||||||
Constructor: httpgetter.New,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
pluginDownloaders, _ := collectPlugins(settings)
|
|
||||||
result = append(result, pluginDownloaders...)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func collectPlugins(settings environment.EnvSettings) ([]getter.Prop, error) {
|
|
||||||
plugdirs := os.Getenv(environment.PluginEnvVar)
|
|
||||||
if plugdirs == "" {
|
|
||||||
home := helmpath.Home(os.Getenv(environment.HomeEnvVar))
|
|
||||||
plugdirs = home.Plugins()
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins, err := plugin.FindPlugins(plugdirs)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var result []getter.Prop
|
|
||||||
for _, plugin := range plugins {
|
|
||||||
for _, downloader := range plugin.Metadata.Downloaders {
|
|
||||||
result = append(result, getter.Prop{
|
|
||||||
Schemes: downloader.Protocols,
|
|
||||||
Constructor: plugingetter.ConstructNew(
|
|
||||||
downloader.Command,
|
|
||||||
settings,
|
|
||||||
plugin.Metadata.Name,
|
|
||||||
plugin.Dir,
|
|
||||||
),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*Package getter provides a generalize tool for fetching data by scheme.
|
||||||
|
|
||||||
|
This provides a method by which the plugin system can load arbitrary protocol
|
||||||
|
handlers based upon a URL scheme.
|
||||||
|
*/
|
||||||
|
package getter
|
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 The Kubernetes Authors All rights reserved.
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package getter
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestProvider(t *testing.T) {
|
||||||
|
p := Provider{
|
||||||
|
[]string{"one", "three"},
|
||||||
|
func(h, e, l, m string) (Getter, error) { return nil, nil },
|
||||||
|
}
|
||||||
|
|
||||||
|
if !p.Provides("three") {
|
||||||
|
t.Error("Expected provider to provide three")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProviders(t *testing.T) {
|
||||||
|
ps := Providers{
|
||||||
|
{[]string{"one", "three"}, func(h, e, l, m string) (Getter, error) { return nil, nil }},
|
||||||
|
{[]string{"two", "four"}, func(h, e, l, m string) (Getter, error) { return nil, nil }},
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := ps.ByScheme("one"); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if _, err := ps.ByScheme("four"); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := ps.ByScheme("five"); err == nil {
|
||||||
|
t.Error("Did not expect handler for five")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAll(t *testing.T) {
|
||||||
|
oldhh := os.Getenv("HELM_HOME")
|
||||||
|
defer os.Setenv("HELM_HOME", oldhh)
|
||||||
|
os.Setenv("HELM_HOME", "")
|
||||||
|
|
||||||
|
env := hh(false)
|
||||||
|
|
||||||
|
all := All(env)
|
||||||
|
if len(all) != 3 {
|
||||||
|
t.Errorf("expected 3 providers (default plus two plugins), got %d", len(all))
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := all.ByScheme("test2"); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestByScheme(t *testing.T) {
|
||||||
|
oldhh := os.Getenv("HELM_HOME")
|
||||||
|
defer os.Setenv("HELM_HOME", oldhh)
|
||||||
|
os.Setenv("HELM_HOME", "")
|
||||||
|
|
||||||
|
env := hh(false)
|
||||||
|
if _, err := ByScheme("test", env); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if _, err := ByScheme("https", env); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 The Kubernetes Authors All rights reserved.
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package getter
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHTTPGetter(t *testing.T) {
|
||||||
|
g, err := newHTTPGetter("http://example.com", "", "", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if hg, ok := g.(*httpGetter); !ok {
|
||||||
|
t.Fatal("Expected newHTTPGetter to produce an httpGetter")
|
||||||
|
} else if hg.client != http.DefaultClient {
|
||||||
|
t.Fatal("Expected newHTTPGetter to return a default HTTP client.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test with SSL:
|
||||||
|
cd := "../../testdata"
|
||||||
|
join := filepath.Join
|
||||||
|
ca, pub, priv := join(cd, "ca.pem"), join(cd, "crt.pem"), join(cd, "key.pem")
|
||||||
|
g, err = newHTTPGetter("http://example.com/", pub, priv, ca)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := g.(*httpGetter); !ok {
|
||||||
|
t.Fatal("Expected newHTTPGetter to produce an httpGetter")
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 The Kubernetes Authors All rights reserved.
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package getter
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"k8s.io/helm/pkg/helm/environment"
|
||||||
|
"k8s.io/helm/pkg/helm/helmpath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func hh(debug bool) environment.EnvSettings {
|
||||||
|
apath, err := filepath.Abs("./testdata")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
hp := helmpath.Home(apath)
|
||||||
|
return environment.EnvSettings{
|
||||||
|
Home: hp,
|
||||||
|
PlugDirs: hp.Plugins(),
|
||||||
|
Debug: debug,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCollectPlugins(t *testing.T) {
|
||||||
|
// Reset HELM HOME to testdata.
|
||||||
|
oldhh := os.Getenv("HELM_HOME")
|
||||||
|
defer os.Setenv("HELM_HOME", oldhh)
|
||||||
|
os.Setenv("HELM_HOME", "")
|
||||||
|
|
||||||
|
env := hh(false)
|
||||||
|
p, err := collectPlugins(env)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(p) != 2 {
|
||||||
|
t.Errorf("Expected 2 plugins, got %d: %v", len(p), p)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := p.ByScheme("test2"); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := p.ByScheme("test"); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := p.ByScheme("nosuchthing"); err == nil {
|
||||||
|
t.Fatal("did not expect protocol handler for nosuchthing")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPluginGetter(t *testing.T) {
|
||||||
|
oldhh := os.Getenv("HELM_HOME")
|
||||||
|
defer os.Setenv("HELM_HOME", oldhh)
|
||||||
|
os.Setenv("HELM_HOME", "")
|
||||||
|
|
||||||
|
env := hh(false)
|
||||||
|
pg := newPluginGetter("echo", env, "test", ".")
|
||||||
|
g, err := pg("test://foo/bar", "", "", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := g.Get("test://foo/bar")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expect := "test://foo/bar"
|
||||||
|
got := strings.TrimSpace(data.String())
|
||||||
|
if got != expect {
|
||||||
|
t.Errorf("Expected %q, got %q", expect, got)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo ENVIRONMENT
|
||||||
|
env
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo ARGUMENTS
|
||||||
|
echo $@
|
@ -0,0 +1,15 @@
|
|||||||
|
name: "testgetter"
|
||||||
|
version: "0.1.0"
|
||||||
|
usage: "Fetch a package from a test:// source"
|
||||||
|
description: |-
|
||||||
|
Print the environment that the plugin was given, then exit.
|
||||||
|
|
||||||
|
This registers the test:// protocol.
|
||||||
|
|
||||||
|
command: "$HELM_PLUGIN_DIR/get.sh"
|
||||||
|
ignoreFlags: true
|
||||||
|
downloaders:
|
||||||
|
#- command: "$HELM_PLUGIN_DIR/get.sh"
|
||||||
|
- command: "echo"
|
||||||
|
protocols:
|
||||||
|
- "test"
|
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo ENVIRONMENT
|
||||||
|
env
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo ARGUMENTS
|
||||||
|
echo $@
|
@ -0,0 +1,10 @@
|
|||||||
|
name: "testgetter2"
|
||||||
|
version: "0.1.0"
|
||||||
|
usage: "Fetch a different package from a test2:// source"
|
||||||
|
description: "Handle test2 scheme"
|
||||||
|
command: "$HELM_PLUGIN_DIR/get.sh"
|
||||||
|
ignoreFlags: true
|
||||||
|
downloaders:
|
||||||
|
- command: "echo"
|
||||||
|
protocols:
|
||||||
|
- "test2"
|
@ -0,0 +1 @@
|
|||||||
|
repository/local/index.yaml
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,3 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
entries: {}
|
||||||
|
generated: 2017-04-28T12:34:38.900985501-06:00
|
@ -0,0 +1,15 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
generated: 2017-04-28T12:34:38.551693035-06:00
|
||||||
|
repositories:
|
||||||
|
- caFile: ""
|
||||||
|
cache: repository/cache/stable-index.yaml
|
||||||
|
certFile: ""
|
||||||
|
keyFile: ""
|
||||||
|
name: stable
|
||||||
|
url: https://kubernetes-charts.storage.googleapis.com
|
||||||
|
- caFile: ""
|
||||||
|
cache: repository/cache/local-index.yaml
|
||||||
|
certFile: ""
|
||||||
|
keyFile: ""
|
||||||
|
name: local
|
||||||
|
url: http://127.0.0.1:8879/charts
|
Loading…
Reference in new issue