def create(self): """ Create object :return: None """ logger.debug( f"Create {self.__class__.__name__} [{getattr(self, self.resource_name)}]" ) self._create_and_update(self._session.put)
def delete(self): """ Remove object :return: None TODO: New entrypoint would go like /api/groups/delete and consumes ["list", "of", "groupnames"] """ logger.debug( f"Remove {self.__class__.__name__} [{getattr(self, self.resource_name)}]" ) request_url = f"{self.base_url}/{self.prefix_uri}/{self._uri_deletion}/{getattr(self, self.resource_name)}" r = self._session.delete(request_url, auth=self._auth) r.raise_for_status() rest_delay()
def delete(self): """ POST security/token/revoke revoke (calling it deletion to be consistent with other classes) a token """ logger.debug( f"Delete {self.__class__.__name__} [{getattr(self, self.resource_name)}]" ) request_url = f"{self.base_url}/{self.prefix_uri}/{self._uri}/revoke" payload = self._prepare_deletion() r = self._session.post(request_url, data=payload, auth=self._auth) r.raise_for_status() rest_delay()
def delete(self): """ Remove object :return: None """ logger.debug( f"Remove {self.__class__.__name__} [{getattr(self, self.resource_name)}]" ) request_url = f"{self.base_url}/{self.prefix_uri}/{self._uri}/{getattr(self, self.resource_name)}" r = self._session.delete( request_url, auth=self._auth, ) raise_for_status(r) rest_delay()
def create(self): """ Create object :return: None """ logger.debug( f"Create {self.__class__.__name__} [{getattr(self, self.resource_name)}]" ) data_json = self._create_json() data_json.update(self.additional_params) request_url = f"{self.base_url}/{self.prefix_uri}/{self._uri}/{getattr(self, self.resource_name)}" r = self._session.put( request_url, json=data_json, headers={"Content-Type": "application/json"}, auth=self._auth, ) r.raise_for_status() rest_delay() self.read()
def read(self): """ Read object from artifactory. Fill object if exist :return: True if object exist, False else """ logger.debug( f"Read {self.__class__.__name__} [{getattr(self, self.resource_name)}]" ) request_url = f"{self.base_url}/{self.prefix_uri}/{self._uri}/{getattr(self, self.resource_name)}" r = self._session.get(request_url, auth=self._auth) if 404 == r.status_code or 400 == r.status_code: logger.debug( f"{self.__class__.__name__} [{getattr(self, self.resource_name)}] does not exist" ) return False else: logger.debug( f"{self.__class__.__name__} [{getattr(self, self.resource_name)}] exist" ) raise_for_status(r) response = r.json() self.raw = response self._read_response(response) return True
def read(self): """ Get Tokens: GET security/token { "tokens":[ { "token_id":"<the token id>", "issuer":"<the service ID of the issuing Artifactory instance>", "subject":"<subject>", "expiry": <time when token expires as seconds since 00:00:00 1/1/1970>, "refreshable":<true | false>, "issued_at":<time issued as seconds since 00:00:00 1/1/1970>, }, ... ] } Read object from artifactory. Fill object if exist :return: True if object exist, False else """ logger.debug( f"Read {self.__class__.__name__} [{getattr(self, self.resource_name)}]" ) request_url = f"{self.base_url}/{self.prefix_uri}/{self._uri}" r = self._session.get(request_url, auth=self._auth) if 404 == r.status_code or 400 == r.status_code: logger.debug( f"{self.__class__.__name__} [{getattr(self, self.resource_name)}] does not exist" ) return False else: logger.debug( f"{self.__class__.__name__} [{getattr(self, self.resource_name)}] exist" ) r.raise_for_status() response = r.json() self.raw = response tokens = response.get("tokens") for token in tokens: key = token.pop("token_id") if key: self.tokens[key].update(token)
def list(self): """ List object from artifactory. :return: List of objects """ logger.debug(f"List {self.__class__.__name__} [{self.name}]") request_url = f"{self.base_url}/{self.prefix_uri}/{self._uri}" response = self._session.get( request_url, auth=self._auth, ) if response.status_code == 200: logger.debug( f"{self.__class__.__name__} [{self.name}] does not exist") json_response = response.json() return [item.get(self.resource_name) for item in json_response] else: logger.debug(f"{self.__class__.__name__} [{self.name}] exist") return "failed"