Skip to content

Check ssh connection to cloud #2

@isitnikov

Description

@isitnikov

Could you please add feature that will check SSH connection to cloud before doing any SSH requests.

See an example:

doMagentoCloudLogin()
{
  read  -n 1 -p "Do you want to connect via magento-cloud? [Y/n]: " GO
  if [[ ! -z "GO" && $GO != "n" ]]; then
    magento-cloud login -f
    if [[ $? -eq 1 ]]; then
      printNotice "Authorization rejected. Exit."
      final 1
    fi
  else
    printNotice "Authorization failed. Exit."
    final 1
  fi
}

checkSsh()
{
  if [[ -z $LOGGED_IN ]]; then
    printNotice "Checking SSH authorization..."
    status=$(ssh -o BatchMode=yes -o ConnectTimeout=5 $1 echo ok 2>&1)

    if [[ $status == ok ]]; then
      printStatus "SSH authorization" "OK"
      LOGGED_IN=1
    elif [[ $status == "Permission denied"* ]] ; then
      printNotice "Permission denied."
      doMagentoCloudLogin
    else
      printNotice "Error: $status"
      doMagentoCloudLogin
    fi
  fi
}

where $1 is SSH uri like: 1.ent-rbbhqz455ie4c-staging-5em2ouy@ssh.ap-3.magento.cloud

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions