From 6befdbc6fa730fc4a5513d2cad9e1784c580e516 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 25 Apr 2015 11:35:39 +0200 Subject: [PATCH] fix(CLI): verified download works * implement custom scopes - previously they could be set, but were ignored during the API call * api-overrides are not yaml files for convenience. Existing ones were updated as needed. Fixes #75 --- etc/api/discovery/v1/discovery-api_overrides.json | 3 --- etc/api/discovery/v1/discovery-api_overrides.yaml | 1 + src/mako/api/lib/mbuild.mako | 4 ++-- src/mako/cli/lib/engine.mako | 9 ++++++++- src/mako/deps.mako | 2 +- src/mako/lib/util.py | 1 + 6 files changed, 13 insertions(+), 7 deletions(-) delete mode 100644 etc/api/discovery/v1/discovery-api_overrides.json create mode 100644 etc/api/discovery/v1/discovery-api_overrides.yaml diff --git a/etc/api/discovery/v1/discovery-api_overrides.json b/etc/api/discovery/v1/discovery-api_overrides.json deleted file mode 100644 index 2e9eb70061..0000000000 --- a/etc/api/discovery/v1/discovery-api_overrides.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "no_auth": 1 -} \ No newline at end of file diff --git a/etc/api/discovery/v1/discovery-api_overrides.yaml b/etc/api/discovery/v1/discovery-api_overrides.yaml new file mode 100644 index 0000000000..7120077bf5 --- /dev/null +++ b/etc/api/discovery/v1/discovery-api_overrides.yaml @@ -0,0 +1 @@ +no_auth: 1 diff --git a/src/mako/api/lib/mbuild.mako b/src/mako/api/lib/mbuild.mako index 6d0fc43a95..7cfcd0fede 100644 --- a/src/mako/api/lib/mbuild.mako +++ b/src/mako/api/lib/mbuild.mako @@ -11,7 +11,7 @@ DELEGATE_PROPERTY_NAME, struct_type_bounds_s, scope_url_to_variant, re_find_replacements, ADD_PARAM_FN, ADD_PARAM_MEDIA_EXAMPLE, upload_action_fn, METHODS_RESOURCE, method_name_to_variant, unique_type_name, size_to_bytes, method_default_scope, - is_repeated_property, setter_fn_name) + is_repeated_property, setter_fn_name, ADD_SCOPE_FN) def get_parts(part_prop): if not part_prop: @@ -173,7 +173,7 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\ /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn add_scope(mut self, scope: T) -> ${ThisType} + pub fn ${ADD_SCOPE_FN}(mut self, scope: T) -> ${ThisType} where T: AsRef { self.${api.properties.scopes}.insert(scope.as_ref().to_string(), ()); self diff --git a/src/mako/cli/lib/engine.mako b/src/mako/cli/lib/engine.mako index 5a6c460d95..d4510b3609 100644 --- a/src/mako/cli/lib/engine.mako +++ b/src/mako/cli/lib/engine.mako @@ -1,7 +1,8 @@ <%namespace name="util" file="../../lib/util.mako"/>\ <%! from util import (hub_type, mangle_ident, indent_all_but_first_by, activity_rust_type, setter_fn_name, ADD_PARAM_FN, - upload_action_fn, is_schema_with_optionals, schema_markers, indent_by) + upload_action_fn, is_schema_with_optionals, schema_markers, indent_by, method_default_scope, + ADD_SCOPE_FN) 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, cmd_ident, call_method_ident, arg_ident, POD_TYPES, flag_ident, ident, JSON_TYPE_VALUE_MAP, @@ -284,6 +285,12 @@ if dry_run { None } else { assert!(err.issues.len() == 0); + % if method_default_scope(mc.m): +<% scope_opt = SOPT + flag_ident('scope') %>\ + if ${scope_opt}.len() > 0 { + call = call.${ADD_SCOPE_FN}(&${scope_opt}); + } + % endif ## Make the call, handle uploads, handle downloads (also media downloads|json decoding) ## TODO: unify error handling % if handle_output: diff --git a/src/mako/deps.mako b/src/mako/deps.mako index 3eed06b963..0eb4fad91e 100644 --- a/src/mako/deps.mako +++ b/src/mako/deps.mako @@ -75,7 +75,7 @@ api_meta_dir = os.path.dirname(api_json) api_crate_publish_file = api_meta_dir + '/crates/' + util.crate_version(cargo.build_version + make.aggregated_target_suffix, json.load(open(api_json, 'r')).get('revision', '00000000')) - api_json_overrides = api_meta_dir + '/' + an + '-api_overrides.json' + api_json_overrides = api_meta_dir + '/' + an + '-api_overrides.yaml' type_specific_json = '$(API_DIR)/type-' + make.id + '.yaml' api_json_inputs = api_json + ' $(API_SHARED_INFO) ' + type_specific_json if os.path.isfile(api_json_overrides): diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index 7d7cdda65c..9e14cd3cb7 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -54,6 +54,7 @@ DEL_METHOD = 'delete' METHODS_RESOURCE = 'methods' ADD_PARAM_FN = 'param' +ADD_SCOPE_FN = 'add_scope' ADD_PARAM_MEDIA_EXAMPLE = "." + ADD_PARAM_FN + '("alt", "media")' SPACES_PER_TAB = 4