|
| 1 | +# coding=utf-8 |
| 2 | + |
| 3 | +from requests import HTTPError |
| 4 | + |
| 5 | +from ..base import BitbucketCloudBase |
| 6 | + |
| 7 | + |
| 8 | +class RepositoryVariables(BitbucketCloudBase): |
| 9 | + def __init__(self, url, *args, **kwargs): |
| 10 | + super(RepositoryVariables, self).__init__(url, *args, **kwargs) |
| 11 | + |
| 12 | + def __get_object(self, data): |
| 13 | + return RepositoryVariable( |
| 14 | + self.url_joiner(self.url, data["uuid"]), |
| 15 | + data, |
| 16 | + **self._new_session_args, |
| 17 | + ) |
| 18 | + |
| 19 | + def each(self, q=None, sort=None): |
| 20 | + """ |
| 21 | + Returns the list of repository variables in this repository. |
| 22 | +
|
| 23 | + :param q: string: Query string to narrow down the response. |
| 24 | + See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details. |
| 25 | + :param sort: string: Name of a response property to sort results. |
| 26 | + See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details. |
| 27 | +
|
| 28 | + :return: A generator for the RepositoryVariable objects |
| 29 | +
|
| 30 | + API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pipelines_config/variables/#get |
| 31 | + """ |
| 32 | + params = {} |
| 33 | + if sort is not None: |
| 34 | + params["sort"] = sort |
| 35 | + if q is not None: |
| 36 | + params["q"] = q |
| 37 | + for pipeline_variable in self._get_paged( |
| 38 | + None, |
| 39 | + trailing=True, |
| 40 | + paging_workaround=True, |
| 41 | + params=params, |
| 42 | + ): |
| 43 | + yield self.__get_object(pipeline_variable) |
| 44 | + |
| 45 | + return |
| 46 | + |
| 47 | + def get(self, uuid): |
| 48 | + """ |
| 49 | + Returns the pipeline with the uuid in this repository. |
| 50 | +
|
| 51 | + :param uuid: string: The requested pipeline uuid |
| 52 | +
|
| 53 | + :return: The requested RepositoryVariable objects |
| 54 | +
|
| 55 | + API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pipelines_config/variables/%7Bvariable_uuid%7D#get |
| 56 | + """ |
| 57 | + return self.__get_object(super(RepositoryVariables, self).get(uuid)) |
| 58 | + |
| 59 | + |
| 60 | +class RepositoryVariable(BitbucketCloudBase): |
| 61 | + def __init__(self, url, data, *args, **kwargs): |
| 62 | + super(RepositoryVariable, self).__init__(url, *args, data=data, expected_type="pipeline_variable", **kwargs) |
| 63 | + |
| 64 | + @property |
| 65 | + def uuid(self): |
| 66 | + """The repository variable uuid""" |
| 67 | + return self.get_data("uuid") |
| 68 | + |
| 69 | + @property |
| 70 | + def key(self): |
| 71 | + """The repository variable key""" |
| 72 | + return self.get_data("key") |
| 73 | + |
| 74 | + @property |
| 75 | + def scope(self): |
| 76 | + """The repository variable scope""" |
| 77 | + return self.get_data("scope") |
| 78 | + |
| 79 | + @property |
| 80 | + def secured(self): |
| 81 | + """The repository variable secured""" |
| 82 | + return self.get_data("secured") |
| 83 | + |
| 84 | + @property |
| 85 | + def system(self): |
| 86 | + """The repository variable system""" |
| 87 | + return self.get_data("system") |
| 88 | + |
| 89 | + @property |
| 90 | + def type(self): |
| 91 | + """The repository variable type""" |
| 92 | + return self.get_data("type") |
| 93 | + |
| 94 | + @property |
| 95 | + def value(self): |
| 96 | + """The repository variable value""" |
| 97 | + return self.get_data("value") |
0 commit comments