github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/apiserver/restrict_upgrades.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package apiserver
     5  
     6  import (
     7  	"github.com/juju/collections/set"
     8  
     9  	"github.com/juju/juju/rpc/params"
    10  )
    11  
    12  func upgradeMethodsOnly(facadeName, methodName string) error {
    13  	if !IsMethodAllowedDuringUpgrade(facadeName, methodName) {
    14  		return params.UpgradeInProgressError
    15  	}
    16  	return nil
    17  }
    18  
    19  func IsMethodAllowedDuringUpgrade(facadeName, methodName string) bool {
    20  	methods, ok := allowedMethodsDuringUpgrades[facadeName]
    21  	if !ok {
    22  		return false
    23  	}
    24  	return methods.Contains(methodName)
    25  }
    26  
    27  // allowedMethodsDuringUpgrades stores api calls
    28  // that are not blocked during the upgrade process
    29  // as well as  their respective facade names.
    30  // When needed, at some future point, this solution
    31  // will need to be adjusted to cater for different
    32  // facade versions as well.
    33  var allowedMethodsDuringUpgrades = map[string]set.Strings{
    34  	"Client": set.NewStrings(
    35  		"FullStatus",          // for "juju status"
    36  		"FindTools",           // for "juju upgrade-model", before we can reset upgrade to re-run
    37  		"AbortCurrentUpgrade", // for "juju upgrade-model", so that we can reset upgrade to re-run
    38  
    39  	),
    40  	"SSHClient": set.NewStrings( // allow all SSH client related calls
    41  		"PublicAddress",
    42  		"PrivateAddress",
    43  		"BestAPIVersion",
    44  		"AllAddresses",
    45  		"PublicKeys",
    46  		"Proxy",
    47  		"Leader",
    48  	),
    49  	"Pinger": set.NewStrings(
    50  		"Ping",
    51  	),
    52  }