Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3-bookworm

RUN mkdir /opt/app
WORKDIR /opt/app

# Have to use older pyyaml than the container provides
# https://github.com/yaml/pyyaml/issues/601#issuecomment-1693730229
# it's even more fun, because python dependencies are a nightmare.
RUN pip install "Cython<3.0" pyyaml==5.4.1 --no-build-isolation \
&& pip install requests

COPY . /opt/app
RUN python3 scripts/dev_setup.py \
&& mkdir /srv/mvnfeed_stage \
&& mvnfeed -h


# configuration file is at ~/.mvnfeed/mvnfeed.ini

ENTRYPOINT ["/usr/local/bin/mvnfeed"]
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
REPOSITORY = 'repository.'
URL = 'url'
AUTHORIZATION = 'authorization'
AUTH_HEADER = 'auth_header'
AUTH_VALUE = 'auth_value'


def _get_config_dir():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import base64
import getpass

from mvnfeed.cli.common.config import REPOSITORY, AUTHORIZATION, URL, repo_section_name, load_config, save_config
from mvnfeed.cli.common.config import REPOSITORY, AUTHORIZATION, URL, AUTH_HEADER, AUTH_VALUE, repo_section_name, load_config, save_config

STAGE_DIR_CONFIGNAME = 'stage_dir'

Expand Down Expand Up @@ -36,27 +36,32 @@ def view_stagedir():
return config.get('general', STAGE_DIR_CONFIGNAME)


def add_repository(name, username, url=None):
def add_repository(name, username=None, url=None, auth_header=None, auth_value=None):
"""
Adds an external Maven repository.

:param name: internal name of the repository
:param username: name of the user for the basic authentication to the repository
:param url: url of the repository
:param auth_header: name of an auth header
:param auth_value: value in that auth header
"""
if username is None:
raise ValueError('Username must be defined')
if url is None:
raise ValueError('Url must be defined')

password = getpass.getpass()
encoded = base64.b64encode((username + ':' + password).encode('utf-8'))
authorization = 'Basic ' + encoded.decode('utf-8')
if username is not None:
password = getpass.getpass()
encoded = base64.b64encode((username + ':' + password).encode('utf-8'))
authorization = 'Basic ' + encoded.decode('utf-8')
else:
authorization = None

config = load_config()
config[repo_section_name(name)] = {
URL: _default_value(url),
AUTHORIZATION: _default_value(authorization)
AUTHORIZATION: _default_value(authorization),
AUTH_HEADER: _default_value(auth_header),
AUTH_VALUE: _default_value(auth_value)
}
save_config(config)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Python 2
from urllib2 import Request, urlopen
from .configuration import get_repository, get_stagedir, get_repository_shortname
from mvnfeed.cli.common.config import AUTHORIZATION, URL, load_config
from mvnfeed.cli.common.config import AUTHORIZATION, URL, AUTH_HEADER, AUTH_VALUE, load_config


def transfer_artifact(name, from_repo, to_repo, transfer_deps=False):
Expand Down Expand Up @@ -261,6 +261,9 @@ def _download_file(from_repository, path, filename, length=16*1024):
if AUTHORIZATION in from_repository and from_repository[AUTHORIZATION]:
logging.debug('authorization header added')
request.add_header('Authorization', from_repository[AUTHORIZATION])
elif AUTH_HEADER in from_repository and from_repository[AUTH_HEADER]:
logging.debug('custom auth header added')
request.add_header(from_repository[AUTH_HEADER], from_repository[AUTH_VALUE])
else:
logging.debug('no authorization configured')

Expand All @@ -283,6 +286,9 @@ def _already_uploaded(to_repository, path):
if AUTHORIZATION in to_repository and to_repository[AUTHORIZATION]:
logging.debug('authorization header added')
headers = {'Authorization': to_repository[AUTHORIZATION]}
elif AUTH_HEADER in to_repository and to_repository[AUTH_HEADER]:
logging.debug('custom auth header added')
headers = {to_repository[AUTH_HEADER]: to_repository[AUTH_VALUE]}
else:
logging.debug('no authorization configured')
headers = {}
Expand Down Expand Up @@ -313,13 +319,15 @@ def _upload_file(to_repository, path, filename):
if AUTHORIZATION in to_repository and to_repository[AUTHORIZATION]:
logging.debug('authorization header added')
headers = {'Authorization': to_repository[AUTHORIZATION]}
elif AUTH_HEADER in to_repository and to_repository[AUTH_HEADER]:
logging.debug('custom auth header added')
headers = {to_repository[AUTH_HEADER]: to_repository[AUTH_VALUE]}
else:
logging.debug('no authorization configured')
headers = {}

try:
with open(filename, 'rb') as file:
response = requests.put(url, files={filename: file}, headers=headers)
response = requests.put(url, data=file, headers=headers)
if not response.ok:
logging.error('error while uploading of %s: %s', path, response.text)
return True
Expand Down