blob: e6291fdaea4d63592cee95fbbd52cf921f066a34 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# Copyright 2016 Google Inc. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Provide various utility/container types needed by Endpoints Framework.
16
17Putting them in this file makes it easier to avoid circular imports,
18as well as keep from complicating tests due to importing code that
19uses App Engine apis.
20"""
21
22from __future__ import absolute_import
23
24import six
25
26import attr
27
28__all__ = [
29 'OAuth2Scope', 'Issuer', 'LimitDefinition', 'Namespace',
30]
31
32
33@attr.s(frozen=True, slots=True)
34class OAuth2Scope(object):
35 scope = attr.ib(validator=attr.validators.instance_of(six.string_types))
36 description = attr.ib(validator=attr.validators.instance_of(six.string_types))
37
38 @classmethod
39 def convert_scope(cls, scope):
40 "Convert string scopes into OAuth2Scope objects."
41 if isinstance(scope, cls):
42 return scope
43 return cls(scope=scope, description=scope)
44
45 @classmethod
46 def convert_list(cls, values):
47 "Convert a list of scopes into a list of OAuth2Scope objects."
48 if values is not None:
49 return [cls.convert_scope(value) for value in values]
50
51Issuer = attr.make_class('Issuer', ['issuer', 'jwks_uri'])
52LimitDefinition = attr.make_class('LimitDefinition', ['metric_name',
53 'display_name',
54 'default_limit'])
55Namespace = attr.make_class('Namespace', ['owner_domain',
56 'owner_name',
57 'package_path'])