Skip to content

Commit

Permalink
fix(mako): deal with missing auth information
Browse files Browse the repository at this point in the history
Now all APIs can be built successfully, which should help to
prevent things from getting hardcoded in any way.
  • Loading branch information
Byron committed Mar 10, 2015
1 parent c7e169d commit df9f029
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
18 changes: 0 additions & 18 deletions etc/api/shared.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,6 @@ directories:
# all mako source files
mako_src: src/mako
api:
blacklist:
- groupsmigration # no oauth2
- licensing # no oauth2
- translate # no oauth2
- pagespeedonline # no oauth2
- gan # no oauth2
- dataflow # no oauth2
- civicinfo # no oauth2
- webmasters # no oauth2
- doubleclickbidmanager # no oauth2
- freebase # no oauth2
- spectrum # no oauth2
- qpxexpress # no oauth2
- discovery # no oauth2
- identitytoolkit # no oauth2
- audit # no oauth2
- webfonts # no oauth2
- customsearch # no oauth2
base_path: "etc/api"
terms:
# how to actually do something with the API
Expand Down
2 changes: 1 addition & 1 deletion src/mako/deps.mako
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<%api_info=[]%>\
% for an, versions in api.list.iteritems():
% if an in api.blacklist:
% if an in api.get('blacklist', list()):
<% continue %>\
% endif
% for version in versions:
Expand Down
4 changes: 4 additions & 0 deletions src/mako/lib/lib.mako
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,13 @@ You can read the full text at the repository's [license file][repo-license].


## Builds the scope-enum for the API
## It's possible there is no scope enum if there is no auth information
###############################################################################################
###############################################################################################
<%def name="scope_enum()">\
% if not auth or not auth.oauth2:
<% return '' %>\
% endif
/// Identifies the an OAuth2 authorization scope.
/// A scope is needed when requesting an
/// [authorization token](https://developers.google.com/youtube/v3/guides/authentication).
Expand Down
4 changes: 4 additions & 0 deletions src/mako/lib/mbuild.mako
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ pub struct ${ThisType}
% endfor
## A generic map for additinal parameters. Sometimes you can set some that are documented online only
${api.properties.params}: HashMap<String, String>,
% if auth and auth.oauth2:
## We need the scopes sorted, to not unnecessarily query new tokens
${api.properties.scopes}: BTreeMap<String, ()>
% endif
}
impl${mb_tparams} MethodBuilder for ${ThisType} {}
Expand Down Expand Up @@ -132,6 +134,7 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\
self
}
% if auth and auth.oauth2:
/// Identifies the authorization scope for the method you are building.
///
/// Use this method to actively specify which scope should be used, instead of relying on the
Expand All @@ -148,6 +151,7 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\
self.${api.properties.scopes}.insert(scope.as_slice().to_string(), ());
self
}
% endif
}
</%def>

Expand Down
8 changes: 7 additions & 1 deletion src/mako/lib/rbuild.mako
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ impl${rb_params} ${ThisType} {
method_args = ', ' + ', '.join('%s: %s' % (mangle_ident(p.name), activity_input_type(p)) for p in required_props)
mb_tparams = mb_type_params_s(m)
# we would could have information about data requirements for each property in it's dict.
# for now, we just hardcode it, and treat the entries as way to easily change param names
assert len(api.properties) == 2, "Hardcoded for now, thanks to scope requirements"
%>\
% if 'description' in m:
Expand All @@ -84,7 +87,10 @@ impl${rb_params} ${ThisType} {
% for p in optional_props:
${property(p.name)}: Default::default(),
% endfor
% for custom_name in api.properties.values():
% for prop_key, custom_name in api.properties.iteritems():
% if prop_key == 'scopes' and (not auth or not auth.oauth2):
<% continue %>\
% endif
${custom_name}: Default::default(),
% endfor
}
Expand Down

0 comments on commit df9f029

Please sign in to comment.