|
package initialize |
|
|
|
import ( |
|
"aurora/internal/tokens" |
|
"bufio" |
|
"fmt" |
|
"os" |
|
"strconv" |
|
|
|
"github.com/google/uuid" |
|
) |
|
|
|
func readAccessToken() *tokens.AccessToken { |
|
var Secrets []*tokens.Secret |
|
|
|
if _, err := os.Stat("access_tokens.txt"); err == nil { |
|
|
|
file, _ := os.Open("access_tokens.txt") |
|
defer file.Close() |
|
scanner := bufio.NewScanner(file) |
|
for scanner.Scan() { |
|
|
|
token := scanner.Text() |
|
if len(token) == 0 { |
|
continue |
|
} |
|
|
|
Secrets = append(Secrets, tokens.NewSecret(token)) |
|
} |
|
} |
|
|
|
|
|
if _, err := os.Stat("free_tokens.txt"); err == nil { |
|
|
|
file, _ := os.Open("free_tokens.txt") |
|
defer file.Close() |
|
scanner := bufio.NewScanner(file) |
|
for scanner.Scan() { |
|
|
|
token := scanner.Text() |
|
if len(token) == 0 { |
|
continue |
|
} |
|
|
|
Secrets = append(Secrets, tokens.NewSecretWithFree(token)) |
|
} |
|
} |
|
|
|
if os.Getenv("FREE_ACCOUNTS") == "" || os.Getenv("FREE_ACCOUNTS") == "true" { |
|
freeAccountsNumStr := os.Getenv("FREE_ACCOUNTS_NUM") |
|
numAccounts := 1024 |
|
if freeAccountsNumStr != "" { |
|
if freeAccountsNum, err := strconv.Atoi(freeAccountsNumStr); err == nil && freeAccountsNum > 0 { |
|
numAccounts = freeAccountsNum |
|
} else { |
|
fmt.Println("Invalid FREE_ACCOUNTS_NUM:", err) |
|
} |
|
} |
|
for i := 0; i < numAccounts; i++ { |
|
uid := uuid.NewString() |
|
Secrets = append(Secrets, tokens.NewSecretWithFree(uid)) |
|
} |
|
} |
|
|
|
token := tokens.NewAccessToken(Secrets) |
|
return &token |
|
} |
|
|