Пример #1
0
func mantaFactory(conf map[string]string) (Client, error) {
	path, ok := conf["path"]
	if !ok {
		return nil, fmt.Errorf("missing 'path' configuration")
	}

	objectName, ok := conf["objectName"]
	if !ok {
		objectName = DEFAULT_OBJECT_NAME
	}

	creds, err := getCredentialsFromEnvironment()

	if err != nil {
		return nil, fmt.Errorf("Error getting Manta credentials: %s", err.Error())
	}

	client := manta.New(joyentclient.NewClient(
		creds.MantaEndpoint.URL,
		"",
		creds,
		log.New(os.Stderr, "", log.LstdFlags),
	))

	return &MantaClient{
		Client:     client,
		Path:       path,
		ObjectName: objectName,
	}, nil
}
Пример #2
0
func newCompute(cloud environs.CloudSpec) (*joyentCompute, error) {
	creds, err := credentials(cloud)
	if err != nil {
		return nil, err
	}
	client := client.NewClient(cloud.Endpoint, cloudapi.DefaultAPIVersion, creds, newGoLogger())
	return &joyentCompute{cloudapi: cloudapi.New(client)}, nil
}
Пример #3
0
func (s *ClientSuite) TestSignURL(c *gc.C) {
	cl := client.NewClient(s.creds.MantaEndpoint.URL, "", s.creds, nil)
	c.Assert(cl, gc.NotNil)

	path := fmt.Sprintf("/%s/stor", s.creds.UserAuthentication.User)
	singedUrl, err := cl.SignURL(path, time.Now().Add(time.Minute*5))
	c.Assert(err, gc.IsNil)
	c.Assert(singedUrl, gc.Not(gc.Equals), "")
}
Пример #4
0
func (s *ClientSuite) TestSendRequest(c *gc.C) {
	cl := client.NewClient(s.creds.SdcEndpoint.URL, "", s.creds, nil)
	c.Assert(cl, gc.NotNil)

	req := joyenthttp.RequestData{}
	resp := joyenthttp.ResponseData{ExpectedStatus: []int{http.StatusOK}}
	err := cl.SendRequest(client.GET, "", "", &req, &resp)
	c.Assert(err, gc.IsNil)
}
Пример #5
0
func newCompute(cfg *environConfig) (*joyentCompute, error) {
	creds, err := credentials(cfg)
	if err != nil {
		return nil, err
	}
	client := client.NewClient(cfg.sdcUrl(), cloudapi.DefaultAPIVersion, creds, &logger)

	return &joyentCompute{
		ecfg:     cfg,
		cloudapi: cloudapi.New(client)}, nil
}
Пример #6
0
// Cloud returns a configured cloudapi.Client instance
func (c *Config) Cloud() (*cloudapi.Client, error) {
	creds, err := c.Creds()
	if err != nil {
		return nil, err
	}

	return cloudapi.New(client.NewClient(
		c.URL,
		cloudapi.DefaultAPIVersion,
		creds,
		&cloudapi.Logger,
	)), nil
}
Пример #7
0
func newStorage(cfg *environConfig, name string) (storage.Storage, error) {
	creds, err := credentials(cfg)
	if err != nil {
		return nil, err
	}
	client := client.NewClient(cfg.mantaUrl(), "", creds, &logger)

	if name == "" {
		name = cfg.controlDir()
	}

	return &JoyentStorage{
		ecfg:          cfg,
		containerName: name,
		manta:         manta.New(client)}, nil
}
Пример #8
0
func (c SDCConfig) getSDCClient() (*cloudapi.Client, error) {
	userauth, err := auth.NewAuth(c.Account, c.KeyMaterial, "rsa-sha256")
	if err != nil {
		return nil, err
	}

	creds := &auth.Credentials{
		UserAuthentication: userauth,
		SdcKeyId:           c.KeyID,
		SdcEndpoint:        auth.Endpoint{URL: c.URL},
	}

	client := cloudapi.New(client.NewClient(
		c.URL,
		cloudapi.DefaultAPIVersion,
		creds,
		log.New(os.Stderr, "", log.LstdFlags),
	))

	return client, nil
}
Пример #9
0
// CreateTritonClient returns an SDC client configured with the appropriate client credentials
// or an error if creating the client fails.
func (c *AccessConfig) CreateTritonClient() (*cloudapi.Client, error) {
	keyData, err := processKeyMaterial(c.KeyMaterial)
	if err != nil {
		return nil, err
	}

	userauth, err := auth.NewAuth(c.Account, string(keyData), "rsa-sha256")
	if err != nil {
		return nil, err
	}

	creds := &auth.Credentials{
		UserAuthentication: userauth,
		SdcKeyId:           c.KeyID,
		SdcEndpoint:        auth.Endpoint{URL: c.Endpoint},
	}

	return cloudapi.New(client.NewClient(
		c.Endpoint,
		cloudapi.DefaultAPIVersion,
		creds,
		log.New(os.Stdout, "", log.Flags()),
	)), nil
}
Пример #10
0
// CreateSDCClient returns an SDC client configured with the appropriate client credentials
// or an error if creating the client fails.
func (c *AccessConfig) CreateSDCClient() (*cloudapi.Client, error) {
	keyData, err := ioutil.ReadFile(c.KeyPath)
	if err != nil {
		return nil, err
	}

	userauth, err := auth.NewAuth(c.Account, string(keyData), "rsa-sha256")
	if err != nil {
		return nil, err
	}

	creds := &auth.Credentials{
		UserAuthentication: userauth,
		SdcKeyId:           c.KeyID,
		SdcEndpoint:        auth.Endpoint{URL: c.Endpoint},
	}

	return cloudapi.New(client.NewClient(
		c.Endpoint,
		cloudapi.DefaultAPIVersion,
		creds,
		&cloudapi.Logger,
	)), nil
}
Пример #11
0
func (s *LiveTests) SetUpTest(c *gc.C) {
	client := client.NewClient(s.creds.MantaEndpoint.URL, "", s.creds, log.New(os.Stderr, "", log.LstdFlags))
	c.Assert(client, gc.NotNil)
	s.testClient = manta.New(client)
	c.Assert(s.testClient, gc.NotNil)
}
Пример #12
0
func (s *ClientSuite) TestNewClient(c *gc.C) {
	cl := client.NewClient(s.creds.SdcEndpoint.URL, "", s.creds, nil)
	c.Assert(cl, gc.NotNil)
}
Пример #13
0
func (s *LiveTests) SetUpTest(c *gc.C) {
	client := client.NewClient(s.creds.MantaEndpoint.URL, "", s.creds, &manta.Logger)
	c.Assert(client, gc.NotNil)
	s.testClient = manta.New(client)
	c.Assert(s.testClient, gc.NotNil)
}
Пример #14
0
func (s *LocalTests) SetUpTest(c *gc.C) {
	client := client.NewClient(s.creds.SdcEndpoint.URL, cloudapi.DefaultAPIVersion, s.creds, log.New(os.Stderr, "", log.LstdFlags))
	c.Assert(client, gc.NotNil)
	s.testClient = cloudapi.New(client)
	c.Assert(s.testClient, gc.NotNil)
}
Пример #15
0
func (s *LiveTests) SetUpTest(c *gc.C) {
	client := client.NewClient(s.creds.SdcEndpoint.URL, cloudapi.DefaultAPIVersion, s.creds, &cloudapi.Logger)
	c.Assert(client, gc.NotNil)
	s.testClient = cloudapi.New(client)
	c.Assert(s.testClient, gc.NotNil)
}
Пример #16
0
const unauthorisedMessage = `
Please ensure the Manta username and SSH access key you have
specified are correct. You can create or import an SSH key via
the "Account Summary" page in the Joyent console.`

// verifyCredentials issues a cheap, non-modifying request to Joyent to
// verify the configured credentials. If verification fails, a user-friendly
// error will be returned, and the original error will be logged at debug
// level.
var verifyCredentials = func(e *joyentEnviron) error {
	creds, err := credentials(e.Ecfg())
	if err != nil {
		return err
	}
	httpClient := client.NewClient(e.Ecfg().sdcUrl(), cloudapi.DefaultAPIVersion, creds, nil)
	apiClient := cloudapi.New(httpClient)
	_, err = apiClient.CountMachines()
	if err != nil {
		logger.Debugf("joyent request failed: %v", err)
		if joyenterrors.IsInvalidCredentials(err) || joyenterrors.IsNotAuthorized(err) {
			return errors.New("authentication failed.\n" + unauthorisedMessage)
		}
		return err
	}
	return nil
}

func credentials(cfg *environConfig) (*auth.Credentials, error) {
	authentication, err := auth.NewAuth(cfg.mantaUser(), cfg.privateKey(), cfg.algorithm())
	if err != nil {