Files
umbrix-libcore/config/warp_account.go

51 lines
1.3 KiB
Go
Raw Normal View History

2024-02-18 12:31:17 +03:30
package config
2024-02-20 22:15:52 +03:30
import (
"encoding/json"
)
2024-02-18 12:31:17 +03:30
type WarpAccount struct {
AccountID string `json:"account-id"`
AccessToken string `json:"access-token"`
}
2024-02-20 22:15:52 +03:30
type WarpWireguardConfig struct {
PrivateKey string `json:"private-key"`
LocalAddressIPv4 string `json:"local-address-ipv4"`
LocalAddressIPv6 string `json:"local-address-ipv6"`
PeerPublicKey string `json:"peer-public-key"`
ClientID string `json:"client-id"`
2024-02-20 22:15:52 +03:30
}
type WarpGenerationResponse struct {
WarpAccount
Log string `json:"log"`
Config WarpWireguardConfig `json:"config"`
}
2024-02-18 12:31:17 +03:30
func GenerateWarpAccount(licenseKey string, accountId string, accessToken string) (string, error) {
identity, log, wg, err := GenerateWarpInfo(licenseKey, accountId, accessToken)
2024-02-18 12:31:17 +03:30
if err != nil {
return "", err
}
2024-02-20 22:15:52 +03:30
2024-02-18 12:31:17 +03:30
warpAccount := WarpAccount{
AccountID: identity.ID,
AccessToken: identity.Token,
2024-02-18 12:31:17 +03:30
}
2024-02-20 22:15:52 +03:30
warpConfig := WarpWireguardConfig{
PrivateKey: wg.PrivateKey,
LocalAddressIPv4: wg.LocalAddressIPv4,
LocalAddressIPv6: wg.LocalAddressIPv6,
PeerPublicKey: wg.PeerPublicKey,
ClientID: wg.ClientID,
2024-02-20 22:15:52 +03:30
}
response := WarpGenerationResponse{warpAccount, log, warpConfig}
responseJson, err := json.Marshal(response)
2024-02-18 12:31:17 +03:30
if err != nil {
return "", err
}
2024-02-20 22:15:52 +03:30
return string(responseJson), nil
2024-02-18 12:31:17 +03:30
}