mirror of
https://github.com/FairwindsOps/polaris.git
synced 2026-02-14 18:09:54 +00:00
* add login flow * add logout functionality * improve code * implement token and status print * implement status command * add user to login * improve server port management * improve login flow * fix login flow * make insights URL for login configurable * remove comments * fix logrus directive usage * add upload-insights command * remove unnecessary usage of pointer * error when using upload-insights and audit-path simultaneously * upload-insights support * set priority to reports * adds report verification * fix logging to meet expected results * renaming variable name * improve results printing * improve variable naming * remove TODO * Update checks severities (#950) * change all ignore checks to warning * promoting checks initially warning that should be danger. * fixing docs and examples * adds changelog * fix changelog version * improve general error message * update workloads to be able grab its version * print URL on stdout on browser error * use os.WriteFile instead of low-level API * renaming fn params * add insights client * validating token on auth status * minor fix * only query for re-auth if token is still valid * update some dependencies in go and CI (#951) * update some dependencies * update testing requirements * Fix cert-manager * lots of deprecated versions * attempts * review suggestions * avoid nil pointer * fix fixtures * fix test --------- Co-authored-by: Robert Brennan <contact@rbren.io> * update changelog --------- Co-authored-by: Andrew Suderman <andy@fairwinds.com> Co-authored-by: Robert Brennan <contact@rbren.io>
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package auth
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/fairwindsops/polaris/pkg/insights"
|
|
)
|
|
|
|
func PrintStatus(insightsHost string) error {
|
|
if content, err := readPolarisHostsFile(); err == nil {
|
|
if len(content) > 0 {
|
|
if h, ok := content[insightsHost]; ok {
|
|
c := insights.NewHTTPClient(insightsHost, h.Organization, h.Token)
|
|
isValid, err := c.IsTokenValid()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !isValid {
|
|
fmt.Println("✕ Your token is no longer valid. Run polaris auth login to authenticate.")
|
|
return nil
|
|
}
|
|
fmt.Printf("✓ Logged in to %s as %s\n", insightsHost, h.User)
|
|
fmt.Printf("✓ Token: %s\n", hideToken(h.Token, 3))
|
|
return nil
|
|
}
|
|
}
|
|
fmt.Printf("✕ No authentication found for host %s. Run polaris auth login to authenticate.\n", insightsHost)
|
|
return nil
|
|
}
|
|
fmt.Println("You are not logged into Fairwinds Insights. Run polaris auth login to authenticate.")
|
|
return nil
|
|
}
|
|
|
|
func hideToken(token string, hideAfter int) string {
|
|
var i int
|
|
return strings.Map(func(r rune) rune {
|
|
defer func() {
|
|
i++
|
|
}()
|
|
if i > hideAfter {
|
|
return []rune("*")[0]
|
|
}
|
|
return r
|
|
}, token)
|
|
}
|