github.com/sgoings/helm@v2.0.0-alpha.2.0.20170406211108-734e92851ac3+incompatible/pkg/plugin/installer/installer.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors All rights reserved. 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 */ 15 16 package installer 17 18 import ( 19 "errors" 20 "fmt" 21 "os" 22 "path/filepath" 23 24 "k8s.io/helm/pkg/helm/helmpath" 25 ) 26 27 // ErrMissingMetadata indicates that plugin.yaml is missing. 28 var ErrMissingMetadata = errors.New("plugin metadata (plugin.yaml) missing") 29 30 // Debug enables verbose output. 31 var Debug bool 32 33 // Installer provides an interface for installing helm client plugins. 34 type Installer interface { 35 // Install adds a plugin to $HELM_HOME. 36 Install() error 37 // Path is the directory of the installed plugin. 38 Path() string 39 } 40 41 // Install installs a plugin to $HELM_HOME. 42 func Install(i Installer) error { 43 return i.Install() 44 } 45 46 // NewForSource determines the correct Installer for the given source. 47 func NewForSource(source, version string, home helmpath.Home) (Installer, error) { 48 // Check if source is a local directory 49 if isLocalReference(source) { 50 return NewLocalInstaller(source, home) 51 } 52 return NewVCSInstaller(source, version, home) 53 } 54 55 // isLocalReference checks if the source exists on the filesystem. 56 func isLocalReference(source string) bool { 57 _, err := os.Stat(source) 58 return err == nil 59 } 60 61 // isPlugin checks if the directory contains a plugin.yaml file. 62 func isPlugin(dirname string) bool { 63 _, err := os.Stat(filepath.Join(dirname, "plugin.yaml")) 64 return err == nil 65 } 66 67 func debug(format string, args ...interface{}) { 68 if Debug { 69 format = fmt.Sprintf("[debug] %s\n", format) 70 fmt.Printf(format, args...) 71 } 72 }