From 159c65916f0fb4d0136a8cc622919daf60a7ecfd Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 21 Apr 2015 12:03:58 +0200 Subject: [PATCH] feat(CLI): --debug flag to output traffix * If `--debug` is set, we will output all server communication to stderr. That way, we can compare our requests to what is expected by ush based on official docs. * `discovery` now doesn't use the API key anymore - this is specified using a custom override. Nice, we are totally ready to test and fix all API features. Related to #70 --- etc/api/discovery/v1/discovery-api_overrides.json | 3 +++ etc/api/type-cli.yaml | 1 + src/mako/api/lib/mbuild.mako | 4 +++- src/mako/cli/lib/docopt.mako | 3 +++ src/mako/cli/lib/engine.mako | 11 ++++++++++- src/mako/cli/main.rs.mako | 6 ++++-- 6 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 etc/api/discovery/v1/discovery-api_overrides.json diff --git a/etc/api/discovery/v1/discovery-api_overrides.json b/etc/api/discovery/v1/discovery-api_overrides.json new file mode 100644 index 0000000000..2e9eb70061 --- /dev/null +++ b/etc/api/discovery/v1/discovery-api_overrides.json @@ -0,0 +1,3 @@ +{ + "no_auth": 1 +} \ No newline at end of file diff --git a/etc/api/type-cli.yaml b/etc/api/type-cli.yaml index 89c4dae62f..25dc06b2b7 100644 --- a/etc/api/type-cli.yaml +++ b/etc/api/type-cli.yaml @@ -29,5 +29,6 @@ cargo: - docopt = "*" - docopt_macros = "*" - rustc-serialize = "*" + - yup-hyper-mock = "*" - serde = ">= 0.3.0" - serde_macros = "*" diff --git a/src/mako/api/lib/mbuild.mako b/src/mako/api/lib/mbuild.mako index da7bc9af45..e66712d052 100644 --- a/src/mako/api/lib/mbuild.mako +++ b/src/mako/api/lib/mbuild.mako @@ -325,7 +325,7 @@ ${capture(lib.test_hub, hub_type_name, comments=show_all) | hide_filter} // As the method needs a request, you would usually fill it with the desired information // into the respective structure. Some of the parts shown here might not be applicable ! // ${random_value_warning} -let mut ${rb_name}: ${request_value_type} = Default::default(); +let mut ${rb_name} = ${request_value_type}::default(); % for spn, sp in request_value.get('properties', dict()).iteritems(): % if parts is not None and spn not in parts: <% continue %> @@ -579,6 +579,7 @@ else { let mut url = "${baseUrl}${m.path}".to_string(); % endif % if not default_scope: + % if no_auth is UNDEFINED: <% assert 'key' in parameters, "Expected 'key' parameter if there are no scopes" %> @@ -593,6 +594,7 @@ else { return Err(Error::MissingAPIKey) } } + % endif % else: if self.${api.properties.scopes}.len() == 0 { self.${api.properties.scopes}.insert(${scope_url_to_variant(name, default_scope, fully_qualified=True)}.as_ref().to_string(), ()); diff --git a/src/mako/cli/lib/docopt.mako b/src/mako/cli/lib/docopt.mako index e74aece73a..ced012a532 100644 --- a/src/mako/cli/lib/docopt.mako +++ b/src/mako/cli/lib/docopt.mako @@ -66,5 +66,8 @@ Configuration: A directory into which we will store our persistent data. Defaults to a user-writable directory that we will create during the first invocation. [default: ${CONFIG_DIR}] + --debug + Output all server communication to standard error. `tx` and `rx` are placed into + the same stream. "); \ No newline at end of file diff --git a/src/mako/cli/lib/engine.mako b/src/mako/cli/lib/engine.mako index 476e295665..efc14ff85a 100644 --- a/src/mako/cli/lib/engine.mako +++ b/src/mako/cli/lib/engine.mako @@ -112,9 +112,18 @@ self.opt.${cmd_ident(method)} { program_name: "${util.program_name()}", db_dir: config_dir.clone(), }, None); + + let client = + if opt.flag_debug { + hyper::Client::with_connector(mock::TeeConnector { + connector: hyper::net::HttpConnector(None) + }) + } else { + hyper::Client::new() + }; let engine = Engine { opt: opt, - hub: ${hub_type_name}::new(hyper::Client::new(), auth), + hub: ${hub_type_name}::new(client, auth), }; match engine._doit(true) { diff --git a/src/mako/cli/main.rs.mako b/src/mako/cli/main.rs.mako index 9bd92b68eb..0e6c0dbd6f 100644 --- a/src/mako/cli/main.rs.mako +++ b/src/mako/cli/main.rs.mako @@ -16,6 +16,7 @@ extern crate docopt; extern crate yup_oauth2 as oauth2; +extern crate yup_hyper_mock as mock; extern crate rustc_serialize; extern crate serde; extern crate hyper; @@ -33,12 +34,13 @@ fn main() { let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit()); match Engine::new(opts) { Err(err) => { - write!(io::stderr(), "{}", err).ok(); + writeln!(io::stderr(), "{}", err).ok(); env::set_exit_status(err.exit_code); }, Ok(engine) => { if let Some(err) = engine.doit() { - write!(io::stderr(), "{}", err).ok(); + writeln!(io::stderr(), "{:?}", err).ok(); + writeln!(io::stderr(), "{}", err).ok(); env::set_exit_status(1); } }