Skip to content

Commit

Permalink
Bitbucket: Adding getting deployment environment variables. (atlassia…
Browse files Browse the repository at this point in the history
  • Loading branch information
djgoku authored May 29, 2023
1 parent 8260416 commit e5824da
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions atlassian/bitbucket/cloud/repositories/deploymentEnvironments.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from ..base import BitbucketCloudBase

from urllib.parse import urlunsplit, urlsplit


class DeploymentEnvironments(BitbucketCloudBase):
def __init__(self, url, *args, **kwargs):
Expand Down Expand Up @@ -58,6 +60,10 @@ def __init__(self, url, data, *args, **kwargs):
super(DeploymentEnvironment, self).__init__(
url, *args, data=data, expected_type="deployment_environment", **kwargs
)
deployment_environment_url = self.get_deployment_environment_variable_url(self.url)
self.__deployment_environment_variables = DeploymentEnvironmentVariables(
"{}/variables".format(deployment_environment_url), **self._new_session_args
)

@property
def uuid(self):
Expand Down Expand Up @@ -118,3 +124,82 @@ def slug(self):
def type(self):
"""The deployment environment type"""
return self.get_data("type")

@property
def deployment_environment_variables(self):
"""The deployment environment variables"""
return self.__deployment_environment_variables

def get_deployment_environment_variable_url(self, url):
parsed_url = urlsplit(url)
path = parsed_url.path.split("/environments/")
new_path = "{}/deployments_config/environments/{}".format(path[0], path[1])
list_parsed_url = list(parsed_url[:])
list_parsed_url[2] = new_path
return urlunsplit(tuple(list_parsed_url))


class DeploymentEnvironmentVariables(BitbucketCloudBase):
def __init__(self, url, *args, **kwargs):
super(DeploymentEnvironmentVariables, self).__init__(url, *args, **kwargs)

def __get_object(self, data):
return DeploymentEnvironmentVariable(
# self.url_joiner(super().get_deployment_environment_variable_url(), data["uuid"]),
self.url,
data,
**self._new_session_args,
)

def each(self, q=None, sort=None):
"""
Returns the list of deployment environment variables in this repository.
:param q: string: Query string to narrow down the response.
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
:param sort: string: Name of a response property to sort results.
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
:return: A generator for the DeploymentEnvironmentVariable objects
API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-deployments-config-environments-environment-uuid-variables-get
"""
params = {}
if sort is not None:
params["sort"] = sort
if q is not None:
params["q"] = q
for deployment_environment_variable in self._get_paged(
None,
params=params,
):
yield self.__get_object(deployment_environment_variable)

return


class DeploymentEnvironmentVariable(BitbucketCloudBase):
def __init__(self, url, data, *args, **kwargs):
super(DeploymentEnvironmentVariable, self).__init__(
url, *args, data=data, expected_type="pipeline_variable", **kwargs
)

@property
def uuid(self):
"""The deployment environment uuid"""
return self.get_data("uuid")

@property
def secured(self):
"""The deployment environment secured"""
return self.get_data("secured")

@property
def type(self):
"""The deployment environment deployment gate enabled"""
return self.get_data("type")

@property
def value(self):
"""The deployment environment environment lock enabled"""
return self.get_data("value")

0 comments on commit e5824da

Please sign in to comment.