Пример #1
0
func (s *cmdControllerSuite) TestControllerLoginCommand(c *gc.C) {
	user := s.Factory.MakeUser(c, &factory.UserParams{
		NoEnvUser: true,
		Password:  "******",
	})
	apiInfo := s.APIInfo(c)
	serverFile := envcmd.ServerFile{
		Addresses: apiInfo.Addrs,
		CACert:    apiInfo.CACert,
		Username:  user.Name(),
		Password:  "******",
	}
	serverFilePath := filepath.Join(c.MkDir(), "server.yaml")
	content, err := goyaml.Marshal(serverFile)
	c.Assert(err, jc.ErrorIsNil)
	err = ioutil.WriteFile(serverFilePath, []byte(content), 0644)
	c.Assert(err, jc.ErrorIsNil)

	s.run(c, "login", "--server", serverFilePath, "just-a-controller")

	// Make sure that the saved server details are sufficient to connect
	// to the api server.
	api, err := juju.NewAPIFromName("just-a-controller", nil)
	c.Assert(err, jc.ErrorIsNil)
	api.Close()
}
Пример #2
0
func (s *KillSuite) newKillCommand() cmd.Command {
	return system.NewKillCommand(
		s.api,
		s.clientapi,
		s.apierror,
		func(name string) (api.Connection, error) {
			return juju.NewAPIFromName(name, nil)
		})
}
Пример #3
0
// initAPIClient initialises the API connection.
// It is the caller's responsibility to close the connection.
func (c *SSHCommon) initAPIClient() (*api.Client, error) {
	st, err := juju.NewAPIFromName(c.EnvName)
	if err != nil {
		return nil, err
	}
	c.apiClient = st.Client()
	c.apiAddr = st.Addr()
	return c.apiClient, nil
}
Пример #4
0
func (c *EnvCommandBase) NewAPIRoot() (*api.State, error) {
	// This is work in progress as we remove the EnvName from downstream code.
	// We want to be able to specify the environment in a number of ways, one of
	// which is the connection name on the client machine.
	if c.envName == "" {
		return nil, errors.Trace(ErrNoEnvironmentSpecified)
	}
	return juju.NewAPIFromName(c.envName)
}
Пример #5
0
func (s *KillSuite) runKillCommand(c *gc.C, args ...string) (*cmd.Context, error) {
	cmd := system.NewKillCommand(
		s.api,
		s.clientapi,
		s.apierror,
		func(name string) (api.Connection, error) {
			return juju.NewAPIFromName(name, nil)
		})
	return testing.RunCommand(c, cmd, args...)
}
Пример #6
0
func EnvClientFactory() (*Client, error) {
	envName := envcmd.ReadCurrentEnvironment()

	state, err := juju.NewAPIFromName(envName)
	if err != nil {
		log.Warn("Got error building API from name: %v", envName, err)
		return nil, fmt.Errorf(connectionError, envName, err)
	}

	client := state.Client()

	wrapper := &Client{}
	wrapper.client = client
	wrapper.apiState = state
	//defer apiclient.Close()
	return wrapper, err
}
Пример #7
0
func (s *cmdControllerSuite) TestCreateEnvironment(c *gc.C) {
	c.Assert(envcmd.WriteCurrentController("dummyenv"), jc.ErrorIsNil)
	// The JujuConnSuite doesn't set up an ssh key in the fake home dir,
	// so fake one on the command line.  The dummy provider also expects
	// a config value for 'state-server'.
	context := s.run(c, "create-environment", "new-env", "authorized-keys=fake-key", "state-server=false")
	c.Check(testing.Stdout(context), gc.Equals, "")
	c.Check(testing.Stderr(context), gc.Equals, `
created environment "new-env"
dummyenv (controller) -> new-env
`[1:])

	// Make sure that the saved server details are sufficient to connect
	// to the api server.
	api, err := juju.NewAPIFromName("new-env", nil)
	c.Assert(err, jc.ErrorIsNil)
	api.Close()
}
Пример #8
0
Файл: main.go Проект: axw/jns
func (s *jujuNameServer) openAPI(envName string) (api.Connection, error) {
	if envName != "" {
		// Domain names are case-insensitive, but environment
		// names are not. We'll error if there are two names
		// that match case-insensitively.
		store, err := configstore.Default()
		if err != nil {
			return nil, errors.Trace(err)
		}
		envNames, err := store.List()
		if err != nil {
			return nil, errors.Trace(err)
		}
		var matches []string
		for _, storeEnvName := range envNames {
			if strings.ToLower(storeEnvName) == strings.ToLower(envName) {
				matches = append(matches, storeEnvName)
			}
		}
		if len(matches) == 0 {
			return nil, errors.NotFoundf("environment %q", envName)
		}
		if len(matches) > 1 {
			return nil, errors.Errorf(
				"%q matches multiple environments: %q",
				envName, matches,
			)
		}
		envName = matches[0]
	}

	jar, err := cookiejar.New(&cookiejar.Options{
		Filename: cookiejar.DefaultCookieFile(),
	})
	if err != nil {
		return nil, errors.Trace(err)
	}
	client := httpbakery.NewClient()
	client.Jar = jar
	client.VisitWebPage = httpbakery.OpenWebBrowser
	return juju.NewAPIFromName(envName, client)
}
Пример #9
0
// newAPIRoot establishes a connection to the API server for
// the named system or environment.
func (ctx *apiContext) newAPIRoot(name string) (api.Connection, error) {
	if name == "" {
		return nil, errors.Trace(errNoNameSpecified)
	}
	return juju.NewAPIFromName(name, ctx.client)
}
Пример #10
0
// newAPIRoot returns a restricted API for the current system using the current
// credentials.  Only the UserManager and EnvironmentManager may be accessed
// through this API connection.
func (c *SysCommandBase) newAPIRoot() (api.Connection, error) {
	if c.systemName == "" {
		return nil, errors.Trace(ErrNoSystemSpecified)
	}
	return juju.NewAPIFromName(c.systemName)
}