github.com/umeshredd/helm@v3.0.0-alpha.1+incompatible/pkg/plugin/installer/base.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 "helm.sh/helm/pkg/plugin/installer"
    17  
    18  import (
    19  	"os"
    20  	"path/filepath"
    21  
    22  	"helm.sh/helm/pkg/helmpath"
    23  )
    24  
    25  type base struct {
    26  	// Source is the reference to a plugin
    27  	Source string
    28  	// HelmHome is the $HELM_HOME directory
    29  	HelmHome helmpath.Home
    30  }
    31  
    32  func newBase(source string, home helmpath.Home) base {
    33  	return base{source, home}
    34  }
    35  
    36  // link creates a symlink from the plugin source to $HELM_HOME.
    37  func (b *base) link(from string) error {
    38  	debug("symlinking %s to %s", from, b.Path())
    39  	return os.Symlink(from, b.Path())
    40  }
    41  
    42  // Path is where the plugin will be symlinked to.
    43  func (b *base) Path() string {
    44  	if b.Source == "" {
    45  		return ""
    46  	}
    47  	return filepath.Join(b.HelmHome.Plugins(), filepath.Base(b.Source))
    48  }