Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Default is localhost.
host = 'localhost'
owner = self.creator.email.split('@')[0] if self.creator else 'NULL'
name = self.name
if self.client:
remote = self.client.remote
host = self.client.remote.get('host') or host
owner = remote.get('owner') or owner
name = remote.get('name') or name
host = os.environ.get('RENKU_DOMAIN') or host
if name:
name = urllib.parse.quote(name, safe='')
project_url = urllib.parse.urljoin(
'https://{host}'.format(host=host),
pathlib.posixpath.join(PROJECT_URL_PATH, owner, name or 'NULL')
)
return project_url
def check_dataverse_uri(url):
"""Check if an URL points to a dataverse instance."""
url_parts = list(urlparse.urlparse(url))
url_parts[2] = pathlib.posixpath.join(
DATAVERSE_API_PATH, DATAVERSE_VERSION_API
)
url_parts[3:6] = [''] * 3
version_url = urlparse.urlunparse(url_parts)
response = requests.get(version_url)
if response.status_code != 200:
return False
version_data = response.json()
if 'status' not in version_data or 'data' not in version_data:
return False
version_info = version_data['data']
def publish_url(self):
"""Returns publish URL."""
url = urllib.parse.urljoin(
self.exporter.zenodo_url,
pathlib.posixpath.join(
ZENODO_API_PATH, ZENODO_DEPOSIT_PATH,
ZENODO_PUBLISH_ACTION_PATH.format(self.id)
)
)
return url
from urllib.parse import quote
super().__attrs_post_init__()
# Determine the hostname for the resource URIs.
# If RENKU_DOMAIN is set, it overrides the host from remote.
# Default is localhost.
host = 'localhost'
if self.client:
host = self.client.remote.get('host') or host
host = os.environ.get('RENKU_DOMAIN') or host
# always set the id by the identifier
self._id = urllib.parse.urljoin(
'https://{host}'.format(host=host),
pathlib.posixpath.join(
'/datasets', quote(self.identifier, safe='')
)
)
# if `date_published` is set, we are probably dealing with
# an imported dataset so `created` is not needed
if self.date_published:
self.created = None
self._label = self.identifier
if not self.path:
self.path = str(
self.client.renku_datasets_path /
quote(str(self.uid), safe='')
)
def generate_id(cls, commit):
"""Calculate action ID."""
host = os.environ.get('RENKU_DOMAIN') or 'localhost'
# always set the id by the identifier
return urllib.parse.urljoin(
'https://{host}'.format(host=host),
posixpath.join(
'/activities', 'commit/{commit.hexsha}'.format(commit=commit)
)
def make_records_url(record_id, base_url):
"""Create URL to access record by ID."""
url_parts = list(urlparse.urlparse(base_url))
url_parts[2] = pathlib.posixpath.join(
DATAVERSE_API_PATH, DATAVERSE_METADATA_API
)
args_dict = {'exporter': DATAVERSE_EXPORTER, 'persistentId': record_id}
url_parts[4] = urllib.parse.urlencode(args_dict)
return urllib.parse.urlunparse(url_parts)
def make_records_url(record_id):
"""Create URL to access record by ID."""
return urllib.parse.urljoin(
ZENODO_BASE_URL,
pathlib.posixpath.join(ZENODO_API_PATH, 'records', record_id)
)
def attach_metadata_url(self):
"""Return URL for attaching metadata."""
url = urllib.parse.urljoin(
self.exporter.zenodo_url,
pathlib.posixpath.join(
ZENODO_API_PATH, ZENODO_DEPOSIT_PATH,
ZENODO_METADATA_URL.format(self.id)
)
)
return url