Compare commits
	
		
			No commits in common. "6c6df42e7f70950e73515c545d1cb64a836a3a5d" and "e0de805af758c4ea4e7479d9850e94b2cb60a8f3" have entirely different histories.
		
	
	
		
			6c6df42e7f
			...
			e0de805af7
		
	
		
| @ -7,7 +7,6 @@ import requests | |||||||
| from time import sleep | from time import sleep | ||||||
| 
 | 
 | ||||||
| from mgrctl.settings.api import ( | from mgrctl.settings.api import ( | ||||||
|     API_INPUT_PORT, |  | ||||||
|     API_URL, |     API_URL, | ||||||
|     API_HEADERS, |     API_HEADERS, | ||||||
|     API_EMAIL, |     API_EMAIL, | ||||||
| @ -15,7 +14,6 @@ from mgrctl.settings.api import ( | |||||||
|     API_VERIFY_SSL, |     API_VERIFY_SSL, | ||||||
|     API_COUNT_TRY_CONNECTIONS |     API_COUNT_TRY_CONNECTIONS | ||||||
| ) | ) | ||||||
| from mgrctl.settings.platform import PLATFORM_TYPE |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class BaseAPI(object): | class BaseAPI(object): | ||||||
| @ -35,7 +33,6 @@ class BaseAPI(object): | |||||||
|     def call_api(self, url, method='GET', headers={}, data={}): |     def call_api(self, url, method='GET', headers={}, data={}): | ||||||
|         attempt = API_COUNT_TRY_CONNECTIONS |         attempt = API_COUNT_TRY_CONNECTIONS | ||||||
|         while attempt: |         while attempt: | ||||||
|             attempt -= 1 |  | ||||||
|             try: |             try: | ||||||
|                 uri = self._gen_request_url(url) |                 uri = self._gen_request_url(url) | ||||||
|                 headers = self.API_HEADERS if not headers else headers |                 headers = self.API_HEADERS if not headers else headers | ||||||
| @ -55,17 +52,6 @@ class BaseAPI(object): | |||||||
|                         verify=self.API_VERIFY_SSL |                         verify=self.API_VERIFY_SSL | ||||||
|                     ) |                     ) | ||||||
|             except Exception as error: |             except Exception as error: | ||||||
|                 ConnectionError = requests.exceptions.ConnectionError |  | ||||||
|                 if type(error) is ConnectionError and PLATFORM_TYPE == 'dci': |  | ||||||
|                     # ? workaround if new docker version use dashes |  | ||||||
|                     # TODO: ISPsystem developers must set container_name !!! |  | ||||||
|                     self.API_URL = f'http://dci-input-1:{API_INPUT_PORT}' |  | ||||||
|                     if attempt == 0: |  | ||||||
|                         click.echo(f'Error: {type(error).__name__}') |  | ||||||
|                         sys.exit() |  | ||||||
|                     else: |  | ||||||
|                         continue |  | ||||||
|                 else: |  | ||||||
|                 click.echo(f'Error: {type(error).__name__}') |                 click.echo(f'Error: {type(error).__name__}') | ||||||
|                 sys.exit() |                 sys.exit() | ||||||
| 
 | 
 | ||||||
| @ -74,6 +60,8 @@ class BaseAPI(object): | |||||||
| 
 | 
 | ||||||
|             # Validate response: |             # Validate response: | ||||||
|             if self._error_handler(response): |             if self._error_handler(response): | ||||||
|  |                 attempt -= 1 | ||||||
|  |                 sleep(2)  # wait 2 second timeout | ||||||
|                 continue  # new attempt connection |                 continue  # new attempt connection | ||||||
| 
 | 
 | ||||||
|             return response |             return response | ||||||
| @ -92,7 +80,6 @@ class BaseAPI(object): | |||||||
| 
 | 
 | ||||||
|     def _is_error_3004(self, error): |     def _is_error_3004(self, error): | ||||||
|         if error.get('code') == 3004: |         if error.get('code') == 3004: | ||||||
|             sleep(2)  # wait 2 second timeout |  | ||||||
|             return True |             return True | ||||||
| 
 | 
 | ||||||
|     def _error_handler(self, response): |     def _error_handler(self, response): | ||||||
|  | |||||||
| @ -6,7 +6,7 @@ | |||||||
| 
 | 
 | ||||||
| # INIT GLOBAL VARIABLES: | # INIT GLOBAL VARIABLES: | ||||||
| _VERSION="0.1.0" | _VERSION="0.1.0" | ||||||
| _SCRIPT_NAME="$(basename $0)" | _SCRIPT_NAME="$0" | ||||||
| _GO_CMD="go3" | _GO_CMD="go3" | ||||||
| _DEBUG_MODE=false | _DEBUG_MODE=false | ||||||
| 
 | 
 | ||||||
| @ -65,21 +65,20 @@ help() { | |||||||
| 	printf "                                                              \n" | 	printf "                                                              \n" | ||||||
| 	printf "Examples:                                                     \n" | 	printf "Examples:                                                     \n" | ||||||
| 	printf "                                                              \n" | 	printf "                                                              \n" | ||||||
| 	printf "${script} --init | init config file                           \n" | 	printf "./gogo.sh --init | init config file                           \n" | ||||||
| 	printf "${script} --crt  | get ssh certificate for go3 connections    \n" | 	printf "./gogo.sh --crt  | get ssh certificate for go3 connections    \n" | ||||||
| 	printf "                                                              \n" | 	printf "                                                              \n" | ||||||
| 	printf "${script} --bill my.example.com                               \n" | 	printf "./gogo.sh --bill my.example.com                               \n" | ||||||
| 	printf "${script} --vm 0.0.0.0 --ssh | only ssh access                \n" | 	printf "./gogo.sh --vm 0.0.0.0 --ssh | only ssh access                \n" | ||||||
| 	printf "${script} --vm 0.0.0.0 --tty | use mgrctl interactive         \n" | 	printf "./gogo.sh --vm 0.0.0.0 --tty | use mgrctl interactive         \n" | ||||||
| 	printf "                                                              \n" | 	printf "                                                              \n" | ||||||
| 	printf "${script} --dci 0.0.0.0 --mgrctl user access --id 3 --count 5 \n" | 	printf "./gogo.sh --dci 0.0.0.0 --mgrctl user access --id 3 --count 5 \n" | ||||||
| 	printf "${script} --dci 0.0.0.0 --mgrctl user ls --admins             \n" | 	printf "./gogo.sh --dci 0.0.0.0 --mgrctl user ls --admins             \n" | ||||||
| 	printf "${script} --dci 0.0.0.0 --mgrctl user --help                  \n" | 	printf "./gogo.sh --dci 0.0.0.0 --mgrctl user --help                  \n" | ||||||
| 	printf "${script} --vm 0.0.0.0 --port 22122 --mgrctl user ls --admins \n" | 	printf "./gogo.sh --vm 0.0.0.0 --port 22122 --mgrctl user ls --admins \n" | ||||||
| 	printf "${script} --vm 0.0.0.0 --tty --mgrctl user ls --admins        \n" | 	printf "./gogo.sh --dns ns1.example.com --web-port 1501               \n" | ||||||
| 	printf "${script} --dns ns1.example.com --web-port 1501               \n" | 	printf "./gogo.sh --dns ns1.example.com --port 22122 --web-port 1501  \n" | ||||||
| 	printf "${script} --dns ns1.example.com --port 22122 --web-port 1501  \n" | 	printf "./gogo.sh --bill my.example.com --port 22 --web-port 1501     \n" | ||||||
| 	printf "${script} --bill my.example.com --port 22 --web-port 1501     \n" |  | ||||||
| 	printf "                                                              \n" | 	printf "                                                              \n" | ||||||
| 	printf "Options:                                                      \n" | 	printf "Options:                                                      \n" | ||||||
| 	printf "                                                              \n" | 	printf "                                                              \n" | ||||||
| @ -87,7 +86,6 @@ help() { | |||||||
| 	printf " --port     | -p       ssh port,   default 22                 \n" | 	printf " --port     | -p       ssh port,   default 22                 \n" | ||||||
| 	printf " --web-port | -wp      web port,   default 443                \n" | 	printf " --web-port | -wp      web port,   default 443                \n" | ||||||
| 	printf " --go/--go3            go version, default go3                \n" | 	printf " --go/--go3            go version, default go3                \n" | ||||||
| 	printf " --ssh                 open only ssh session                  \n" |  | ||||||
| 	printf " --tty                 for vm6/dci6 echo cmd for run container\n" | 	printf " --tty                 for vm6/dci6 echo cmd for run container\n" | ||||||
| 	printf " --mgrctl [args]       for vm6/dci6 customize access params   \n" | 	printf " --mgrctl [args]       for vm6/dci6 customize access params   \n" | ||||||
| 	printf "                                                              \n" | 	printf "                                                              \n" | ||||||
| @ -106,12 +104,12 @@ continue_handler() { | |||||||
| # Init script configuration file: | # Init script configuration file: | ||||||
| init_config() { | init_config() { | ||||||
| 	# Lables: | 	# Lables: | ||||||
| 	local warning=$(colorize RED "WARNING!") | 	local warning=$(colorize RED "WARNING! ") | ||||||
| 	local success=$(colorize GREEN "SUCCESS!") | 	local success=$(colorize GREEN "SUCCESS! ") | ||||||
| 	local script_name=$(colorize GREEN "${_SCRIPT_NAME}") | 	local script_name=$(colorize GREEN "${_SCRIPT_NAME}") | ||||||
| 	# check if config file exists: | 	# check if config file exists: | ||||||
| 	if [ -f $_CONFIG ]; then | 	if [ -f $_CONFIG ]; then | ||||||
| 		echo "${warning} Config file is already exists" | 		echo "${warning}: Config file is already exists" | ||||||
| 		echo "New initialization rewrites current config" | 		echo "New initialization rewrites current config" | ||||||
| 		continue_handler | 		continue_handler | ||||||
| 	fi | 	fi | ||||||
| @ -135,9 +133,7 @@ SSH_CRT_FILE=$_SSH_CRT_FILE | |||||||
| MGRCTL_IMAGE=$_MGRCTL_IMAGE | MGRCTL_IMAGE=$_MGRCTL_IMAGE | ||||||
| DEBUG_MODE=false | DEBUG_MODE=false | ||||||
| EOF | EOF | ||||||
| 	echo "" | 	echo "${success}: Config file was created, run ${script_name} again" | ||||||
| 	echo "${success} Config file was created, run ${script_name} again" |  | ||||||
| 	echo "" |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -377,7 +373,7 @@ set_ssh_agent() { | |||||||
| renewal_crt() { | renewal_crt() { | ||||||
| 	export VAULT_ADDR=$_VAULT_SERVER_ADDR | 	export VAULT_ADDR=$_VAULT_SERVER_ADDR | ||||||
| 	get_vault_crt $_VAULT_SSH_PUBLIC_KEY $_SSH_CRT_FILE | 	get_vault_crt $_VAULT_SSH_PUBLIC_KEY $_SSH_CRT_FILE | ||||||
| 	set_ssh_agent $_SSH_PRIVATE_KEY_PATH | 	set_ssh_agent $SSH_PRIVATE_KEY_PATH | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -390,13 +386,6 @@ optparser() { | |||||||
| 		help | 		help | ||||||
| 		exit 2 | 		exit 2 | ||||||
| 	fi | 	fi | ||||||
| 	# run init config if flag --init and exit: |  | ||||||
| 	if [[ "$1" == "--init" ]]; then |  | ||||||
| 		init_config |  | ||||||
| 		exit 0 |  | ||||||
| 	fi |  | ||||||
| 	# load config from config file: |  | ||||||
| 	load_config |  | ||||||
| 	# parse opts: | 	# parse opts: | ||||||
| 	while [ ! -z "$1" ]; do | 	while [ ! -z "$1" ]; do | ||||||
| 		case "$1" in | 		case "$1" in | ||||||
| @ -437,6 +426,10 @@ optparser() { | |||||||
| 					_IS_SSH_ONLY=true | 					_IS_SSH_ONLY=true | ||||||
| 				fi | 				fi | ||||||
| 				;; | 				;; | ||||||
|  | 			--init|-i) | ||||||
|  | 				init_config | ||||||
|  | 				exit 0 | ||||||
|  | 				;; | ||||||
| 			--crt|-c) | 			--crt|-c) | ||||||
| 				renewal_crt | 				renewal_crt | ||||||
| 				exit 0 | 				exit 0 | ||||||
| @ -463,6 +456,7 @@ optparser() { | |||||||
| 
 | 
 | ||||||
| # Entrypoint: | # Entrypoint: | ||||||
| main() { | main() { | ||||||
|  | 	load_config | ||||||
| 	optparser $@ | 	optparser $@ | ||||||
| 	get_access | 	get_access | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user