Source code for api4jenkins.credential

# encoding: utf-8


from .item import AsyncItem, Item
from .mix import (AsyncConfigurationMixIn, AsyncDeletionMixIn,
                  ConfigurationMixIn, DeletionMixIn)


[docs] class Credentials(Item):
[docs] def get(self, name): for key in self.api_json(tree='domains[urlName]')['domains'].keys(): if key == name: return Domain(self.jenkins, f'{self.url}domain/{key}/') return None
[docs] def create(self, xml): self.handle_req('POST', 'createDomain', headers=self.headers, content=xml)
[docs] def iter(self): for key in self.api_json(tree='domains[urlName]')['domains'].keys(): yield Domain(self.jenkins, f'{self.url}domain/{key}/')
@property def global_domain(self): return self['_']
[docs] class Domain(Item, ConfigurationMixIn, DeletionMixIn):
[docs] def get(self, id): for item in self.api_json(tree='credentials[id]')['credentials']: if item['id'] == id: return Credential(self.jenkins, f'{self.url}credential/{id}/') return None
[docs] def create(self, xml): self.handle_req('POST', 'createCredentials', headers=self.headers, content=xml)
[docs] def iter(self): for item in self.api_json(tree='credentials[id]')['credentials']: yield Credential(self.jenkins, f'{self.url}credential/{item["id"]}/')
[docs] class Credential(Item, ConfigurationMixIn, DeletionMixIn): pass
# async class
[docs] class AsyncCredentials(AsyncItem):
[docs] async def get(self, name): data = await self.api_json(tree='domains[urlName]') for key in data['domains'].keys(): if key == name: return AsyncDomain(self.jenkins, f'{self.url}domain/{key}/') return None
[docs] async def create(self, xml): await self.handle_req('POST', 'createDomain', headers=self.headers, content=xml)
[docs] async def aiter(self): data = await self.api_json(tree='domains[urlName]') for key in data['domains'].keys(): yield Domain(self.jenkins, f'{self.url}domain/{key}/')
@property async def global_domain(self): return await self['_']
[docs] class AsyncDomain(AsyncItem, AsyncConfigurationMixIn, AsyncDeletionMixIn):
[docs] async def get(self, id): data = await self.api_json(tree='credentials[id]') for item in data['credentials']: if item['id'] == id: return AsyncCredential(self.jenkins, f'{self.url}credential/{id}/') return None
[docs] async def create(self, xml): await self.handle_req('POST', 'createCredentials', headers=self.headers, content=xml)
[docs] async def aiter(self): data = await self.api_json(tree='credentials[id]') for item in data['credentials']: yield AsyncCredential(self.jenkins, f'{self.url}credential/{item["id"]}/')
[docs] class AsyncCredential(AsyncItem, AsyncConfigurationMixIn, AsyncDeletionMixIn): pass