github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/apiserver/restrict_migrations.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 migrationClientMethodsOnly(facadeName, methodName string) error {
    13  	if !IsMethodAllowedDuringMigration(facadeName, methodName) {
    14  		return params.MigrationInProgressError
    15  	}
    16  	return nil
    17  }
    18  
    19  func IsMethodAllowedDuringMigration(facadeName, methodName string) bool {
    20  	methods, ok := allowedMethodsDuringMigration[facadeName]
    21  	if !ok {
    22  		return false
    23  	}
    24  	return methods.Contains(methodName)
    25  }
    26  
    27  // allowedMethodsDuringUpgrades stores api calls that are not blocked for user
    28  // logins during the migration of the model from one controller to another.
    29  var allowedMethodsDuringMigration = map[string]set.Strings{
    30  	"Client": set.NewStrings(
    31  		"FullStatus", // for "juju status"
    32  	),
    33  	"Storage": set.NewStrings(
    34  		// for "juju status --storage"
    35  		"ListFilesystems",
    36  		"ListVolumes",
    37  		"ListStorageDetails",
    38  	),
    39  	"SSHClient": set.NewStrings( // allow all SSH client related calls
    40  		"PublicAddress",
    41  		"PrivateAddress",
    42  		"BestAPIVersion",
    43  		"AllAddresses",
    44  		"PublicKeys",
    45  		"Proxy",
    46  	),
    47  	"Pinger": set.NewStrings(
    48  		"Ping",
    49  	),
    50  }