Exemple #1
0
    def test_unlink(self):
        """
        Test that folder/file unlink works
        """
        path = ArtifactoryPath(
            "http://artifactory.local/artifactory/ext-release-local/org/company/tool/1.0/tool-1.0.tar.gz"
        )
        constructed_url = (
            "http://artifactory.local/artifactory"
            "/api/storage"
            "/ext-release-local/org/company/tool/1.0/tool-1.0.tar.gz")
        responses.add(
            responses.GET,
            constructed_url,
            status=200,
            json=self.file_stat,
        )

        responses.add(
            responses.DELETE,
            str(path),
            status=200,
        )

        path.unlink()
Exemple #2
0
    def test_unlink_raises_on_404(self):
        """
        Test that folder/file unlink raises exception if we checked that file
        exsists and we still get 404. This is a result of permission issue
        """
        path = ArtifactoryPath(
            "http://artifactory.local/artifactory/ext-release-local/org/company/tool/1.0/tool-1.0.tar.gz"
        )
        constructed_url = (
            "http://artifactory.local/artifactory"
            "/api/storage"
            "/ext-release-local/org/company/tool/1.0/tool-1.0.tar.gz")
        responses.add(
            responses.GET,
            constructed_url,
            status=200,
            json=self.file_stat,
        )

        responses.add(
            responses.DELETE,
            str(path),
            status=404,
        )

        with self.assertRaises(ArtifactoryException) as context:
            path.unlink()

        self.assertTrue(
            "insufficient Artifactory privileges" in str(context.exception))
def delete_old_artifacts(list_of_artifacts, chart_name):
    """Extract list of artifacts for this chart and only keep the last NUMBER_OF_CHARTS versions uploaded"""
    artifacts = list(filter(lambda x: chart_name == x[0], list_of_artifacts))
    if len(artifacts) < NUMBER_OF_CHARTS:
        return
    artifacts.sort(key=lambda date: time.strptime(date[1], '%d-%b-%Y %H:%M'))
    for artifact in artifacts[:-(NUMBER_OF_CHARTS + 1)]:
        artifact_path = ArtifactoryPath(
            full_artifactory_url + artifact[2],
            auth=credentials,
        )
        if artifact_path.exists():
            print("Deleting artifact " + artifact[2])
            artifact_path.unlink()
Exemple #4
0
    def test_unlink_raises_not_found(self):
        """
        Test that folder/file unlink raises OSError if file does not exist
        """
        path = ArtifactoryPath(
            "http://artifactory.local/artifactory/ext-release-local/org/company/tool/1.0/tool-1.0.tar.gz"
        )
        constructed_url = (
            "http://artifactory.local/artifactory"
            "/api/storage"
            "/ext-release-local/org/company/tool/1.0/tool-1.0.tar.gz")
        responses.add(
            responses.GET,
            constructed_url,
            status=404,
            body="Unable to find item",
        )
        with self.assertRaises(OSError) as context:
            path.unlink()

        self.assertTrue(
            "No such file or directory" in context.exception.strerror)
Exemple #5
0
import os
from artifactory import ArtifactoryPath

JF_USER = os.environ['JF_USER']
JF_USER_TOKEN = os.environ['JF_USER_TOKEN']
ARTIFACT_TO_REMOVE = os.environ['ARTIFACT_TO_REMOVE']

path = ArtifactoryPath(ARTIFACT_TO_REMOVE, auth=(JF_USER, JF_USER_TOKEN))

if path.exists():
    path.unlink()
Exemple #6
0
def delete_artifact(artifact_url):
    url = ArtifactoryPath(artifact_url, apikey=api_key)
    if url.exists():
        url.unlink()
Exemple #7
0
print("Processing list....")
for item in artifacts_list:
    file_args = aql_search.file_search(repo, path, item["name"], days)
    file_list = aql.aql(*file_args)
    flag = aql_search.check_file_list(file_list, days)
    if flag:
        continue
    for file in file_list:
        file_url = art_url + file['repo'] + "/" + file['path'] + "/" + file[
            'name']
        full_path = ArtifactoryPath(file_url, apikey=art_apikey)
        total_file_count += 1
        if delete:
            if full_path.exists():
                log_msg = "deleting: " + file_url
                full_path.unlink()
        else:
            log_msg = "dry run: " + file_url
            if 'downloaded' in file['stats'][0]:
                log_msg += "\n Last downloaded: " + file['stats'][0][
                    'downloaded']

        log_file.write(log_msg + "\n")

        if verbose:
            print(log_msg)

run_stop = timeit.default_timer()
running_time = run_stop - run_start
log_msg_total = "   # packages: " + str(
    len(artifacts_list)) + "\n   # files:    " + str(