puppetlabs/puppetlabs-cloud-provisioner — pull request #51 by jeffmccune (2011-11-03 21:42:16+00:00)
Title: (#10197) Add HTTP authentication to classify action

Without this patch applied the puppet node classify action does not
support HTTP authentication.

This patch provides basic client authentication using two additional
command line options. This options are truly optional and default to
nil. Authentication will not be used if the options are not provided.

The options --enc-auth-user and --enc-auth-passwd both default to use
environment variables for their values. These environment variables in
turn default to nil if they are not set. This provides a nice
precedence of command line option overriding environment variables
overriding a default nil value.

The patch also moves all of the HTTP client requests into a self
contained method to centralize the authentication logic. This will have
the added benefit of making it easier to mock and test HTTP API calls in
unit testing. The additional method is named http_request to model the
http.request method. The new method automatically determines if it
needs to issue a GET or POST request and will process any JSON responses
provided by the REST API. When issuing a POST, the http_request method
automatically converts and passed data into a JSON string and places it
into the body of the request.

Spec tests have been updated for the option parsing for the classify
action.

In addition, spec tests have been changed to use the new http_request
helper method instead of directly mocking Net::HTTP objects. In turn,
test coverage is included in this patch to validate the expected
behavior of the http_request method this patch introduces.