def pullArtifact(user, token, file, url): """Pulls the given file from the url with the provided user/token auth""" if (artifactory.ArtifactoryPath(url, auth=(user, token)).exists()): print("Pulling {file} from {url}".format(file=file, url=url)) path = artifactory.ArtifactoryPath(url, auth=(user, token)) with path.open() as fd: with open(file, "wb") as out: out.write(fd.read()) else: print("Artifact Not Found: {url}".format(url=url))
def findCompatibleArtifact(user, token, listUrl, currentVersion, filename, ext): """Searches the artifact folder to find the latest compatible artifact version""" print("Searching for Latest Compatible Artifact") compatibleSemver = None currentSemver = Semver(currentVersion) path = artifactory.ArtifactoryPath(listUrl, auth=(user, token)) # Iterate over all artifacts in the ArtifactoryPath (because path.glob was throwing exceptions on Linux systems) if (path.exists()): for artifact in path: # Only look at artifacts with the same filename and major version modelPrefix = "{filename}_v{major}".format( filename=filename, major=currentSemver.major) if modelPrefix in str(artifact): artifactSemver = Semver( str(artifact).split("_v")[1].split(ext)[0]) if (currentSemver.isBackwardCompatible(artifactSemver)) and ( (compatibleSemver is None) or (compatibleSemver < artifactSemver)): compatibleSemver = artifactSemver # Identify the latest compatible version # Raise an error if no compatible version is found if (compatibleSemver is None): raise RuntimeError(ERROR_NOT_COMPATIBLE) return "{filename}_v{version}.{ext}".format(filename=filename, version=compatibleSemver, ext=ext)
def _iter_valid_paths(ro_account, project_url): path = artifactory.ArtifactoryPath(project_url, verify=True, auth=(ro_account.username, ro_account.password)) for sub_path in path.iterdir(): if _is_good_artifactory_path(sub_path): yield sub_path
def _download_from_artifactory(fpath, tgt_path, api_key): """Download a single file from Artifactory.""" lic_file = artifactory.ArtifactoryPath(fpath, apikey=api_key) tgt_file = pathlib.Path(tgt_path, os.path.basename(fpath.strip(os.sep))) tgt_file.touch(exist_ok=True) with open(str(tgt_file), "wb") as local_lfile: with lic_file.open() as rem_lfile: rbytes = rem_lfile.read() local_lfile.write(rbytes) return tgt_file.resolve()
def pushArtifact(artifactFile, user, token, file, url, force): """Pushes the given file to the url with the provided user/token auth""" # Error and exit if artifact already exists and we are not forcing an override try: if (not force) and (artifactory.ArtifactoryPath( url, auth=(user, token)).exists()): raise RuntimeError(ERROR_ALREADY_PUSHED) except MissingSchema: pass # Rename artifact, deploy the renamed artifact, and then rename it back to original name print("Deploying {file} to {url}".format(file=file, url=url)) path = artifactory.ArtifactoryPath(url, auth=(user, token)) shutil.copyfile(artifactFile, file) try: path.deploy_file(file) os.remove(file) except: os.remove(file) raise
def _find_path(conf, project, acct): project_url = conf.base_url if not project_url.endswith("/"): project_url += "/" project_url += 'artifactory/docker-cloud-' project_url += urllib.quote(project) project_url += "-local" path = artifactory.ArtifactoryPath(project_url, verify=True, auth=(acct.username, acct.password)) if path.exists() and path.is_dir(): return path return None
def remote_fetch(self, import_spec): ''' Fetch Artifactory artifact :param import_spec: The yaml import stanza for this operation. The 'from' must specify an Artifactory path. :type argument: dict :return: The type and content of the specified artifact :rtype: tuple ''' artifactory_path = artifactory.ArtifactoryPath(import_spec['from']) extension = path.splitext(import_spec['from'])[1][1:] with artifactory_path.open() as fobj: content = fobj.read() return (artifactory_path, extension, content)
def get_latest_artifactory_build_tag(build_name, current_build_tag, api_key): """Get the latest build tag from artifactory.""" ap = artifactory.ArtifactoryPath( ARTIFACTORY_PREFIX, build_name, apikey=api_key ) build_tag_list = sorted( (str(p) for p in ap), key=lambda x: int(re.search(r"\d*$", x).group(0)) ) # The "last build" tag could actually be the same as the current build # when running in our Jenkins pipelines. # We should return the penultimate build tag if this is the case. last_build_tag = build_tag_list[-1].split("/")[-1] penultimate_tag = build_tag_list[-2].split("/")[-1] return [ last_build_tag if last_build_tag != current_build_tag else penultimate_tag ]
def check_fetch_version(check_version, ro_account, project_url): path = artifactory.ArtifactoryPath(project_url, verify=True, auth=(ro_account.username, ro_account.password)) found_path = None busted = False for sub_path in path.iterdir(): if sub_path.name != check_version: continue if not _is_good_artifactory_path(sub_path): found_path = sub_path busted = True break else: found_path = sub_path break if found_path is not None and busted: raise excp.NotFound("Version '%s' was not found as a valid subpath" " under '%s'" % (check_version, project_url)) if found_path is None: raise excp.NotFound("Version '%s' was not found under" " '%s'" % (check_version, project_url)) return VersionedPath(LooseVersion(found_path.name), found_path)
def f(uri): return artifactory.ArtifactoryPath(artifactory_server + uri, auth=artifactory_auth)
def setUp(self): self.aql = artifactory.ArtifactoryPath("http://b/artifactory")
def get_artifactory_repository(url): return artifactory.ArtifactoryPath(url, verify=False)