Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi account support | Fix #98 #137

Merged
merged 2 commits into from
May 8, 2021

Conversation

Akianonymus
Copy link
Collaborator

@Akianonymus Akianonymus commented Jan 4, 2021

Add four new flags

  • -a | --account - Use a different account than default

  • -la | --list accounts - List all the accounts configured with CLIENT_ID, CLIENT_SECRET and REFRESH_TOKEN

  • -ca | --create-account - Create a new account

  • -da | --delete-account - Delete an existing account

--list-accounts, --create-accounts and --delete-account flags can be used without any usual input required

The config format is changed, ACCOUNT_${account}_ prefix is added to every config var, where ${account} is the account name

The old configs will be automatically migrated with account name default( if default taken then a number suffix will be added like default1, default2, etc )

move authentication/config related functions to auth-utils.[bash|sh]

create more authentication functions to reduce some clutter

add a lot of error checks, minute situations like chmod failing, failing to write to config file

bash script changes: export all sub functions in their sub scripts

export variables when it is created that are needed for parallel uploads

google-oauth2.[sh|bash]: Make changes for refactored functions | Misc changes

as it is supposed to be a sample script, so don't modify default config

new flag "add" - authenticates a new user but will use the client id and secret if available. If not, then same as create flag.

@Akianonymus Akianonymus linked an issue Jan 4, 2021 that may be closed by this pull request
@Akianonymus Akianonymus changed the title Multi account support | Fix #98 [WIP] Multi account support | Fix #98 Jan 4, 2021
@Akianonymus
Copy link
Collaborator Author

This is a huge change, literally and figuratively both.

I have tested multiple scenarios to make it break free, like with no config, with config having old values, config having old and new values both, config with just new values.

This has been working so far.

After this is merged then the service accounts pull request will be updated accordingly.

@Akianonymus Akianonymus changed the title [WIP] Multi account support | Fix #98 Multi account support | Fix #98 Jan 4, 2021
@Akianonymus Akianonymus force-pushed the multi-account-support branch 3 times, most recently from 4796e60 to aa0a33e Compare January 5, 2021 10:05
labbots
labbots previously approved these changes Jan 17, 2021
@labbots
Copy link
Owner

labbots commented Apr 24, 2021

@Akianonymus is this PR safe to merge?

@Akianonymus
Copy link
Collaborator Author

Akianonymus commented Apr 28, 2021

@labbots Have to test again, it's been a while since i touched this.

Will be ready in this week probably, given no anamolies.

@Akianonymus Akianonymus force-pushed the multi-account-support branch 2 times, most recently from 3c24c68 to b6fbb3f Compare May 7, 2021 13:54
Add four new flags

* -a | --account - Use a different account than default

* -la | --list accounts - List all the accounts configured with CLIENT_ID, CLIENT_SECRET and REFRESH_TOKEN

* -ca | --create-account - Create a new account

* -da | --delete-account - Delete an existing account

--list-accounts, --create-accounts and --delete-account flags can be used without any usual input required

The config format is changed, ACCOUNT_${account}_ prefix is added to every config var, where ${account} is the account name

The old configs will be automatically migrated with account name default( if default taken then a number suffix will be added like default1, default2, etc )

move authentication/config related functions to auth-utils.[bash|sh]

create more authentication functions to reduce some clutter

add a lot of error checks, minute situations like chmod failing, failing to write to config file

bash script changes: export all sub functions in their sub scripts

export variables when it is created that are needed for parallel uploads
… changes

* as it is supposed to be a sample script, so don't modify default config

* new flag "add" - authenticates a new user but will use the client id and secret if available. If not, then same as create flag.
@Akianonymus
Copy link
Collaborator Author

@labbots This should be safe to merge now.

I have tried to test in many scenarios as possible, as mentioned in one of my previous comments in this thread, regarding config files and authentication.

For upload tests, i ran this script, which covers almost all of the uploading aspects of the script:-

#!/usr/bin/env bash

set -e

shell="${1:?Give Shell}"

cd "${shell}/release" || exit 1

LOGNAME="$((RANDOM * RANDOM))"
FILE="${LOGNAME}".testfile

trap 'exit' INT TERM
trap 'rm -rf "${FILE}"* "${LOGNAME}"* Test_gupload ; kill -- -$$' EXIT
trap '' TSTP # ignore ctrl + z

_show_log() {
    printf "%s\n" "$(< "${LOGNAME}")" && rm "${LOGNAME}"
    printf "\n"
}

# File test
printf "" >| "${FILE}"

DEFAULT_ARGS="./gupload ${FILE} -C Test_gupload --skip-internet-check"

${DEFAULT_ARGS}

${DEFAULT_ARGS} -d -r root -i "${LOGNAME}" -S
TEST_FILE_ID="$(: $(grep ID "${LOGNAME}") && printf "%s\n" "${_/ID: /}")"
_show_log

${DEFAULT_ARGS} -o -r root -i "${LOGNAME}" -S
_show_log

# Folder upload tests
mkdir -p Test_gupload/test

for i in {Test_gupload,Test_gupload/test}/{1..2}; do
    printf "%s\n" "" >| "${i}"
done

DEFAULT_FOLDER_ARGS="./gupload Test_gupload --skip-internet-check"

${DEFAULT_FOLDER_ARGS} -d -r root -i "${LOGNAME}" -S
_show_log

${DEFAULT_FOLDER_ARGS} -o -r root -i "${LOGNAME}"
_show_log

${DEFAULT_FOLDER_ARGS} -s -d -r root -i "${LOGNAME}"
_show_log

${DEFAULT_FOLDER_ARGS} -s -o -r root -i "${LOGNAME}" -S
_show_log

${DEFAULT_FOLDER_ARGS} -d -r root -i "${LOGNAME}" -p 2 -S
_show_log

${DEFAULT_FOLDER_ARGS} -o -r root -i "${LOGNAME}" -p 2
_show_log

${DEFAULT_FOLDER_ARGS} -s -d -r root -i "${LOGNAME}" -p 2
_show_log

${DEFAULT_FOLDER_ARGS} -s -o -r root -i "${LOGNAME}" -p 2 -S
_show_log

# file clone test
./gupload -C Test_gupload -cl "${TEST_FILE_ID}" -r root -i "${LOGNAME}" -S
_show_log

./gupload -C Test_gupload -cl "${TEST_FILE_ID}" -r root -i "${LOGNAME}" -d -S
_show_log

./gupload -C Test_gupload -cl "${TEST_FILE_ID}" -r root -i "${LOGNAME}" -o -S
_show_log

@Akianonymus Akianonymus self-assigned this May 7, 2021
@labbots
Copy link
Owner

labbots commented May 7, 2021

@Akianonymus I ve approved the changes. Feel free to merge whenever you are ready

@Akianonymus
Copy link
Collaborator Author

@Akianonymus I ve approved the changes. Feel free to merge whenever you are ready

image

Enable rebase and merge option, seem like it is disabled.

@labbots
Copy link
Owner

labbots commented May 8, 2021

@Akianonymus Rebase and merge is now enabled

@Akianonymus Akianonymus merged commit 1302aba into labbots:master May 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for managing multiple accounts
2 participants