oscope-dev / scope

Scoping user machines
https://oscope-dev.github.io/scope/
BSD 3-Clause "New" or "Revised" License
6 stars 3 forks source link

If a check fails, and fix runs and displays to the console, it's not obvious what is running #42

Open technicalpickles opened 9 months ago

technicalpickles commented 9 months ago

I am starting a check for aws sso login. I borrowed logic for checking if a session is expired, and then signin in from code I've used before. I've noticed that check doesn't typically show the output on the console, and was kinda surprised when I got the output for fix on the console. It is actually what I wanted, because there is output the user needs to attend to 😁 I am more creating is to see if this is the desired behavior or not.

I did notice that you get that output before it's clear what the output is from.

Here's the implementation:

#!/usr/bin/env bash

subcommand=$1
if [ -z "$subcommand" ]; then
  echo "USAGE: $0 [check|fix]"
  exit 1
fi

aws_path=$(which aws 2>/dev/null)

function check() {
  echo -n "Checking for aws on your PATH... "

  if [[ -z "$aws_path" ]]; then
    echo "Couldn't find aws on the PATH"
    exit 1
  else
    echo "OK ($aws_path)"
  fi

  echo -n "Checking SSO session... "; 
  if ! aws sts get-caller-identity >/dev/null 2>&1;  then
    echo "PROBLEM (SSO session invalid or expired)"
    exit 1
  else
    echo "OK"
  fi
}

function fix() {
  if [[ -z "$aws_path" ]]; then
    echo "Installing awscli..."
    brew install awscli
  fi

  if ! aws sts get-caller-identity >/dev/null 2>&1;  then
    echo "Signing in... keep an eye out for the browser window"
    aws sso login
  fi
}

case "$subcommand" in
  fix) fix; check ;;
  check) check ;;
  *)
    echo "Don't know how to '$subcommand'"
    exit 1
    ;;
esac

And the YAML:

apiVersion: scope.github.com/v1alpha
kind: ScopeDoctorCheck
metadata:
  name: 00-aws-sso
spec:
  check:
    target: aws-sso.sh check
  fix:
    target: aws-sso.sh fix
  description: AWS SSO
  help: You need to login to AWS SSO

And here's the output:

❯ scope doctor run --only 00-aws-sso                                                                                                                                                                                                                     
 INFO More detailed logs at /tmp/scope/scope-root-20240129-JH8m.log
Signing in... keep an eye out for the browser window
Attempting to automatically open the SSO authorization page in your default browser.
If the browser does not open or you wish to use a different device to authorize this request, open the following URL:

https://device.sso.us-west-1.amazonaws.com/

Then enter the code:

REDACTED
Successfully logged into Start URL: redacted
Checking for aws on your PATH... OK (/opt/homebrew/bin/aws)
Checking SSO session... OK
 INFO Check `00-aws-sso` failed. Fix ran successfully.
ethankhall commented 9 months ago

I'm up for showing the output. My initial thought was, there woudln't be anything that a user would want to see from a check, so that's why it's hidden, but happy to switch it up.

technicalpickles commented 9 months ago

I'm thinking to output like:

rubberduck203 commented 1 day ago

+1 I think it would be good to display some output from the checks.