mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-01-09 13:04:05 +01:00
chore(code): updated to latest state
This commit is contained in:
@@ -20,7 +20,7 @@ use clap::{App, SubCommand, Arg};
|
||||
|
||||
mod cmn;
|
||||
|
||||
use cmn::{InvalidOptionsError, CLIError, JsonTokenStorage, arg_from_str, writer_from_opts, parse_kv_arg,
|
||||
use cmn::{InvalidOptionsError, CLIError, JsonTokenStorage, arg_from_str, writer_from_opts, parse_kv_arg,
|
||||
input_file_from_opts, input_mime_from_opts, FieldCursor, FieldError, CallType, UploadProtocol,
|
||||
calltype_from_str, remove_json_null_values, ComplexType, JsonType, JsonTypeInfo};
|
||||
|
||||
@@ -36,76 +36,22 @@ enum DoitError {
|
||||
ApiError(api::Error),
|
||||
}
|
||||
|
||||
struct Engine<'n, 'a> {
|
||||
opt: ArgMatches<'n, 'a>,
|
||||
struct Engine<'n> {
|
||||
opt: ArgMatches<'n>,
|
||||
hub: api::Cloudtrace<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>,
|
||||
gp: Vec<&'static str>,
|
||||
gpm: Vec<(&'static str, &'static str)>,
|
||||
}
|
||||
|
||||
|
||||
impl<'n, 'a> Engine<'n, 'a> {
|
||||
fn _methods_get_discovery(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
||||
-> Result<(), DoitError> {
|
||||
let mut call = self.hub.methods().get_discovery();
|
||||
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
|
||||
let (key, value) = parse_kv_arg(&*parg, err, false);
|
||||
match key {
|
||||
"version" => {
|
||||
call = call.version(value.unwrap_or(""));
|
||||
},
|
||||
"labels" => {
|
||||
call = call.add_labels(value.unwrap_or(""));
|
||||
},
|
||||
"format" => {
|
||||
call = call.format(value.unwrap_or(""));
|
||||
},
|
||||
"args" => {
|
||||
call = call.add_args(value.unwrap_or(""));
|
||||
},
|
||||
_ => {
|
||||
let mut found = false;
|
||||
for param in &self.gp {
|
||||
if key == *param {
|
||||
found = true;
|
||||
call = call.param(self.gpm.iter().find(|t| t.0 == key).unwrap_or(&("", key)).1, value.unwrap_or("unset"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v.extend(["labels", "version", "args", "format"].iter().map(|v|*v));
|
||||
v } ));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let protocol = CallType::Standard;
|
||||
if dry_run {
|
||||
Ok(())
|
||||
} else {
|
||||
assert!(err.issues.len() == 0);
|
||||
match match protocol {
|
||||
CallType::Standard => call.doit(),
|
||||
_ => unreachable!()
|
||||
} {
|
||||
Err(api_err) => Err(DoitError::ApiError(api_err)),
|
||||
Ok(mut response) => {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn _projects_patch_traces(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
||||
impl<'n> Engine<'n> {
|
||||
fn _projects_patch_traces(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
|
||||
-> Result<(), DoitError> {
|
||||
|
||||
let mut field_cursor = FieldCursor::default();
|
||||
let mut object = json::value::Value::Object(Default::default());
|
||||
|
||||
for kvarg in opt.values_of("kv").unwrap_or(Vec::new()).iter() {
|
||||
for kvarg in opt.values_of("kv").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
|
||||
let last_errc = err.issues.len();
|
||||
let (key, value) = parse_kv_arg(&*kvarg, err, false);
|
||||
let mut temp_cursor = field_cursor.clone();
|
||||
@@ -119,8 +65,8 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
let type_info: Option<(&'static str, JsonTypeInfo)> =
|
||||
|
||||
let type_info: Option<(&'static str, JsonTypeInfo)> =
|
||||
match &temp_cursor.to_string()[..] {
|
||||
_ => {
|
||||
let suggestion = FieldCursor::did_you_mean(key, &vec![]);
|
||||
@@ -134,7 +80,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
let mut request: api::Traces = json::value::from_value(object).unwrap();
|
||||
let mut call = self.hub.projects().patch_traces(request, opt.value_of("project-id").unwrap_or(""));
|
||||
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
|
||||
for parg in opt.values_of("v").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
|
||||
let (key, value) = parse_kv_arg(&*parg, err, false);
|
||||
match key {
|
||||
_ => {
|
||||
@@ -147,7 +93,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v } ));
|
||||
@@ -160,7 +106,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
Ok(())
|
||||
} else {
|
||||
assert!(err.issues.len() == 0);
|
||||
for scope in self.opt.values_of("url").unwrap_or(Vec::new()).iter() {
|
||||
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
|
||||
call = call.add_scope(scope);
|
||||
}
|
||||
let mut ostream = match writer_from_opts(opt.value_of("out")) {
|
||||
@@ -183,10 +129,10 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn _projects_traces_get(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
||||
fn _projects_traces_get(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
|
||||
-> Result<(), DoitError> {
|
||||
let mut call = self.hub.projects().traces_get(opt.value_of("project-id").unwrap_or(""), opt.value_of("trace-id").unwrap_or(""));
|
||||
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
|
||||
for parg in opt.values_of("v").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
|
||||
let (key, value) = parse_kv_arg(&*parg, err, false);
|
||||
match key {
|
||||
_ => {
|
||||
@@ -199,7 +145,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v } ));
|
||||
@@ -212,7 +158,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
Ok(())
|
||||
} else {
|
||||
assert!(err.issues.len() == 0);
|
||||
for scope in self.opt.values_of("url").unwrap_or(Vec::new()).iter() {
|
||||
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
|
||||
call = call.add_scope(scope);
|
||||
}
|
||||
let mut ostream = match writer_from_opts(opt.value_of("out")) {
|
||||
@@ -235,10 +181,10 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn _projects_traces_list(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
|
||||
fn _projects_traces_list(&self, opt: &ArgMatches<'n>, dry_run: bool, err: &mut InvalidOptionsError)
|
||||
-> Result<(), DoitError> {
|
||||
let mut call = self.hub.projects().traces_list(opt.value_of("project-id").unwrap_or(""));
|
||||
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
|
||||
for parg in opt.values_of("v").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
|
||||
let (key, value) = parse_kv_arg(&*parg, err, false);
|
||||
match key {
|
||||
"view" => {
|
||||
@@ -272,7 +218,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
err.issues.push(CLIError::UnknownParameter(key.to_string(),
|
||||
{let mut v = Vec::new();
|
||||
v.extend(self.gp.iter().map(|v|*v));
|
||||
v.extend(["order-by", "page-size", "filter", "page-token", "start-time", "end-time", "view"].iter().map(|v|*v));
|
||||
@@ -286,7 +232,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
Ok(())
|
||||
} else {
|
||||
assert!(err.issues.len() == 0);
|
||||
for scope in self.opt.values_of("url").unwrap_or(Vec::new()).iter() {
|
||||
for scope in self.opt.values_of("url").map(|i|i.collect()).unwrap_or(Vec::new()).iter() {
|
||||
call = call.add_scope(scope);
|
||||
}
|
||||
let mut ostream = match writer_from_opts(opt.value_of("out")) {
|
||||
@@ -314,17 +260,6 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
let mut call_result: Result<(), DoitError> = Ok(());
|
||||
let mut err_opt: Option<InvalidOptionsError> = None;
|
||||
match self.opt.subcommand() {
|
||||
("methods", Some(opt)) => {
|
||||
match opt.subcommand() {
|
||||
("get-discovery", Some(opt)) => {
|
||||
call_result = self._methods_get_discovery(opt, dry_run, &mut err);
|
||||
},
|
||||
_ => {
|
||||
err.issues.push(CLIError::MissingMethodError("methods".to_string()));
|
||||
writeln!(io::stderr(), "{}\n", opt.usage()).ok();
|
||||
}
|
||||
}
|
||||
},
|
||||
("projects", Some(opt)) => {
|
||||
match opt.subcommand() {
|
||||
("patch-traces", Some(opt)) => {
|
||||
@@ -359,14 +294,14 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
}
|
||||
|
||||
// Please note that this call will fail if any part of the opt can't be handled
|
||||
fn new(opt: ArgMatches<'a, 'n>) -> Result<Engine<'a, 'n>, InvalidOptionsError> {
|
||||
fn new(opt: ArgMatches<'n>) -> Result<Engine<'n>, InvalidOptionsError> {
|
||||
let (config_dir, secret) = {
|
||||
let config_dir = match cmn::assure_config_dir_exists(opt.value_of("folder").unwrap_or("~/.google-service-cli")) {
|
||||
Err(e) => return Err(InvalidOptionsError::single(e, 3)),
|
||||
Ok(p) => p,
|
||||
};
|
||||
|
||||
match cmn::application_secret_from_directory(&config_dir, "cloudtrace1-secret.json",
|
||||
match cmn::application_secret_from_directory(&config_dir, "cloudtrace1-secret.json",
|
||||
"{\"installed\":{\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"client_secret\":\"hCsslbCUyfehWMmbkG8vTYxG\",\"token_uri\":\"https://accounts.google.com/o/oauth2/token\",\"client_email\":\"\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"oob\"],\"client_x509_cert_url\":\"\",\"client_id\":\"620010449518-9ngf7o4dhs0dka470npqvor6dc5lqb9b.apps.googleusercontent.com\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\"}}") {
|
||||
Ok(secret) => (config_dir, secret),
|
||||
Err(e) => return Err(InvalidOptionsError::single(e, 4))
|
||||
@@ -386,7 +321,7 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
db_dir: config_dir.clone(),
|
||||
}, None);
|
||||
|
||||
let client =
|
||||
let client =
|
||||
if opt.is_present("debug") {
|
||||
hyper::Client::with_connector(mock::TeeConnector {
|
||||
connector: hyper::net::HttpsConnector::<hyper::net::Openssl>::default()
|
||||
@@ -428,27 +363,14 @@ impl<'n, 'a> Engine<'n, 'a> {
|
||||
fn main() {
|
||||
let mut exit_status = 0i32;
|
||||
let arg_data = [
|
||||
("methods", "methods: 'get-discovery'", vec![
|
||||
("get-discovery",
|
||||
Some(r##"Returns a discovery document in the specified `format`. The typeurl in the returned google.protobuf.Any value depends on the requested format."##),
|
||||
"Details at http://byron.github.io/google-apis-rs/google_cloudtrace1_cli/methods_get-discovery",
|
||||
vec![
|
||||
(Some(r##"v"##),
|
||||
Some(r##"p"##),
|
||||
Some(r##"Set various optional parameters, matching the key=value form"##),
|
||||
Some(false),
|
||||
Some(true)),
|
||||
]),
|
||||
]),
|
||||
|
||||
("projects", "methods: 'patch-traces', 'traces-get' and 'traces-list'", vec![
|
||||
("patch-traces",
|
||||
Some(r##"Updates the existing traces specified by PatchTracesRequest and inserts the new traces. Any existing trace or span fields included in an update are overwritten by the update, and any additional fields in an update are merged with the existing trace data."##),
|
||||
("patch-traces",
|
||||
Some(r##"Sends new traces to Cloud Trace or updates existing traces. If the ID of a trace that you send matches that of an existing trace, any fields in the existing trace and its spans are overwritten by the provided values, and any new fields provided are merged with the existing trace data. If the ID does not match, a new trace is created."##),
|
||||
"Details at http://byron.github.io/google-apis-rs/google_cloudtrace1_cli/projects_patch-traces",
|
||||
vec![
|
||||
(Some(r##"project-id"##),
|
||||
None,
|
||||
Some(r##"The project id of the trace to patch."##),
|
||||
Some(r##"ID of the Cloud project where the trace data is stored."##),
|
||||
Some(true),
|
||||
Some(false)),
|
||||
|
||||
@@ -470,19 +392,19 @@ fn main() {
|
||||
Some(false),
|
||||
Some(false)),
|
||||
]),
|
||||
("traces-get",
|
||||
Some(r##"Gets one trace by id."##),
|
||||
("traces-get",
|
||||
Some(r##"Gets a single trace by its ID."##),
|
||||
"Details at http://byron.github.io/google-apis-rs/google_cloudtrace1_cli/projects_traces-get",
|
||||
vec![
|
||||
(Some(r##"project-id"##),
|
||||
None,
|
||||
Some(r##"The project id of the trace to return."##),
|
||||
Some(r##"ID of the Cloud project where the trace data is stored."##),
|
||||
Some(true),
|
||||
Some(false)),
|
||||
|
||||
(Some(r##"trace-id"##),
|
||||
None,
|
||||
Some(r##"The trace id of the trace to return."##),
|
||||
Some(r##"ID of the trace to return."##),
|
||||
Some(true),
|
||||
Some(false)),
|
||||
|
||||
@@ -498,13 +420,13 @@ fn main() {
|
||||
Some(false),
|
||||
Some(false)),
|
||||
]),
|
||||
("traces-list",
|
||||
Some(r##"List traces matching the filter expression."##),
|
||||
("traces-list",
|
||||
Some(r##"Returns of a list of traces that match the specified filter conditions."##),
|
||||
"Details at http://byron.github.io/google-apis-rs/google_cloudtrace1_cli/projects_traces-list",
|
||||
vec![
|
||||
(Some(r##"project-id"##),
|
||||
None,
|
||||
Some(r##"The stringified-version of the project id."##),
|
||||
Some(r##"ID of the Cloud project where the trace data is stored."##),
|
||||
Some(true),
|
||||
Some(false)),
|
||||
|
||||
@@ -526,8 +448,8 @@ fn main() {
|
||||
|
||||
let mut app = App::new("cloudtrace1")
|
||||
.author("Sebastian Thiel <byronimo@gmail.com>")
|
||||
.version("0.3.2+20150825")
|
||||
.about("The Google Cloud Trace API provides services for reading and writing runtime trace data for Cloud applications.")
|
||||
.version("0.3.3+20151207")
|
||||
.about("The Cloud Trace API allows you to send traces to and retrieve traces from Google Cloud Trace.")
|
||||
.after_help("All documentation details can be found at http://byron.github.io/google-apis-rs/google_cloudtrace1_cli")
|
||||
.arg(Arg::with_name("url")
|
||||
.long("scope")
|
||||
@@ -550,7 +472,7 @@ fn main() {
|
||||
.multiple(false)
|
||||
.takes_value(false));
|
||||
|
||||
for &(main_command_name, ref about, ref subcommands) in arg_data.iter() {
|
||||
for &(main_command_name, about, ref subcommands) in arg_data.iter() {
|
||||
let mut mcmd = SubCommand::with_name(main_command_name).about(about);
|
||||
|
||||
for &(sub_command_name, ref desc, url_info, ref args) in subcommands {
|
||||
@@ -561,7 +483,7 @@ fn main() {
|
||||
scmd = scmd.after_help(url_info);
|
||||
|
||||
for &(ref arg_name, ref flag, ref desc, ref required, ref multi) in args {
|
||||
let arg_name_str =
|
||||
let arg_name_str =
|
||||
match (arg_name, flag) {
|
||||
(&Some(an), _ ) => an,
|
||||
(_ , &Some(f)) => f,
|
||||
|
||||
Reference in New Issue
Block a user