本文整理汇总了Golang中github.com/juju/juju/jujuclient.NewFileClientStore函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFileClientStore函数的具体用法?Golang NewFileClientStore怎么用?Golang NewFileClientStore使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFileClientStore函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestLoginCommand
func (s *cmdLoginSuite) TestLoginCommand(c *gc.C) {
s.createTestUser(c)
// logout "admin" first; we'll need to give it
// a non-random password before we can do so.
s.changeUserPassword(c, "admin", "hunter2")
s.run(c, nil, "logout")
// TODO(axw) 2016-09-08 #1621375
// "juju logout" should clear the cookies for the controller.
os.Remove(filepath.Join(utils.Home(), ".go-cookies"))
context := s.run(c, strings.NewReader("hunter2\nhunter2\n"), "login", "test")
c.Assert(testing.Stdout(context), gc.Equals, "")
c.Assert(testing.Stderr(context), gc.Equals, `
please enter password for [email protected] on kontroll:
You are now logged in to "kontroll" as "[email protected]".
`[1:])
// We should have a macaroon, but no password, in the client store.
store := jujuclient.NewFileClientStore()
accountDetails, err := store.AccountDetails("kontroll")
c.Assert(err, jc.ErrorIsNil)
c.Assert(accountDetails.Password, gc.Equals, "")
// We should be able to login with the macaroon.
s.run(c, nil, "status")
}
示例2: TestLoginCommand
func (s *cmdLoginSuite) TestLoginCommand(c *gc.C) {
s.createTestUser(c)
// logout "admin" first; we'll need to give it
// a non-random password before we can do so.
s.changeUserPassword(c, "admin", "hunter2")
s.run(c, nil, "logout")
context := s.run(c, strings.NewReader("hunter2\nhunter2\n"), "login", "test")
c.Assert(testing.Stdout(context), gc.Equals, "")
c.Assert(testing.Stderr(context), gc.Equals, `
password:
You are now logged in to "kontroll" as "[email protected]".
`[1:])
// We should have a macaroon, but no password, in the client store.
store := jujuclient.NewFileClientStore()
accountDetails, err := store.AccountByName("kontroll", "[email protected]")
c.Assert(err, jc.ErrorIsNil)
c.Assert(accountDetails.Password, gc.Equals, "")
c.Assert(accountDetails.Macaroon, gc.Not(gc.Equals), "")
// We should be able to login with the macaroon.
s.run(c, nil, "status")
}
示例3: NewRegisterCommand
// NewRegisterCommand returns a command to allow the user to register a controller.
func NewRegisterCommand() cmd.Command {
c := ®isterCommand{}
c.apiOpen = c.APIOpen
c.listModelsFunc = c.listModels
c.store = jujuclient.NewFileClientStore()
return modelcmd.WrapBase(c)
}
示例4: Init
// Init implements Command.Init, then calls the wrapped command's Init.
func (w *sysCommandWrapper) Init(args []string) error {
store := w.ClientStore()
if store == nil {
store = jujuclient.NewFileClientStore()
w.SetClientStore(store)
}
if w.setFlags {
if w.controllerName == "" && w.useDefaultControllerName {
name, err := w.getDefaultControllerName()
if err != nil {
return errors.Trace(err)
}
w.controllerName = name
}
if w.controllerName == "" && !w.useDefaultControllerName {
return ErrNoControllerSpecified
}
}
if w.controllerName != "" {
if err := w.SetControllerName(w.controllerName); err != nil {
return errors.Trace(err)
}
}
return w.ControllerCommand.Init(args)
}
示例5: CreateUserHome
// Create a home directory and Juju data home for user username.
// This is used by setUpConn to create the 'ubuntu' user home, after RootDir,
// and may be used again later for other users.
func (s *JujuConnSuite) CreateUserHome(c *gc.C, params *UserHomeParams) {
if s.RootDir == "" {
c.Fatal("JujuConnSuite.setUpConn required first for RootDir")
}
c.Assert(params.Username, gc.Not(gc.Equals), "")
home := filepath.Join(s.RootDir, "home", params.Username)
err := os.MkdirAll(home, 0777)
c.Assert(err, jc.ErrorIsNil)
err = utils.SetHome(home)
c.Assert(err, jc.ErrorIsNil)
jujuHome := filepath.Join(home, ".local", "share")
err = os.MkdirAll(filepath.Join(home, ".local", "share"), 0777)
c.Assert(err, jc.ErrorIsNil)
previousJujuXDGDataHome := osenv.SetJujuXDGDataHome(jujuHome)
if params.SetOldHome {
s.oldJujuXDGDataHome = previousJujuXDGDataHome
}
err = os.MkdirAll(s.DataDir(), 0777)
c.Assert(err, jc.ErrorIsNil)
jujuModelEnvKey := "JUJU_MODEL"
if params.ModelEnvKey != "" {
jujuModelEnvKey = params.ModelEnvKey
}
s.PatchEnvironment(osenv.JujuModelEnvKey, jujuModelEnvKey)
s.ControllerStore = jujuclient.NewFileClientStore()
}
示例6: Init
// Init implements Command.Init, then calls the wrapped command's Init.
func (w *sysCommandWrapper) Init(args []string) error {
store := w.ClientStore()
if store == nil {
store = jujuclient.NewFileClientStore()
}
store = QualifyingClientStore{store}
w.SetClientStore(store)
if w.setControllerFlags {
if w.controllerName == "" && w.useDefaultController {
store := w.ClientStore()
currentController, err := store.CurrentController()
if err != nil {
return translateControllerError(store, err)
}
w.controllerName = currentController
}
if w.controllerName == "" && !w.useDefaultController {
return ErrNoControllersDefined
}
}
if w.controllerName != "" {
if err := w.SetControllerName(w.controllerName); err != nil {
return translateControllerError(w.ClientStore(), err)
}
}
return w.ControllerCommand.Init(args)
}
示例7: newSwitchCommand
func newSwitchCommand() cmd.Command {
cmd := &switchCommand{
Store: jujuclient.NewFileClientStore(),
}
cmd.RefreshModels = cmd.JujuCommandBase.RefreshModels
return modelcmd.WrapBase(cmd)
}
示例8: Init
func (w *modelCommandWrapper) Init(args []string) error {
store := w.ClientStore()
if store == nil {
store = jujuclient.NewFileClientStore()
}
store = QualifyingClientStore{store}
w.SetClientStore(store)
if !w.skipModelFlags {
if w.modelName == "" && w.useDefaultModel {
// Look for the default.
defaultModel, err := GetCurrentModel(store)
if err != nil {
return err
}
w.modelName = defaultModel
}
if w.modelName == "" && !w.useDefaultModel {
return errors.Trace(ErrNoModelSpecified)
}
}
if w.modelName != "" {
if err := w.SetModelName(w.modelName); err != nil {
return translateControllerError(store, err)
}
}
return w.ModelCommand.Init(args)
}
示例9: NewRegisterCommand
// NewRegisterCommand returns a command to allow the user to register a controller.
func NewRegisterCommand() cmd.Command {
cmd := ®isterCommand{}
cmd.apiOpen = cmd.APIOpen
cmd.refreshModels = cmd.RefreshModels
cmd.store = jujuclient.NewFileClientStore()
return modelcmd.WrapBase(cmd)
}
示例10: TestReadEmptyFile
func (s *ControllersFileSuite) TestReadEmptyFile(c *gc.C) {
err := ioutil.WriteFile(osenv.JujuXDGDataHomePath("controllers.yaml"), []byte(""), 0600)
c.Assert(err, jc.ErrorIsNil)
controllerStore := jujuclient.NewFileClientStore()
controllers, err := controllerStore.AllControllers()
c.Assert(err, jc.ErrorIsNil)
c.Assert(controllers, gc.IsNil)
}
示例11: Init
// Init implements Command.Init, then calls the wrapped command's Init.
func (w *sysCommandWrapper) Init(args []string) error {
store := w.ClientStore()
if store == nil {
store = jujuclient.NewFileClientStore()
}
store = QualifyingClientStore{store}
w.SetClientStore(store)
return w.ControllerCommand.Init(args)
}
示例12: SetUpTest
func (s *ControllersSuite) SetUpTest(c *gc.C) {
s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
s.store = jujuclient.NewFileClientStore()
s.controllerName = "test.controller"
s.controller = jujuclient.ControllerDetails{
UnresolvedAPIEndpoints: []string{"test.server.hostname"},
ControllerUUID: "test.uuid",
APIEndpoints: []string{"test.api.endpoint"},
CACert: "test.ca.cert",
Cloud: "aws",
CloudRegion: "southeastasia",
}
}
示例13: TestRemoveControllerRemovesModels
func (s *ModelsSuite) TestRemoveControllerRemovesModels(c *gc.C) {
store := jujuclient.NewFileClientStore()
err := store.AddController("kontroll", jujuclient.ControllerDetails{
ControllerUUID: "abc",
CACert: "woop",
})
c.Assert(err, jc.ErrorIsNil)
err = store.RemoveController("kontroll")
c.Assert(err, jc.ErrorIsNil)
models, err := jujuclient.ReadModelsFile(jujuclient.JujuModelsPath())
c.Assert(err, jc.ErrorIsNil)
_, ok := models["admin/kontroll"]
c.Assert(ok, jc.IsFalse) // kontroll models are removed
}
示例14: TestRemoveControllerRemovesaccounts
func (s *AccountsSuite) TestRemoveControllerRemovesaccounts(c *gc.C) {
store := jujuclient.NewFileClientStore()
err := store.AddController("kontroll", jujuclient.ControllerDetails{
ControllerUUID: "abc",
CACert: "woop",
})
c.Assert(err, jc.ErrorIsNil)
err = store.RemoveController("kontroll")
c.Assert(err, jc.ErrorIsNil)
accounts, err := jujuclient.ReadAccountsFile(jujuclient.JujuAccountsPath())
c.Assert(err, jc.ErrorIsNil)
_, ok := accounts["kontroll"]
c.Assert(ok, jc.IsFalse) // kontroll accounts are removed
}
示例15: TestJujuEnvVars
func (suite *PluginSuite) TestJujuEnvVars(c *gc.C) {
// Plugins are run as model commands, and so require a current
// account and model.
err := modelcmd.WriteCurrentController("myctrl")
c.Assert(err, jc.ErrorIsNil)
store := jujuclient.NewFileClientStore()
err = store.UpdateAccount("myctrl", "[email protected]", jujuclient.AccountDetails{
User: "[email protected]",
Password: "hunter2",
})
c.Assert(err, jc.ErrorIsNil)
err = store.SetCurrentAccount("myctrl", "[email protected]")
c.Assert(err, jc.ErrorIsNil)
suite.makeFullPlugin(PluginParams{Name: "foo"})
output := badrun(c, 0, "foo", "-m", "mymodel", "-p", "pluginarg")
expectedDebug := "foo -m mymodel -p pluginarg\nmodel is: mymodel\n.*home is: .*\\.local/share/juju\n"
c.Assert(output, gc.Matches, expectedDebug)
}