github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/apiserver/read_only_calls.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package apiserver
     5  
     6  import (
     7  	"github.com/juju/utils/set"
     8  )
     9  
    10  // readOnlyCalls specify a white-list of API calls that do not
    11  // modify the database. The format of the calls is "<facade>.<method>".
    12  // At this stage, we are explicitly ignoring the facade version.
    13  var readOnlyCalls = set.NewStrings(
    14  	"Action.Actions",
    15  	"Action.FindActionTagsByPrefix",
    16  	"Action.ListAll",
    17  	"Action.ListPending",
    18  	"Action.ListRunning",
    19  	"Action.ListCompleted",
    20  	"Action.ServicesCharmActions",
    21  	"Annotations.Get",
    22  	"Block.List",
    23  	"Charms.CharmInfo",
    24  	"Charms.IsMetered",
    25  	"Charms.List",
    26  	"Client.AgentVersion",
    27  	"Client.APIHostPorts",
    28  	"Client.CharmInfo",
    29  	"Client.ModelGet",
    30  	"Client.ModelInfo",
    31  	"Client.ModelUserInfo",
    32  	"Client.FullStatus",
    33  	// FindTools, while being technically read only, isn't a useful
    34  	// command for a read only user to run.
    35  	// While GetBundleChanges is technically read only, it is a precursor
    36  	// to deploying the bundle or changes. But... let's leave it here anyway.
    37  	"Client.GetBundleChanges",
    38  	"Client.GetModelConstraints",
    39  	"Client.PrivateAddress",
    40  	"Client.PublicAddress",
    41  	// ResolveCharms, while being technically read only, isn't a useful
    42  	// command for a read only user to run.
    43  	// Status is so old it shouldn't be used.
    44  	"Client.StatusHistory",
    45  	"Client.WatchAll",
    46  	// TODO: add controller work.
    47  	"KeyManager.ListKeys",
    48  	"ModelManager.ModelInfo",
    49  	"Service.GetConstraints",
    50  	"Service.CharmRelations",
    51  	"Service.Get",
    52  	"Spaces.ListSpaces",
    53  	"Storage.ListStorageDetails",
    54  	"Storage.ListFilesystems",
    55  	"Storage.ListPools",
    56  	"Storage.ListVolumes",
    57  	"Subnets.AllSpaces",
    58  	"Subnets.AllZones",
    59  	"Subnets.ListSubnets",
    60  	"UserManager.UserInfo",
    61  )
    62  
    63  // isCallReadOnly returns whether or not the method on the facade
    64  // is known to not alter the database.
    65  func isCallReadOnly(facade, method string) bool {
    66  	key := facade + "." + method
    67  	// NOTE: maybe useful in the future to be able to specify entire facades
    68  	// as read only, in which case specifying something like "Facade.*" would
    69  	// be useful. Not sure we'll ever need this, but something to think about
    70  	// perhaps.
    71  	return readOnlyCalls.Contains(key)
    72  }