def regenerate_api_key(self) -> ApiKeyModel: """ Regenerate an API key for the current user :return: API key """ response = self._put(f"api/{self._uri}/apiKey") logger.debug("API Key successfully regenerated") return ApiKeyModel(**response.json())
def get_api_key(self) -> ApiKeyModel: """ Get the current user's own API key :return: API key """ response = self._get(f"api/{self._uri}/apiKey") logger.debug("API Key successfully delivered") return ApiKeyModel(**response.json())
def create_api_key(self) -> ApiKeyModel: """ Create an API key for the current user. :return: Error if API key already exists - use regenerate API key instead. """ response = self._post(f"api/{self._uri}/apiKey") logger.debug("API Key successfully created") return ApiKeyModel(**response.json())
import responses from pyartifactory import ArtifactorySecurity from pyartifactory.models import AuthModel, PasswordModel, ApiKeyModel URL = "http://localhost:8080/artifactory" AUTH = ("user", "password_or_apiKey") PASSWORD = PasswordModel(password="******") API_KEY = ApiKeyModel(apiKey="test_api_key") class TestSecurity: @staticmethod @responses.activate def test_get_encrypted_password(): data = PASSWORD.dict() data["password"] = PASSWORD.password.get_secret_value() responses.add( responses.GET, f"{URL}/api/security/encryptedPassword", json=data, status=200, ) artifactory_security = ArtifactorySecurity( AuthModel(url=URL, auth=AUTH)) enc_pass = artifactory_security.get_encrypted_password() assert (enc_pass.password.get_secret_value() == PASSWORD.password.get_secret_value()) @staticmethod