Skip to content

Commit 6befdbc

Browse files
committed
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
1 parent a328942 commit 6befdbc

6 files changed

Lines changed: 13 additions & 7 deletions

File tree

etc/api/discovery/v1/discovery-api_overrides.json

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
no_auth: 1

src/mako/api/lib/mbuild.mako

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
DELEGATE_PROPERTY_NAME, struct_type_bounds_s, scope_url_to_variant,
1212
re_find_replacements, ADD_PARAM_FN, ADD_PARAM_MEDIA_EXAMPLE, upload_action_fn, METHODS_RESOURCE,
1313
method_name_to_variant, unique_type_name, size_to_bytes, method_default_scope,
14-
is_repeated_property, setter_fn_name)
14+
is_repeated_property, setter_fn_name, ADD_SCOPE_FN)
1515
1616
def get_parts(part_prop):
1717
if not part_prop:
@@ -173,7 +173,7 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\
173173
/// Usually there is more than one suitable scope to authorize an operation, some of which may
174174
/// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
175175
/// sufficient, a read-write scope will do as well.
176-
pub fn add_scope<T>(mut self, scope: T) -> ${ThisType}
176+
pub fn ${ADD_SCOPE_FN}<T>(mut self, scope: T) -> ${ThisType}
177177
where T: AsRef<str> {
178178
self.${api.properties.scopes}.insert(scope.as_ref().to_string(), ());
179179
self

src/mako/cli/lib/engine.mako

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<%namespace name="util" file="../../lib/util.mako"/>\
22
<%!
33
from util import (hub_type, mangle_ident, indent_all_but_first_by, activity_rust_type, setter_fn_name, ADD_PARAM_FN,
4-
upload_action_fn, is_schema_with_optionals, schema_markers, indent_by)
4+
upload_action_fn, is_schema_with_optionals, schema_markers, indent_by, method_default_scope,
5+
ADD_SCOPE_FN)
56
from cli import (mangle_subcommand, new_method_context, PARAM_FLAG, STRUCT_FLAG, UPLOAD_FLAG, OUTPUT_FLAG, VALUE_ARG,
67
CONFIG_DIR, SCOPE_FLAG, is_request_value_property, FIELD_SEP, docopt_mode, FILE_ARG, MIME_ARG, OUT_ARG,
78
cmd_ident, call_method_ident, arg_ident, POD_TYPES, flag_ident, ident, JSON_TYPE_VALUE_MAP,
@@ -284,6 +285,12 @@ if dry_run {
284285
None
285286
} else {
286287
assert!(err.issues.len() == 0);
288+
% if method_default_scope(mc.m):
289+
<% scope_opt = SOPT + flag_ident('scope') %>\
290+
if ${scope_opt}.len() > 0 {
291+
call = call.${ADD_SCOPE_FN}(&${scope_opt});
292+
}
293+
% endif
287294
## Make the call, handle uploads, handle downloads (also media downloads|json decoding)
288295
## TODO: unify error handling
289296
% if handle_output:

src/mako/deps.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
api_meta_dir = os.path.dirname(api_json)
7676
api_crate_publish_file = api_meta_dir + '/crates/' + util.crate_version(cargo.build_version +
7777
make.aggregated_target_suffix, json.load(open(api_json, 'r')).get('revision', '00000000'))
78-
api_json_overrides = api_meta_dir + '/' + an + '-api_overrides.json'
78+
api_json_overrides = api_meta_dir + '/' + an + '-api_overrides.yaml'
7979
type_specific_json = '$(API_DIR)/type-' + make.id + '.yaml'
8080
api_json_inputs = api_json + ' $(API_SHARED_INFO) ' + type_specific_json
8181
if os.path.isfile(api_json_overrides):

src/mako/lib/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
METHODS_RESOURCE = 'methods'
5555

5656
ADD_PARAM_FN = 'param'
57+
ADD_SCOPE_FN = 'add_scope'
5758
ADD_PARAM_MEDIA_EXAMPLE = "." + ADD_PARAM_FN + '("alt", "media")'
5859

5960
SPACES_PER_TAB = 4

0 commit comments

Comments
 (0)