예제 #1
0
// Creds returns the credentials needed to connect to Triton
func (c *Config) Creds() (*auth.Credentials, error) {
	if c.creds != nil {
		return c.creds, nil
	}

	keyData, err := ioutil.ReadFile(c.Key)
	if err != nil {
		return nil, err
	}

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

	// TODO: this is missing MantaKeyId (string) and MantaEndpoint (string). These
	// will need to be added when Manta support is added to the provider.
	c.creds = &auth.Credentials{
		UserAuthentication: userauth,
		SdcKeyId:           c.KeyID,
		SdcEndpoint:        auth.Endpoint{URL: c.URL},
	}

	return c.creds, nil
}
예제 #2
0
// NewServer returns a Server
func NewServer() (*Server, error) {
	s := new(Server)

	s.Server = httptest.NewServer(nil)
	s.oldHandler = s.Server.Config.Handler
	s.Mux = httprouter.New()
	s.Server.Config.Handler = s.Mux

	key, err := ioutil.ReadFile(TestKeyFile)
	if err != nil {
		return nil, err
	}

	authentication, err := auth.NewAuth(TestAccount, string(key), "rsa-sha256")

	s.Creds = &auth.Credentials{
		UserAuthentication: authentication,
		SdcKeyId:           TestKeyID,
		SdcEndpoint:        auth.Endpoint{URL: s.Server.URL},
	}

	s.API = local.New(s.Server.URL, TestAccount)
	s.API.SetupHTTP(s.Mux)

	return s, nil
}
예제 #3
0
func (s *LoopingHTTPSuite) SetUpSuite(c *gc.C) {
	s.HTTPSuite.SetUpSuite(c)
	authCreds, err := auth.NewAuth("test_user", key, "rsa-sha256")
	c.Assert(err, gc.IsNil)
	s.creds = &auth.Credentials{
		UserAuthentication: authCreds,
		SdcKeyId:           "test_key",
		SdcEndpoint:        auth.Endpoint{URL: "http://gotest.api.joyentcloud.com"},
	}
}
예제 #4
0
func credentials(cfg *environConfig) (*auth.Credentials, error) {
	authentication, err := auth.NewAuth(cfg.sdcUser(), cfg.privateKey(), cfg.algorithm())
	if err != nil {
		return nil, errors.Errorf("cannot create credentials: %v", err)
	}
	return &auth.Credentials{
		UserAuthentication: authentication,
		SdcKeyId:           cfg.sdcKeyId(),
		SdcEndpoint:        auth.Endpoint{URL: cfg.sdcUrl()},
	}, nil
}
예제 #5
0
파일: auth_test.go 프로젝트: joyent/gosign
func (s *AuthSuite) TestCreateMantaAuthorizationHeader(c *gc.C) {
	headers := make(http.Header)
	headers["Date"] = []string{"Mon, 14 Oct 2013 18:49:29 GMT"}
	authentication, err := auth.NewAuth("test_user", key, "rsa-sha256")
	c.Assert(err, gc.IsNil)
	credentials := &auth.Credentials{
		UserAuthentication: authentication,
		MantaKeyId:         "test_key",
		MantaEndpoint:      auth.Endpoint{URL: "http://gotest.manta.joyent.com"},
	}
	authHeader, err := auth.CreateAuthorizationHeader(headers, credentials, true)
	c.Assert(err, gc.IsNil)
	c.Assert(authHeader, gc.Equals, "Signature keyId=\"/test_user/keys/"+testJpcKeyName+"\",algorithm=\"rsa-sha256\",signature=\""+MantaSignature+"\"")
}
예제 #6
0
func SignHeader(url string, header http.Header, org, user, key string) string {
	// TODO: algorithm should be dynamic
	authentication, err := auth.NewAuth(org, key, "rsa-sha256")
	check(err, "Error while creating a new auth:")

	credentials := &auth.Credentials{
		UserAuthentication: authentication,
		SdcKeyId:           user,
		SdcEndpoint:        auth.Endpoint{URL: url},
	}
	auth_header, err := auth.CreateAuthorizationHeader(header, credentials, false)
	check(err, "Error while CreateAuthorizationHeader:")

	return auth_header
}
예제 #7
0
파일: local_test.go 프로젝트: joyent/gosdc
func (s *LocalTests) SetUpSuite(c *gc.C) {
	// Set up the HTTP server.
	s.Server = httptest.NewServer(nil)
	s.oldHandler = s.Server.Config.Handler
	s.Mux = httprouter.New()
	s.Server.Config.Handler = s.Mux

	// Set up a Joyent CloudAPI service.
	authentication, err := auth.NewAuth("localtest", string(privateKey), "rsa-sha256")
	c.Assert(err, gc.IsNil)

	s.creds = &auth.Credentials{
		UserAuthentication: authentication,
		SdcKeyId:           "",
		SdcEndpoint:        auth.Endpoint{URL: s.Server.URL},
	}
	s.cloudapi = lc.New(s.creds.SdcEndpoint.URL, s.creds.UserAuthentication.User)
	s.cloudapi.SetupHTTP(s.Mux)
}
예제 #8
0
func getCredentialsFromEnvironment() (cred *joyentauth.Credentials, err error) {

	user := os.Getenv("MANTA_USER")
	keyId := os.Getenv("MANTA_KEY_ID")
	url := os.Getenv("MANTA_URL")
	keyMaterial := os.Getenv("MANTA_KEY_MATERIAL")

	if _, err := os.Stat(keyMaterial); err == nil {
		// key material is a file path; try to read it
		keyBytes, err := ioutil.ReadFile(keyMaterial)
		if err != nil {
			return nil, fmt.Errorf("Error reading key material from %s: %s",
				keyMaterial, err)
		} else {
			block, _ := pem.Decode(keyBytes)
			if block == nil {
				return nil, fmt.Errorf(
					"Failed to read key material '%s': no key found", keyMaterial)
			}

			if block.Headers["Proc-Type"] == "4,ENCRYPTED" {
				return nil, fmt.Errorf(
					"Failed to read key '%s': password protected keys are\n"+
						"not currently supported. Please decrypt the key prior to use.", keyMaterial)
			}

			keyMaterial = string(keyBytes)
		}
	}

	authentication, err := joyentauth.NewAuth(user, keyMaterial, "rsa-sha256")
	if err != nil {
		return nil, fmt.Errorf("Error constructing authentication for %s: %s", user, err)
	}

	return &joyentauth.Credentials{
		UserAuthentication: authentication,
		SdcKeyId:           "",
		SdcEndpoint:        joyentauth.Endpoint{},
		MantaKeyId:         keyId,
		MantaEndpoint:      joyentauth.Endpoint{URL: url},
	}, nil
}
예제 #9
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
}
예제 #10
0
파일: auth_test.go 프로젝트: joyent/gosign
// GH-8
func (s *AuthSuite) TestAuthorizationRegion(c *gc.C) {
	authentication, err := auth.NewAuth("test_user", key, "rsa-sha256")
	c.Assert(err, gc.IsNil)
	credentials := &auth.Credentials{
		UserAuthentication: authentication,
		SdcKeyId:           "test_key",
		SdcEndpoint:        auth.Endpoint{URL: "http://gotest.api.joyentcloud.com/"},
	}
	c.Assert(credentials.Region(), gc.Equals, "gotest")

	credentials.SdcEndpoint.URL = "http://gotest"
	c.Assert(credentials.Region(), gc.Equals, "gotest")

	credentials.SdcEndpoint.URL = "http://localhost/"
	c.Assert(credentials.Region(), gc.Equals, "some-region")

	credentials.SdcEndpoint.URL = "http://127.0.0.1"
	c.Assert(credentials.Region(), gc.Equals, "some-region")

	credentials.SdcEndpoint.URL = "bogus"
	c.Assert(credentials.Region(), gc.Equals, "")
}
예제 #11
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
}
예제 #12
0
파일: jpc.go 프로젝트: joyent/gocommon
// credentialsFromEnv creates and initializes the credentials from the
// environment variables.
func credentialsFromEnv(key string) (*auth.Credentials, error) {
	var keyName string
	if key == "" {
		keyName = getUserHome() + "/.ssh/id_rsa"
	} else {
		keyName = key
	}
	privateKey, err := ioutil.ReadFile(keyName)
	if err != nil {
		return nil, err
	}
	authentication, err := auth.NewAuth(getConfig(TritonAccount, SdcAccount, MantaUser), string(privateKey), "rsa-sha256")
	if err != nil {
		return nil, err
	}

	return &auth.Credentials{
		UserAuthentication: authentication,
		SdcKeyId:           getConfig(TritonKeyId, SdcKeyId),
		SdcEndpoint:        auth.Endpoint{URL: getConfig(TritonUrl, SdcUrl)},
		MantaKeyId:         getConfig(MantaKeyId),
		MantaEndpoint:      auth.Endpoint{URL: getConfig(MantaUrl)},
	}, nil
}
예제 #13
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
}