Remove support for debug logging of CLI programs

The needed feature was removed from yup-hyper-mock, and if needed
it can certainly be re-implemented.
This commit is contained in:
Sebastian Thiel
2021-04-01 16:37:53 +08:00
parent 112ef3f3ac
commit 0bf46b95f3
7 changed files with 6 additions and 120 deletions

View File

@@ -26,7 +26,6 @@ path = "src/main.rs"
% endif
[dependencies]
hyper = "^ 0.14"
hyper-rustls = "^0.22"
## Must match the one hyper uses, otherwise there are duplicate similarly named `Mime` structs
mime = "^ 0.2.0"
@@ -34,7 +33,6 @@ serde = "^ 1.0"
serde_json = "^ 1.0"
serde_derive = "^ 1.0"
yup-oauth2 = "^ 5.0"
tokio = "^ 1.0"
itertools = "^ 0.10"
% for dep in cargo.get('dependencies', list()):
${dep}

View File

@@ -1,6 +1,6 @@
<%
from util import (markdown_comment, new_context)
from cli import (CONFIG_DIR, CONFIG_DIR_FLAG, SCOPE_FLAG, application_secret_path, DEBUG_FLAG, DEBUG_AUTH_FLAG)
from cli import (CONFIG_DIR, CONFIG_DIR_FLAG, SCOPE_FLAG, application_secret_path, DEBUG_FLAG)
c = new_context(schemas, resources, context.get('methods'))
%>\
@@ -88,10 +88,7 @@ Even though the CLI does its best to provide usable error messages, sometimes it
what exactly led to a particular issue. This is done by allowing all client-server communication to be
output to standard error *as-is*.
The `--${DEBUG_FLAG}` flag will print all client-server communication to standard error, whereas the `--${DEBUG_AUTH_FLAG}` flag
will cause all communication related to authentication to standard error.
If the `--${DEBUG_FLAG}` flag is set, error-results will be debug-printed, possibly yielding more information about the
issue at hand.
The `--${DEBUG_FLAG}` flag will print errors using the `Debug` representation to standard error.
You may consider redirecting standard error into a file for ease of use, e.g. `${util.program_name()} --${DEBUG_FLAG} <resource> <method> [options] 2>debug.txt`.

View File

@@ -5,7 +5,7 @@
from util import (put_and, supports_scopes, api_index, indent_by, enclose_in, put_and, escape_rust_string)
from cli import (mangle_subcommand, new_method_context, PARAM_FLAG, STRUCT_FLAG, UPLOAD_FLAG, OUTPUT_FLAG, VALUE_ARG,
CONFIG_DIR, SCOPE_FLAG, is_request_value_property, FIELD_SEP, docopt_mode, FILE_ARG, MIME_ARG, OUT_ARG,
CONFIG_DIR_FLAG, KEY_VALUE_ARG, to_docopt_arg, DEBUG_FLAG, DEBUG_AUTH_FLAG, MODE_ARG, SCOPE_ARG,
CONFIG_DIR_FLAG, KEY_VALUE_ARG, to_docopt_arg, DEBUG_FLAG, MODE_ARG, SCOPE_ARG,
CONFIG_DIR_ARG, FILE_FLAG, MIME_FLAG, subcommand_md_filename)
def rust_boolean(v):
@@ -71,12 +71,6 @@ 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_FLAG}
Output all server communication to standard error. `tx` and `rx` are placed
into the same stream.
--${DEBUG_AUTH_FLAG}
Output all communication related to authentication to standard error. `tx`
and `rx` are placed into the same stream.
</%def>
@@ -114,16 +108,7 @@ Configuration:
global_args.append((
DEBUG_FLAG,
"Output all server communication to standard error. `tx` and `rx` are placed "
"into the same stream.",
None,
False,
))
global_args.append((
DEBUG_AUTH_FLAG,
"Output all communication related to authentication to standard error. `tx` "
"and `rx` are placed into the same stream.",
"Debug print all errors",
None,
False,
))

View File

@@ -7,7 +7,7 @@
CONFIG_DIR, SCOPE_FLAG, is_request_value_property, FIELD_SEP, docopt_mode, FILE_ARG, MIME_ARG, OUT_ARG,
call_method_ident, POD_TYPES, opt_value, ident, JSON_TYPE_VALUE_MAP,
KEY_VALUE_ARG, to_cli_schema, SchemaEntry, CTYPE_POD, actual_json_type, CTYPE_MAP, CTYPE_ARRAY,
application_secret_path, DEBUG_FLAG, DEBUG_AUTH_FLAG, CONFIG_DIR_FLAG, req_value, MODE_ARG,
application_secret_path, CONFIG_DIR_FLAG, req_value, MODE_ARG,
opt_values, SCOPE_ARG, CONFIG_DIR_ARG, DEFAULT_MIME, field_vec, comma_sep_fields, JSON_TYPE_TO_ENUM_MAP,
CTYPE_TO_ENUM_MAP)
@@ -122,8 +122,7 @@ impl<'n> Engine<'n> {
yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
).persist_tokens_to_disk(format!("{}/${util.program_name()}", config_dir)).build().await.unwrap();
let client =
${self._debug_client(DEBUG_FLAG) | indent_all_but_first_by(3)};
let client = hyper::Client::builder().build(hyper_rustls::HttpsConnector::with_native_roots());
<% gpm = gen_global_parameter_names(parameters) %>\
let engine = Engine {
opt: opt,
@@ -152,16 +151,6 @@ impl<'n> Engine<'n> {
}
</%def>
<%def name="_debug_client(flag_name)" buffered="True">\
if opt.is_present("${flag_name}") {
hyper::Client::with_connector(mock::TeeConnector {
connector: hyper::net::HttpsConnector::new(hyper_rustls::TlsClient::new())
})
} else {
hyper::Client::with_connector(hyper::net::HttpsConnector::new(hyper_rustls::TlsClient::new()))
}\
</%def>
<%def name="_method_call_impl(c, resource, method)" buffered="True">\
<%
mc = new_method_context(resource, method, c)

View File

@@ -14,13 +14,11 @@
</%block>
#![allow(unused_variables, unused_imports, dead_code, unused_mut)]
#[macro_use]
extern crate tokio;
#[macro_use]
extern crate clap;
extern crate yup_oauth2 as oauth2;
extern crate yup_hyper_mock as mock;
extern crate hyper_rustls;
extern crate serde;
extern crate serde_json;

View File

@@ -18,7 +18,6 @@ KEY_VALUE_ARG = 'kv'
SCOPE_FLAG = 'scope'
CONFIG_DIR_FLAG = 'config-dir'
DEBUG_FLAG = 'debug'
DEBUG_AUTH_FLAG = 'debug-auth'
DEFAULT_MIME = 'application/octet-stream'
MODE_ARG = 'mode'

View File

@@ -27,8 +27,6 @@ mod cli;
/// This module is for testing only, its code is used in mako templates
#[cfg(test)]
mod test_api {
extern crate yup_hyper_mock as hyper_mock;
use self::hyper_mock::*;
use super::api::client::*;
use hyper;
use std::default::Default;
@@ -51,49 +49,6 @@ bar\r\n\
const EXPECTED_LEN: usize = 223;
#[test]
fn multi_part_reader() {
let mut r1 = MockStream::with_input(b"foo");
let mut r2 = MockStream::with_input(b"bar");
let mut mpr: MultiPartReader = Default::default();
mpr.add_part(&mut r1, 50, "application/json".parse().unwrap())
.add_part(&mut r2, 25, "application/plain".parse().unwrap());
let mut res = String::new();
let r = mpr.read_to_string(&mut res).unwrap();
assert_eq!(res.len(), r);
// NOTE: This CAN fail, as the underlying header hashmap is not sorted
// As the test is just for dev, and doesn't run on travis, we are fine,
// for now. Possible solution would be to omit the size field (make it
// optional)
assert_eq!(r, EXPECTED_LEN);
// assert_eq!(res, EXPECTED);
}
#[test]
fn multi_part_reader_single_byte_read() {
let mut r1 = MockStream::with_input(b"foo");
let mut r2 = MockStream::with_input(b"bar");
let mut mpr: MultiPartReader = Default::default();
mpr.add_part(&mut r1, 50, "application/json".parse().unwrap())
.add_part(&mut r2, 25, "application/plain".parse().unwrap());
let buf = &mut [0u8];
let mut v = Vec::<u8>::new();
while let Ok(br) = mpr.read(buf) {
if br == 0 {
break;
}
v.push(buf[0]);
}
assert_eq!(v.len(), EXPECTED_LEN);
// See above: headers are unordered
// assert_eq!(v.container_as_str().unwrap(), EXPECTED);
}
#[test]
fn serde() {
#[derive(Default, Serialize, Deserialize)]
@@ -135,33 +90,6 @@ bar\r\n\
// let b: BarOpt = json::from_str(&j).unwrap();
}
#[test]
fn content_range() {
for &(ref c, ref expected) in &[
(
ContentRange {
range: None,
total_length: 50,
},
"Content-Range: bytes */50\r\n",
),
(
ContentRange {
range: Some(Chunk {
first: 23,
last: 40,
}),
total_length: 45,
},
"Content-Range: bytes 23-40/45\r\n",
),
] {
let mut headers = hyper::header::Headers::new();
headers.set(c.clone());
assert_eq!(headers.to_string(), expected.to_string());
}
}
#[test]
fn byte_range_from_str() {
assert_eq!(
@@ -169,14 +97,6 @@ bar\r\n\
Ok(Chunk { first: 2, last: 42 })
)
}
#[test]
fn parse_range_response() {
let r: RangeResponseHeader =
hyper::header::Header::parse_header(&[b"bytes 2-42".to_vec()]).unwrap();
assert_eq!(r.0.first, 2);
assert_eq!(r.0.last, 42);
}
}
#[cfg(test)]