github.com/stefanmcshane/helm@v0.0.0-20221213002717-88a4a2c6e77d/pkg/plugin/installer/local_installer.go (about) 1 /* 2 Copyright The Helm Authors. 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 // import "github.com/stefanmcshane/helm/pkg/plugin/installer" 17 18 import ( 19 "os" 20 "path/filepath" 21 22 "github.com/pkg/errors" 23 ) 24 25 // ErrPluginNotAFolder indicates that the plugin path is not a folder. 26 var ErrPluginNotAFolder = errors.New("expected plugin to be a folder") 27 28 // LocalInstaller installs plugins from the filesystem. 29 type LocalInstaller struct { 30 base 31 } 32 33 // NewLocalInstaller creates a new LocalInstaller. 34 func NewLocalInstaller(source string) (*LocalInstaller, error) { 35 src, err := filepath.Abs(source) 36 if err != nil { 37 return nil, errors.Wrap(err, "unable to get absolute path to plugin") 38 } 39 i := &LocalInstaller{ 40 base: newBase(src), 41 } 42 return i, nil 43 } 44 45 // Install creates a symlink to the plugin directory. 46 // 47 // Implements Installer. 48 func (i *LocalInstaller) Install() error { 49 stat, err := os.Stat(i.Source) 50 if err != nil { 51 return err 52 } 53 if !stat.IsDir() { 54 return ErrPluginNotAFolder 55 } 56 57 if !isPlugin(i.Source) { 58 return ErrMissingMetadata 59 } 60 debug("symlinking %s to %s", i.Source, i.Path()) 61 return os.Symlink(i.Source, i.Path()) 62 } 63 64 // Update updates a local repository 65 func (i *LocalInstaller) Update() error { 66 debug("local repository is auto-updated") 67 return nil 68 }