-
Notifications
You must be signed in to change notification settings - Fork 17
Description
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!