Add a new hosting service HTTP request builder function for credentials.

Review Request #10636 — Created July 19, 2019 and submitted — Latest diff uploaded


Review Board


This introduces HostingServiceClient.get_http_credentials(), which is
responsible for returning the credentials used to authenticate with the
hosting service. It takes in the username/password provided in the
request (if any), along with any other request arguments, and returns a
dictionary that will be passed down into build_http_request().

By default, this will return the account username and password (if an
encrypted password key exists in the account data), which
build_http_request() will use for Basic or Digest auth (if enabled on
the client). Subclasses are free to handle those credentials however
they want, though.

Alternatively, it can return a headers key in the credentials
dictionary, and all headers will be added to the request. This allows
for a custom Authorization header, or some other header used for that
particular service.

This takes care of one of the more common cases for overriding
build_http_request(), and simplifies unit testing.

Unit tests can more easily test against the credentials as well, either
using the already-supported username= and password= keyword
arguments in assertHTTPCall(), or by passing in a credentials= with
the full dictionary.

RB Gateway has been updated to take advantage of this new support.

Unit tests pass.

Tested that I can link an account with RB Gateway.