Skip to content
Draft
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
50 changes: 49 additions & 1 deletion augur/application/cli/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import uuid
import traceback
import requests
import tempfile
from redis.exceptions import ConnectionError as RedisConnectionError

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pylint] reported by reviewdog 🐶
W0611: Unused ConnectionError imported from redis.exceptions as RedisConnectionError (unused-import)


from augur.tasks.start_tasks import augur_collection_monitor, create_collection_status_records
Expand All @@ -23,6 +24,8 @@
from augur.tasks.data_analysis.contributor_breadth_worker.contributor_breadth_worker import contributor_breadth_model
from augur.application.db.models import UserRepo
from augur.application.db.session import DatabaseSession
from augur.application.config import AugurConfig
from augur.application.db import get_engine
from augur.application.logs import AugurLogger
from augur.application.service_manager import AugurServiceManager, cleanup_collection_status_and_rabbit, clean_collection_status
from augur.application.db.lib import get_value
Expand All @@ -35,6 +38,48 @@

logger = AugurLogger("augur", reset_logfiles=reset_logs).get_logger()

def create_git_credential_file(github_key, gitlab_key):
if 'AUGUR_GITHUB_USERNAME' in os.environ:
print("Found AUGUR_GITHUB_USERNAME env variable")
github_username = os.environ.get("AUGUR_GITHUB_USERNAME")
else:
github_username = input("Please input your GitHub username")

if 'AUGUR_GITLAB_USERNAME' in os.environ:
print("Found AUGUR_GITLAB_USERNAME env variable")
gitlab_username = os.environ.get("AUGUR_GITLAB_USERNAME")
else:
gitlab_username = input("Please input your GitLab username")


engine = get_engine()
with DatabaseSession(logger, engine) as session:
config = AugurConfig(logger, session)

worker_options = config.get_section("Facade")
repo_base_directory = worker_options['repo_directory']

credential_file_text = f"""
https://{github_username}:{github_key}@github.com
https://{gitlab_username}:{gitlab_key}@gitlab.com
"""

link_path = f"{repo_base_directory}/.git-credentials"
fd, temp_path = tempfile.mkstemp(prefix="myapp_", suffix=".tmp")
with os.fdopen(fd, "w") as f:
f.write(credential_file_text)

# Create a temporary symlink
tmp_link = link_path + ".new"
os.symlink(temp_path, tmp_link)
# Atomically swap it into place
os.replace(tmp_link, link_path)

facade_credential_store = f"git config --global credential.helper \"store --file {repo_base_directory}/.git-credentials\""
subprocess.Popen(facade_credential_store.split(" "))

Check notice

Code scanning / Bandit

subprocess call - check for execution of untrusted input. Note

subprocess call - check for execution of untrusted input.



@click.group('server', short_help='Commands for controlling the backend API server & data collection workers')
@click.pass_context
def cli(ctx):
Expand Down Expand Up @@ -168,7 +213,10 @@ def start(ctx, disable_collection, development, pidfile, port):

clean_collection_status(session)
assign_orphan_repos_to_default_user(session)


#Create git credentials file and store git credentials
create_git_credential_file(ghkeyman.keys[0], glkeyman.keys[0])

create_collection_status_records.si().apply_async()
time.sleep(3)

Expand Down
10 changes: 5 additions & 5 deletions scripts/install/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ function create_config() {
fi

#Create and cache credentials for github and gitlab
touch $facade_repo_directory/.git-credentials
#touch $facade_repo_directory/.git-credentials

echo "https://$github_username:$github_api_key@github.com" > $facade_repo_directory/.git-credentials
echo "https://$gitlab_username:$gitlab_api_key@gitlab.com" >> $facade_repo_directory/.git-credentials
#echo "https://$github_username:$github_api_key@github.com" > $facade_repo_directory/.git-credentials
#echo "https://$gitlab_username:$gitlab_api_key@gitlab.com" >> $facade_repo_directory/.git-credentials

git config --global credential.helper "store --file $facade_repo_directory/.git-credentials"
"${cmd[@]}"
#git config --global credential.helper "store --file $facade_repo_directory/.git-credentials"
#"${cmd[@]}"
}
echo
echo "Collecting data for config..."
Expand Down
Loading