Skip to content

client.base BaseQuery/query usage? #77

@epaulson

Description

@epaulson

I know there's some refactoring of the codebase in progress, but what's the recommended pattern for adding a new service, and specifically, what in client.base should be used?

I'd like to use Step Functions with txaws, and I've been poking around at s3.client, ec2.client, and client.base and they all seem to handle communicating with AWS and generating requests/signatures differently.

I've been able to mostly get a sample request working with just client.base.query and the object that it returns - here's a good chunk of my sample code:

from twisted.web.client import FileBodyProducer
from txaws.client.base import BaseClient, BaseQuery, error_wrapper, RequestDetails, query, url_context
import hashlib
from hashlib import sha256

from txaws import _auth_v4
import txaws.credentials as txcreds


# parts removed
reqbody = "{}"
content_sha256 = sha256(reqbody).hexdigest().decode("ascii")
body_producer = FileBodyProducer(BytesIO(reqbody))
amz_headers = {"Target": "AWSStepFunctions.ListStateMachines"}
headers = Headers({"Content-Type": ["application/x-amz-json-1.0"]})
creds = txcreds.AWSCredentials(mykeyid, mysecret)
urlreq = url_context(scheme=u"https", host=u"states.us-east-1.amazonaws.com",port=None, path=[u""],query=[])
details = RequestDetails(region=b"us-east-1", service=b"states", method=b"POST",url_context = urlreq, amz_headers=amz_headers, headers=headers, body_producer=body_producer, content_sha256=content_sha256)
q = query(credentials=creds, details=details)
d = q.submit()
d.ddCallback(cbRequest)

It doesn't quite work - in _Query in client/base.py, there's a call to _auth_v4._CanonicalRequest.from_request_components() with a hardcoded set of a headers_to_sign - unfortunately for me, I need to add x-amz-target to that list, and I think content-type, but that's not a settable option.

Looking at other services, should I completely build my own query factory and not try to reuse anything, or would it be OK to maybe add a parameter to RequestDetails so I can pass in a list of headers to include in the signed headers list, and build a lightweight wrapper around the base query object? Is there a reason that the base query is intentionally not subclassable and instead hidden behind query()?

Thanks for your advice!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions