TruCol / Self-host-GitLab-CI-for-GitHub

Installs your own GitLab CI and runs it on all your GitHub repos, in a single command.
GNU Affero General Public License v3.0
4 stars 3 forks source link

Determine difference in two methods. #117

Closed a-t-0 closed 2 years ago

a-t-0 commented 2 years ago
a-t-0 commented 2 years ago

What is needed: Check if ssh key already works, and return "FOUND" if yes.

Then if not, ensure it is created.

Check if ssh key works, if not, raise error.

a-t-0 commented 2 years ago
# TODO: duplicate with: assert_has_push_access_to_gitlab_build_status_repo_in_github
# Run with: 
# bash -c "source src/import.sh && assert_has_push_access_to_gitlab_build_status_repo_in_github a-t-0"
assert_has_push_access_to_gitlab_build_status_repo_in_github() {
    local github_username="$1"
    local github_pwd="$2"

    # Assumes the GitLab build status repository exists in GitHub.
    # Verify if the GitLab build status repository exists in GitHub.
    assert_public_github_repository_exists "$github_username" "$GITHUB_STATUS_WEBSITE_GLOBAL"

    # Get the GitHub ssh deploy key to push and pull the GitLab build status 
    # icons to the GitHub build status repository.
    printf "\n\n\n Ensuring a ssh deploy key is to GitHub to push build status icons to your build status repository.\n\n\n."
    get_github_build_status_repo_ssh_deploy_key "example@example.com" "$GITHUB_SSH_DEPLOY_KEY_NAME" "$github_username" "$github_pwd"
    printf "\n\n\n Verifying the GitHub ssh deploy token is able to push build status icons to your build status repository.\n\n\n."
    verify_machine_has_push_access_to_gitlab_build_status_repo_in_github "$GITHUB_SSH_DEPLOY_KEY_NAME"
}
a-t-0 commented 2 years ago

Get an assert and a check out of:

assert_has_push_access_to_gitlab_build_status_repo_in_github
verify_machine_has_push_access_to_gitlab_build_status_repo_in_github
a-t-0 commented 2 years ago
local public_key_filename="$GITHUB_SSH_DEPLOY_KEY_NAME.pub"
    local private_key_filename="$GITHUB_SSH_DEPLOY_KEY_NAME"

    # Use the generation and activate functions as verifiers.
    # Assert the ssh-keys exist.
    manual_assert_file_exists "$DEFAULT_SSH_LOCATION/$public_key_filename"
    manual_assert_file_exists "$DEFAULT_SSH_LOCATION/$private_key_filename"

    # Verify the ssh-key is added to the ssh-agent.
    public_key_sha=$(get_public_key_sha_from_key_filename $GITHUB_SSH_DEPLOY_KEY_NAME)
    if [ "$(check_if_public_key_sha_is_in_ssh_agent $public_key_sha)" != "FOUND" ]; then
        echo "Error, the ssh-key should added to the ssh-agent (in ssh-add -l), however, they were not found in the ssh-agent."
        exit 10
    fi
a-t-0 commented 2 years ago
local public_key_filename="$GITHUB_SSH_DEPLOY_KEY_NAME.pub"
    local private_key_filename="$GITHUB_SSH_DEPLOY_KEY_NAME"

    # 0. Check if the ssh key file exists locally.
    if [ "$(file_exists "$DEFAULT_SSH_LOCATION/$public_key_filename")" != "FOUND" ]; then
        echo "NOTFOUND"
    fi
    if [ "$(file_exists "$DEFAULT_SSH_LOCATION/$private_key_filename")" != "FOUND" ]; then
        echo "NOTFOUND"
    fi

    # 1. Veriying the ssh-key is created and added to the ssh-agent. 
    local public_key_sha=$(get_public_key_sha_from_key_filename $GITHUB_SSH_DEPLOY_KEY_NAME)
    if [ "$(check_if_public_key_sha_is_in_ssh_agent $public_key_sha)" != "FOUND" ]; then
        echo "NOTFOUND"
    fi
a-t-0 commented 2 years ago

Got the verificfation completed.