github.com/iaas-resource-provision/iaas-rpc@v1.0.7-0.20211021023331-ed21f798c408/plugins.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  	"path/filepath"
     7  	"runtime"
     8  
     9  	"github.com/iaas-resource-provision/iaas-rpc/internal/command/cliconfig"
    10  )
    11  
    12  // globalPluginDirs returns directories that should be searched for
    13  // globally-installed plugins (not specific to the current configuration).
    14  //
    15  // Earlier entries in this slice get priority over later when multiple copies
    16  // of the same plugin version are found, but newer versions always override
    17  // older versions where both satisfy the provider version constraints.
    18  func globalPluginDirs() []string {
    19  	var ret []string
    20  	// Look in ~/.iaas-rpc.dir/plugins/ , or its equivalent on non-UNIX
    21  	dir, err := cliconfig.ConfigDir()
    22  	if err != nil {
    23  		log.Printf("[ERROR] Error finding global config directory: %s", err)
    24  	} else {
    25  		machineDir := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH)
    26  		ret = append(ret, filepath.Join(dir, "plugins"))
    27  		ret = append(ret, filepath.Join(dir, "plugins", machineDir))
    28  	}
    29  
    30  	return ret
    31  }