github.com/x-helm/helm@v3.0.0-beta.3+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  }
    29  
    30  func newBase(source string) base {
    31  	return base{source}
    32  }
    33  
    34  // link creates a symlink from the plugin source to the base path.
    35  func (b *base) link(from string) error {
    36  	debug("symlinking %s to %s", from, b.Path())
    37  	return os.Symlink(from, b.Path())
    38  }
    39  
    40  // Path is where the plugin will be symlinked to.
    41  func (b *base) Path() string {
    42  	if b.Source == "" {
    43  		return ""
    44  	}
    45  	return helmpath.DataPath("plugins", filepath.Base(b.Source))
    46  }