Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
team = self.tower.create_team_in_organization('Default',
'team_name',
'description')
self.assertIsInstance(team, Team)
duplicate_team = self.tower.create_team_in_organization('Default',
'team_name',
'description2')
self.assertFalse(duplicate_team)
with self.assertRaises(InvalidOrganization):
self.tower.create_team_in_organization('DefaultBroken',
'team_name',
'description2')
self.assertTrue(self.tower.delete_team_in_organization('Default', 'team_name'))
with self.assertRaises(InvalidOrganization):
self.tower.delete_team_in_organization('DefaultBroken', 'team_name')
with self.assertRaises(InvalidTeam):
self.tower.delete_team_in_organization('Default', 'team_name')
self.tower.create_credential_in_organization_with_type_id('BrokenOrg',
'CredName2',
'CredDescription',
'workflow_admin',
'workflow_team',
'Source Control',
'{}')
with self.assertRaises(InvalidUser):
self.tower.create_credential_in_organization_with_type_id('workflow',
'CredName2',
'CredDescription',
'workflow_adminBroken',
'workflow_team',
'Source Control',
'{}')
with self.assertRaises(InvalidTeam):
self.tower.create_credential_in_organization_with_type_id('workflow',
'CredName2',
'CredDescription',
'workflow_admin',
'workflow_teamBroken',
'Source Control',
'{}')
with self.assertRaises(InvalidVariables):
self.tower.create_credential_in_organization_with_type_id('workflow',
'CredName2',
'CredDescription',
'workflow_admin',
'workflow_team',
'Source Control',
'garbage')
credential_with_type_id = self.tower.create_credential_in_organization_with_type_id('workflow',
__license__ = '''MIT'''
__maintainer__ = '''Costas Tyfoxylos'''
__email__ = ''''''
__status__ = '''Development''' # "Prototype", "Development", "Production".
# This is to 'use' the module(s), so lint doesn't complain
assert __version__
# assert exceptions
assert AuthFailed
assert InvalidUserLevel
assert InvalidOrganization
assert InvalidVariables
assert InvalidInventory
assert InvalidUser
assert InvalidTeam
assert InvalidCredential
assert InvalidGroup
assert InvalidHost
assert InvalidProject
assert InvalidCredentialType
assert InvalidPlaybook
assert InvalidInstanceGroup
assert InvalidJobType
assert InvalidVerbosity
assert InvalidJobTemplate
assert PermissionNotFound
assert InvalidValue
assert InvalidRole
# assert objects
assert Tower
def delete_team(self, name):
"""Deletes a team by name.
Args:
name: The name of the team to delete.
Returns:
bool: True on success, False otherwise.
Raises:
InvalidTeam: The team provided as argument does not exist.
"""
team = self.get_team_by_name(name)
if not team:
raise InvalidTeam(name)
return team.delete()
"""Deletes a team from tower.
Args:
organization: The name of the organization the team belongs to.
name: The name of the team to delete.
Returns:
bool: True on success, False otherwise.
Raises:
InvalidTeam: The team provided as argument does not exist.
"""
team = self.get_organization_team_by_name(organization, name)
if not team:
raise InvalidTeam(team)
return team.delete()
Raises:
InvalidOrganization: The organization provided as argument does not exist.
InvalidUser: The user provided as argument does not exist.
InvalidTeam: The team provided as argument does not exist.
InvalidVariables: The inputs provided as argument is not valid json.
"""
organization_ = self.get_organization_by_name(organization)
if not organization_:
raise InvalidOrganization(organization)
user_ = self.get_user_by_username(user)
if not user_:
raise InvalidUser(user)
team_ = organization_.get_team_by_name(team)
if not team_:
raise InvalidTeam(team)
payload = {'name': name,
'description': description,
'organization': organization_.id,
'user': user_.id,
'team': team_.id,
'credential_type': credential_type_id}
if not validate_json(inputs_):
raise InvalidVariables(inputs_)
payload['inputs'] = json.loads(inputs_)
url = '{api}/credentials/'.format(api=self.api)
response = self.session.post(url, json=payload)
if not response.ok:
self._logger.error('Error creating credential "%s", response was: "%s"', name, response.text)
return Credential(self, response.json()) if response.ok else None
InvalidOrganization: The organization provided as argument does not exist.
InvalidUser: The user provided as argument does not exist.
InvalidTeam: The team provided as argument does not exist.
InvalidCredentialType: The credential type provided as argument does not exist.
InvalidVariables: The inputs provided as argument is not valid json.
"""
organization_ = self.get_organization_by_name(organization)
if not organization_:
raise InvalidOrganization(organization)
user_ = self.get_user_by_username(user)
if not user_:
raise InvalidUser(user)
team_ = organization_.get_team_by_name(team)
if not team_:
raise InvalidTeam(team)
credential_type_ = self.get_credential_type_by_name(credential_type)
if not credential_type_:
raise InvalidCredentialType(credential_type)
if not validate_json(inputs_):
raise InvalidVariables(inputs_)
return self.create_credential_with_credential_type_id(name,
credential_type_.id,
description=description,
user_id=user_.id,
team_id=team_.id,
organization_id=organization_.id,
inputs=inputs_
)