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>
54 lines
969 B
Go
54 lines
969 B
Go
package auth
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
var userHomeDir string
|
|
var polarisHostsFilepath string
|
|
|
|
var ErrNotLoggedIn = errors.New("not logged in")
|
|
|
|
func init() {
|
|
var err error
|
|
userHomeDir, err = os.UserHomeDir()
|
|
if err != nil {
|
|
logrus.Fatalf("reading user home dir: %v", err)
|
|
}
|
|
polarisHostsFilepath = userHomeDir + "/.config/polaris/hosts.yaml"
|
|
}
|
|
|
|
func readPolarisHostsFile() (map[string]Host, error) {
|
|
f, err := os.Open(polarisHostsFilepath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
b, err := io.ReadAll(f)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
content := map[string]Host{}
|
|
err = yaml.Unmarshal(b, &content)
|
|
return content, err
|
|
}
|
|
|
|
func GetAuth(insightsHost string) (*Host, error) {
|
|
hosts, err := readPolarisHostsFile()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(hosts) == 0 {
|
|
return nil, ErrNotLoggedIn
|
|
}
|
|
if h, ok := hosts[insightsHost]; ok {
|
|
return &h, nil
|
|
}
|
|
return nil, ErrNotLoggedIn
|
|
}
|