コード例 #1
0
ファイル: service.go プロジェクト: rem7/remap
// newRequest creates a new request for a DataPipeline operation and runs any
// custom request initialization.
func (c *DataPipeline) newRequest(op *service.Operation, params, data interface{}) *service.Request {
	req := service.NewRequest(c.Service, op, params, data)

	// Run custom request initialization if present
	if initRequest != nil {
		initRequest(req)
	}

	return req
}
コード例 #2
0
ファイル: api.go プロジェクト: davidwadden/lattice-release
// GetMetadata uses the path provided to request
func (c *Client) GetMetadata(p string) (string, error) {
	op := &service.Operation{
		Name:       "GetMetadata",
		HTTPMethod: "GET",
		HTTPPath:   path.Join("/", "meta-data", p),
	}

	output := &metadataOutput{}
	req := service.NewRequest(c.Service, op, nil, output)

	return output.Content, req.Send()
}
コード例 #3
0
func TestEndpoint(t *testing.T) {
	c := ec2metadata.New(&ec2metadata.Config{})
	op := &service.Operation{
		Name:       "GetMetadata",
		HTTPMethod: "GET",
		HTTPPath:   path.Join("/", "meta-data", "testpath"),
	}

	req := service.NewRequest(c.Service, op, nil, nil)
	assert.Equal(t, "http://169.254.169.254/latest", req.Endpoint)
	assert.Equal(t, "http://169.254.169.254/latest/meta-data/testpath", req.HTTPRequest.URL.String())
}
コード例 #4
0
func BenchmarkRESTBuild_Complex_elastictranscoderCreateJobInput(b *testing.B) {
	svc := service.NewService(nil)
	svc.ServiceName = "elastictranscoder"
	svc.APIVersion = "2012-09-25"

	for i := 0; i < b.N; i++ {
		r := service.NewRequest(svc, &service.Operation{Name: "CreateJobInput"}, restjsonBuildParms, nil)
		rest.Build(r)
		if r.Error != nil {
			b.Fatal("Unexpected error", r.Error)
		}
	}
}
コード例 #5
0
func BenchmarkJSONUtilBuild_Simple_dynamodbPutItem(b *testing.B) {
	svc := service.NewService(nil)

	params := getDynamodbPutItemParams(b)

	for i := 0; i < b.N; i++ {
		r := service.NewRequest(svc, &service.Operation{Name: "Operation"}, params, nil)
		_, err := jsonutil.BuildJSON(r.Params)
		if err != nil {
			b.Fatal("Unexpected error", err)
		}
	}
}
コード例 #6
0
func BenchmarkJSONRPCBuild_Simple_dynamodbPutItem(b *testing.B) {
	svc := service.NewService(nil)

	params := getDynamodbPutItemParams(b)

	for i := 0; i < b.N; i++ {
		r := service.NewRequest(svc, &service.Operation{Name: "Operation"}, params, nil)
		jsonrpc.Build(r)
		if r.Error != nil {
			b.Fatal("Unexpected error", r.Error)
		}
	}
}
コード例 #7
0
func benchRESTXMLBuild(b *testing.B, op *service.Operation, params interface{}) {
	svc := service.NewService(nil)
	svc.ServiceName = "cloudfront"
	svc.APIVersion = "2015-04-17"

	for i := 0; i < b.N; i++ {
		r := service.NewRequest(svc, op, params, nil)
		restxml.Build(r)
		if r.Error != nil {
			b.Fatal("Unexpected error", r.Error)
		}
	}
}
コード例 #8
0
func benchEC2QueryBuild(b *testing.B, opName string, params interface{}) {
	svc := service.NewService(nil)
	svc.ServiceName = "ec2"
	svc.APIVersion = "2015-04-15"

	for i := 0; i < b.N; i++ {
		r := service.NewRequest(svc, &service.Operation{
			Name:       opName,
			HTTPMethod: "POST",
			HTTPPath:   "/",
		}, params, nil)
		ec2query.Build(r)
		if r.Error != nil {
			b.Fatal("Unexpected error", r.Error)
		}
	}
}
コード例 #9
0
func BenchmarkRESTBuild_Simple_elastictranscoderListJobsByPipeline(b *testing.B) {
	svc := service.NewService(nil)
	svc.ServiceName = "elastictranscoder"
	svc.APIVersion = "2012-09-25"

	params := &elastictranscoder.ListJobsByPipelineInput{
		PipelineId: aws.String("Id"), // Required
		Ascending:  aws.String("Ascending"),
		PageToken:  aws.String("Id"),
	}

	for i := 0; i < b.N; i++ {
		r := service.NewRequest(svc, &service.Operation{Name: "ListJobsByPipeline"}, params, nil)
		rest.Build(r)
		if r.Error != nil {
			b.Fatal("Unexpected error", r.Error)
		}
	}
}
コード例 #10
0
func TestResignRequestExpiredCreds(t *testing.T) {
	creds := credentials.NewStaticCredentials("AKID", "SECRET", "SESSION")
	r := service.NewRequest(
		service.NewService(&aws.Config{Credentials: creds}),
		&service.Operation{
			Name:       "BatchGetItem",
			HTTPMethod: "POST",
			HTTPPath:   "/",
		},
		nil,
		nil,
	)
	Sign(r)
	querySig := r.HTTPRequest.Header.Get("Authorization")

	creds.Expire()

	Sign(r)
	assert.NotEqual(t, querySig, r.HTTPRequest.Header.Get("Authorization"))
}
コード例 #11
0
func TestIgnoreResignRequestWithValidCreds(t *testing.T) {
	r := service.NewRequest(
		service.NewService(&aws.Config{
			Credentials: credentials.NewStaticCredentials("AKID", "SECRET", "SESSION"),
			Region:      aws.String("us-west-2"),
		}),
		&service.Operation{
			Name:       "BatchGetItem",
			HTTPMethod: "POST",
			HTTPPath:   "/",
		},
		nil,
		nil,
	)

	Sign(r)
	sig := r.HTTPRequest.Header.Get("Authorization")

	Sign(r)
	assert.Equal(t, sig, r.HTTPRequest.Header.Get("Authorization"))
}
コード例 #12
0
func TestAnonymousCredentials(t *testing.T) {
	r := service.NewRequest(
		service.NewService(&aws.Config{Credentials: credentials.AnonymousCredentials}),
		&service.Operation{
			Name:       "BatchGetItem",
			HTTPMethod: "POST",
			HTTPPath:   "/",
		},
		nil,
		nil,
	)
	Sign(r)

	urlQ := r.HTTPRequest.URL.Query()
	assert.Empty(t, urlQ.Get("X-Amz-Signature"))
	assert.Empty(t, urlQ.Get("X-Amz-Credential"))
	assert.Empty(t, urlQ.Get("X-Amz-SignedHeaders"))
	assert.Empty(t, urlQ.Get("X-Amz-Date"))

	hQ := r.HTTPRequest.Header
	assert.Empty(t, hQ.Get("Authorization"))
	assert.Empty(t, hQ.Get("X-Amz-Date"))
}
コード例 #13
0
func TestPreResignRequestExpiredCreds(t *testing.T) {
	provider := &credentials.StaticProvider{credentials.Value{"AKID", "SECRET", "SESSION"}}
	creds := credentials.NewCredentials(provider)
	r := service.NewRequest(
		service.NewService(&aws.Config{Credentials: creds}),
		&service.Operation{
			Name:       "BatchGetItem",
			HTTPMethod: "POST",
			HTTPPath:   "/",
		},
		nil,
		nil,
	)
	r.ExpireTime = time.Minute * 10

	Sign(r)
	querySig := r.HTTPRequest.URL.Query().Get("X-Amz-Signature")

	creds.Expire()
	r.Time = time.Now().Add(time.Hour * 48)

	Sign(r)
	assert.NotEqual(t, querySig, r.HTTPRequest.URL.Query().Get("X-Amz-Signature"))
}
コード例 #14
0
ファイル: build_test.go プロジェクト: kgutwin/vault
// newRequest creates a new request for a InputService1ProtocolTest operation and runs any
// custom request initialization.
func (c *InputService1ProtocolTest) newRequest(op *service.Operation, params, data interface{}) *service.Request {
	req := service.NewRequest(c.Service, op, params, data)

	return req
}