當前位置: 首頁>>代碼示例>>Golang>>正文


Golang jujuclient.NewFileClientStore函數代碼示例

本文整理匯總了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")
}
開發者ID:kat-co,項目名稱:juju,代碼行數:28,代碼來源:cmd_juju_login_test.go

示例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")
}
開發者ID:makyo,項目名稱:juju,代碼行數:25,代碼來源:cmd_juju_login_test.go

示例3: NewRegisterCommand

// NewRegisterCommand returns a command to allow the user to register a controller.
func NewRegisterCommand() cmd.Command {
	c := &registerCommand{}
	c.apiOpen = c.APIOpen
	c.listModelsFunc = c.listModels
	c.store = jujuclient.NewFileClientStore()
	return modelcmd.WrapBase(c)
}
開發者ID:bac,項目名稱:juju,代碼行數:8,代碼來源:register.go

示例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)
}
開發者ID:AlexisBruemmer,項目名稱:juju,代碼行數:26,代碼來源:controller.go

示例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()
}
開發者ID:bac,項目名稱:juju,代碼行數:34,代碼來源:conn.go

示例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)
}
開發者ID:bac,項目名稱:juju,代碼行數:29,代碼來源:controller.go

示例7: newSwitchCommand

func newSwitchCommand() cmd.Command {
	cmd := &switchCommand{
		Store: jujuclient.NewFileClientStore(),
	}
	cmd.RefreshModels = cmd.JujuCommandBase.RefreshModels
	return modelcmd.WrapBase(cmd)
}
開發者ID:bac,項目名稱:juju,代碼行數:7,代碼來源:switch.go

示例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)
}
開發者ID:bac,項目名稱:juju,代碼行數:27,代碼來源:modelcommand.go

示例9: NewRegisterCommand

// NewRegisterCommand returns a command to allow the user to register a controller.
func NewRegisterCommand() cmd.Command {
	cmd := &registerCommand{}
	cmd.apiOpen = cmd.APIOpen
	cmd.refreshModels = cmd.RefreshModels
	cmd.store = jujuclient.NewFileClientStore()
	return modelcmd.WrapBase(cmd)
}
開發者ID:makyo,項目名稱:juju,代碼行數:8,代碼來源:register.go

示例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)
}
開發者ID:AlexisBruemmer,項目名稱:juju,代碼行數:9,代碼來源:controllersfile_test.go

示例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)
}
開發者ID:kat-co,項目名稱:juju,代碼行數:11,代碼來源:controller.go

示例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",
	}
}
開發者ID:bac,項目名稱:juju,代碼行數:13,代碼來源:controllers_test.go

示例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
}
開發者ID:bac,項目名稱:juju,代碼行數:15,代碼來源:models_test.go

示例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
}
開發者ID:bac,項目名稱:juju,代碼行數:15,代碼來源:accounts_test.go

示例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)
}
開發者ID:makyo,項目名稱:juju,代碼行數:19,代碼來源:plugin_test.go


注:本文中的github.com/juju/juju/jujuclient.NewFileClientStore函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。