Passed
Push — develop ( e15ceb...5f9839 )
by Dean
02:51
created

Service   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 12
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A context() 0 3 1
A __init__() 0 2 1
1
from plugin.api.core.exceptions import ApiError
2
from plugin.api.core.manager import ApiManager
0 ignored issues
show
Bug introduced by
The name manager does not seem to exist in module plugin.api.core.
Loading history...
Configuration introduced by
Unable to import 'plugin.api.core.manager' (invalid syntax (<string>, line 77))

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
3
from plugin.core.helpers import decorator
4
5
import logging
6
7
log = logging.getLogger(__name__)
8
9
10
class AuthenticationRequiredError(ApiError):
11
    code = 'authentication.required'
12
    message = 'API authentication required'
13
14
15
class ServiceMeta(type):
16
    def __init__(cls, name, bases, attributes):
17
        super(ServiceMeta, cls).__init__(name, bases, attributes)
18
19
        if '__metaclass__' in attributes:
20
            return
21
22
        # Register API service
23
        ApiManager.register(cls)
24
25
26
class Service(object):
27
    __metaclass__ = ServiceMeta
28
    __key__ = None
29
30
    manager = None
31
32
    def __init__(self, manager):
33
        self.manager = manager
34
35
    @property
36
    def context(self):
37
        return self.manager.context
38
39
40
@decorator.wraps
41
def expose(authenticated=True):
42
    def outer(func):
43
        def inner(self, *args, **kwargs):
44
            if authenticated and self.context.token is None:
45
                raise AuthenticationRequiredError
46
47
            return func(self, *args, **kwargs)
48
49
        # Attach meta to wrapper
50
        inner.__meta__ = {
51
            'authenticated': authenticated,
52
            'exposed': True
53
        }
54
55
        return inner
56
57
    return outer
58