GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

b2blaze.models.bucket_list.B2Buckets.get()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 5
nop 3
dl 0
loc 12
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
c 0
b 0
f 0
1
"""
2
Copyright George Sibble 2018
3
"""
4
5 1
from ..b2_exceptions import B2Exception, B2InvalidBucketName, B2InvalidBucketConfiguration
6 1
from .bucket import B2Bucket
7 1
from ..api import API
8
9
10 1
class B2Buckets(object):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
11
    """
12
13
    """
14 1
    public = 'allPublic'
15 1
    private = 'allPrivate'
16
17 1
    def __init__(self, connector):
18
        """
19
20
        :param connector:
21
        """
22 1
        self.connector = connector
23 1
        self._buckets_by_name = {}
24 1
        self._buckets_by_id = {}
25
26 1
    def all(self):
27
        """
28
29
        :return:
30
        """
31 1
        return self._update_bucket_list(retrieve=True)
32
33 1
    def _update_bucket_list(self, retrieve=False):
34
        """
35
36
        :param retrieve:
37
        :return:
38
        """
39 1
        path = API.list_all_buckets
40 1
        response = self.connector.make_request(path=path, method='post', account_id_required=True)
41 1
        if response.status_code == 200:
42 1
            response_json = response.json()
43 1
            buckets = []
44 1
            self._buckets_by_name = {}
45 1
            self._buckets_by_id = {}
46 1
            for bucket_json in response_json['buckets']:
47 1
                new_bucket = B2Bucket(connector=self.connector, parent_list=self, **bucket_json)
48 1
                buckets.append(new_bucket)
49 1
                self._buckets_by_name[bucket_json['bucketName']] = new_bucket
50 1
                self._buckets_by_id[bucket_json['bucketId']] = new_bucket
51 1
            if retrieve:
52 1
                return buckets
53
        else:
54
            raise B2Exception.parse(response)
55
56 1
    def get(self, bucket_name=None, bucket_id=None):
57
        """
58
59
        :param bucket_name:
60
        :param bucket_id:
61
        :return:
62
        """
63 1
        self._update_bucket_list()
64 1
        if bucket_name is not None:
0 ignored issues
show
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
65 1
            return self._buckets_by_name.get(bucket_name, None)
66
        else:
67
            return self._buckets_by_id.get(bucket_id, None)
68
69 1
    def create(self, bucket_name, security, configuration=None):
70
        """
71
72
        :param bucket_name:
73
        :param configuration:
74
        :return:
75
        """
76 1
        path = API.create_bucket
77 1
        if type(bucket_name) != str and type(bucket_name) != bytes:
0 ignored issues
show
introduced by
Using type() instead of isinstance() for a typecheck.
Loading history...
78
            raise B2InvalidBucketName("Bucket name must be alphanumeric or '-")
79 1
        if type(configuration) != dict and configuration is not None:
0 ignored issues
show
introduced by
Using type() instead of isinstance() for a typecheck.
Loading history...
80
            raise B2InvalidBucketConfiguration
81 1
        params = {
82
            'bucketName': bucket_name,
83
            'bucketType': security,
84
            #TODO: bucketInfo
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
85
            #TODO: corsRules
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
86
            #TODO: lifeCycleRules
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
87
        }
88 1
        response = self.connector.make_request(path=path, method='post', params=params, account_id_required=True)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (113/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
89 1
        if response.status_code == 200:
90 1
            bucket_json = response.json()
91 1
            new_bucket = B2Bucket(connector=self.connector, parent_list=self, **bucket_json)
92 1
            self._buckets_by_name[bucket_json['bucketName']] = new_bucket
93 1
            self._buckets_by_id[bucket_json['bucketId']] = new_bucket
94 1
            return new_bucket
95
        else:
96
            raise B2Exception.parse(response)
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...