gogoair / lavatory

Tooling to define repository specific retention policies in Artifactory.
Apache License 2.0
21 stars 14 forks source link

Gracefully proceed when user is not admin #35

Closed sijis closed 5 years ago

sijis commented 6 years ago

This attempts to address the output when lavatory is run with an account that is not contain Admin Privileges.

Account with admin access

+ lavatory -v policies
[DEBUG] lavatory.commands.policies Passed args: <click.core.Context object at 0x7f89a8d26f28>, None, (), local
[DEBUG] lavatory.utils.artifactory Storage info data: {'storageSummary': {'binariesSummary': {'binariesCount': '0', 'binariesSize': '0 bytes', 'artifactsSize': '0 bytes', 'optimization': 'N/A', 'itemsCount': '0', 'artifactsCount': '0'}, 'fileStoreSummary': {'storageType': 'file-system', 'storageDirectory': '/opt/jfrog/artifactory/data/filestore', 'totalSpace': '459.62 GB', 'usedSpace': '83.59 GB (18.19%)', 'freeSpace': '376.03 GB (81.81%)'}, 'repositoriesSummaryList': [{'repoKey': 'docker-local', 'repoType': 'LOCAL', 'foldersCount': 0, 'filesCount': 0, 'usedSpace': '0 bytes', 'itemsCount': 0, 'packageType': 'Docker', 'percentage': 'N/A'}, {'repoKey': 'auto-trashcan', 'repoType': 'NA', 'foldersCount': 0, 'filesCount': 0, 'usedSpace': '0 bytes', 'itemsCount': 0, 'packageType': 'NA', 'percentage': 'N/A'}, {'repoKey': 'docker-remote-cache', 'repoType': 'CACHE', 'foldersCount': 0, 'filesCount': 0, 'usedSpace': '0 bytes', 'itemsCount': 0, 'packageType': 'Docker', 'percentage': 'N/A'}, {'repoKey': 'bintray-docker-remote-cache', 'repoType': 'CACHE', 'foldersCount': 0, 'filesCount': 0, 'usedSpace': '0 bytes', 'itemsCount': 0, 'packageType': 'Docker', 'percentage': 'N/A'}, {'repoKey': 'docker', 'repoType': 'VIRTUAL', 'foldersCount': 0, 'filesCount': 0, 'usedSpace': '0 bytes', 'itemsCount': 0, 'packageType': 'Docker', 'percentage': 'N/A'}, {'repoKey': 'TOTAL', 'repoType': 'NA', 'foldersCount': 0, 'filesCount': 0, 'usedSpace': '0 bytes', 'itemsCount': 0}]}, 'binariesSummary': {'binariesCount': '0', 'binariesSize': '0 bytes', 'artifactsSize': '0 bytes', 'optimization': 'N/A', 'itemsCount': '0', 'artifactsCount': '0'}, 'fileStoreSummary': {'storageType': 'file-system', 'storageDirectory': '/opt/jfrog/artifactory/data/filestore', 'totalSpace': '459.62 GB', 'usedSpace': '83.59 GB (18.19%)', 'freeSpace': '376.03 GB (81.81%)'}, 'repositoriesSummaryList': [{'repoKey': 'docker-local', 'repoType': 'LOCAL', 'foldersCount': 0, 'filesCount': 0, 'usedSpace': '0 bytes', 'itemsCount': 0, 'packageType': 'Docker', 'percentage': 'N/A'}, {'repoKey': 'auto-trashcan', 'repoType': 'NA', 'foldersCount': 0, 'filesCount': 0, 'usedSpace': '0 bytes', 'itemsCount': 0, 'packageType': 'NA', 'percentage': 'N/A'}, {'repoKey': 'docker-remote-cache', 'repoType': 'CACHE', 'foldersCount': 0, 'filesCount': 0, 'usedSpace': '0 bytes', 'itemsCount': 0, 'packageType': 'Docker', 'percentage': 'N/A'}, {'repoKey': 'bintray-docker-remote-cache', 'repoType': 'CACHE', 'foldersCount': 0, 'filesCount': 0, 'usedSpace': '0 bytes', 'itemsCount': 0, 'packageType': 'Docker', 'percentage': 'N/A'}, {'repoKey': 'docker', 'repoType': 'VIRTUAL', 'foldersCount': 0, 'filesCount': 0, 'usedSpace': '0 bytes', 'itemsCount': 0, 'packageType': 'Docker', 'percentage': 'N/A'}, {'repoKey': 'TOTAL', 'repoType': 'NA', 'foldersCount': 0, 'filesCount': 0, 'usedSpace': '0 bytes', 'itemsCount': 0}]}
[DEBUG] lavatory.utils.artifactory Skipping repo auto-trashcan, not of type local
[DEBUG] lavatory.utils.artifactory Skipping repo docker-remote-cache, not of type local
[DEBUG] lavatory.utils.artifactory Skipping repo bintray-docker-remote-cache, not of type local
[DEBUG] lavatory.utils.artifactory Skipping repo docker, not of type local
[DEBUG] lavatory.utils.get_artifactory_info Storage info: {'docker-local': {'repoKey': 'docker-local', 'repoType': 'LOCAL', 'foldersCount': 0, 'filesCount': 0, 'usedSpace': '0 bytes', 'itemsCount': 0, 'packageType': 'Docker', 'percentage': 'N/A'}}
[INFO] lavatory.utils.setup_pluginbase Searching for policies in ['/home/saviles/data/git/github/lavatory/src/lavatory/utils/../policies']
[DEBUG] lavatory.utils.setup_pluginbase Policies found: ['default']
[INFO] lavatory.utils.setup_pluginbase No policy found for docker-local. Applying Default
[INFO] lavatory.commands.policies docker-local - Default Policy. Keeps the last 5 artifacts from each project
[{"repo": "docker-local", "policy_description": "Default Policy. Keeps the last 5 artifacts from each project"}]
+ lavatory stats --repo=docker
[INFO] lavatory.commands.stats Repo Name: docker.
[INFO] lavatory.commands.stats Repo Type: VIRTUAL - Docker.
[INFO] lavatory.commands.stats Repo Used Space: 0 bytes - N/A of total used space.
[INFO] lavatory.commands.stats Repo Folders 0, Files 0. Total items count: 0.
[INFO] lavatory.commands.stats -------------------------
Done.
+ lavatory purge --policies-path=/home/saviles/retention-policies/
[INFO] lavatory.utils.setup_pluginbase Searching for policies in ['/home/saviles/retention-policies/', '/home/saviles/data/git/github/lavatory/src/lavatory/utils/../policies']
[INFO] lavatory.commands.purge Applying retention policies to docker-local
[INFO] lavatory.utils.setup_pluginbase No policy found for docker-local. Applying Default
[INFO] lavatory.commands.purge Policy Docs: Default Policy. Keeps the last 5 artifacts from each project
[INFO] lavatory.utils.artifactory Searching for purgable artifacts with count based retention in docker-local.
[INFO] lavatory.utils.artifactory Running mode: DRYRUN
[INFO] lavatory.commands.purge Processed docker-local, Purged 0
[INFO] lavatory.commands.purge Purging Performance:
[INFO] lavatory.utils.performance docker-local size: 0 bytes; reduction: storage 0 bytes (0.0%), files 0 (0.0%)
[INFO] lavatory.commands.purge Success.

Account without admin access

+ lavatory -v policies
[DEBUG] lavatory.commands.policies Passed args: <click.core.Context object at 0x7f78fbb36fd0>, None, (), local
[WARNING] lavatory.utils.get_artifactory_info Account is not an admin and may not be able to get storage details.
[DEBUG] lavatory.utils.get_artifactory_info Storage info: []
[INFO] lavatory.utils.setup_pluginbase Searching for policies in ['/home/saviles/data/git/github/lavatory/src/lavatory/utils/../policies']
[DEBUG] lavatory.utils.setup_pluginbase Policies found: ['default']
[]
+ lavatory stats --repo=docker
[WARNING] lavatory.utils.get_artifactory_info Account is not an admin and may not be able to get storage details.
User does not have "Admin Privileges" to generate statistics.
+ lavatory purge --policies-path=/home/saviles/retention-policies/
[WARNING] lavatory.utils.get_artifactory_info Account is not an admin and may not be able to get storage details.
[WARNING] lavatory.utils.get_artifactory_info Account is not an admin and may not be able to get storage details.
[INFO] lavatory.utils.setup_pluginbase Searching for policies in ['/home/saviles/retention-policies/', '/home/saviles/data/git/github/lavatory/src/lavatory/utils/../policies']
[INFO] lavatory.commands.purge Applying retention policies to 
[INFO] lavatory.commands.purge User does not have "Admin Privileges" to generate performance details.
[INFO] lavatory.commands.purge Success.

This should fix and address issue #32.

sijis commented 6 years ago

I still need to address test cases.

sijis commented 5 years ago

Fixed the tests.