mirror of
https://github.com/ANG13T/SatIntel.git
synced 2025-12-05 20:40:09 -08:00
Merge pull request #2 from christopherwoodall/1-env-auth-over-ride
Set/Get environmental variables in `main.go`
This commit is contained in:
10
README.md
10
README.md
@@ -37,11 +37,11 @@ Make an account at [**Space Track**](https://space-track.org) save username and
|
||||
|
||||
Create an account at [**N2YO**](https://n2yo.com) and save API key.
|
||||
|
||||
Update `main.go` to have proper credentials
|
||||
```
|
||||
os.Setenv("SPACE_TRACK_USERNAME", "username")
|
||||
os.Setenv("SPACE_TRACK_PASSWORD", "password")
|
||||
os.Setenv("N2YO_API_KEY", "api-key")
|
||||
The CLI will prompt for both Space Track and N2YO credentials if none are present in your environmental variables. To export your credentials enter the following commands:
|
||||
```bash
|
||||
$ export SPACE_TRACK_USERNAME="YOUR_USER_NAME"
|
||||
$ export SPACE_TRACK_PASSWORD="YOUR_PASSWORD"
|
||||
$ export N2YO_API_KEY="YOUR_API_KEY"
|
||||
```
|
||||
|
||||
To build from source, you will need Go installed.
|
||||
|
||||
43
main.go
43
main.go
@@ -1,17 +1,50 @@
|
||||
/*
|
||||
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
|
||||
|
||||
Copyright © 2023 Angelina Tsuboi angelinatsuboi@proton.me
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/ANG13T/SatIntel/cli"
|
||||
)
|
||||
|
||||
func setEnvironmentalVariable(envKey string) string {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
fmt.Printf("%s: ", envKey)
|
||||
input, err := reader.ReadString('\n')
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Error reading input:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
input = strings.TrimSuffix(input, "\n")
|
||||
|
||||
if err := os.Setenv(envKey, input); err != nil {
|
||||
fmt.Printf("Error setting environment variable %s: %v\n", envKey, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return input
|
||||
}
|
||||
|
||||
|
||||
func checkEnvironmentalVariable(envKey string) {
|
||||
_, found := os.LookupEnv(envKey)
|
||||
if !found {
|
||||
setEnvironmentalVariable(envKey)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
os.Setenv("SPACE_TRACK_USERNAME", "username")
|
||||
os.Setenv("SPACE_TRACK_PASSWORD", "password")
|
||||
os.Setenv("N2YO_API_KEY", "api-key")
|
||||
checkEnvironmentalVariable("SPACE_TRACK_USERNAME")
|
||||
checkEnvironmentalVariable("SPACE_TRACK_PASSWORD")
|
||||
checkEnvironmentalVariable("N2YO_API_KEY")
|
||||
|
||||
cli.SatIntel()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user