sync: 0.7.0 from main (3f0d10f172101035f4e0f736695e1700ee1ec967)

This commit is contained in:
github-actions[bot] committed 2026-04-17 18:41:28 +00:00
1 parent 182a719053
commit fdf612350a
34 files changed
+2032 -430

No files matched your search

+257 -209
View File
@@ -24,17 +24,17 @@ import (
"time"
)
var _k1 = []byte{0x92, 0x8a, 0x16, 0xa6, 0xfe, 0xe4, 0x09, 0xeb, 0xf6, 0x25, 0xd6, 0xf3, 0x94, 0x0f, 0x76, 0xef, 0x38, 0x68, 0xe0, 0x52, 0x4e, 0xca, 0x54, 0x25, 0x4b, 0x93, 0x52, 0xc6, 0x5a, 0x59, 0x4e, 0x64, 0xa7, 0xce, 0x48, 0x22, 0x7f, 0x04, 0x3c, 0x59, 0x0e, 0x3b}
var _k0 = []byte{0xfa, 0xfe, 0x62, 0xd6, 0x8d, 0xde, 0x26, 0xc4, 0x9a, 0x4c, 0xb5, 0x96, 0xfa, 0x7c, 0x13, 0xc1, 0x5d, 0x1e, 0x8f, 0x3e, 0x3b, 0xbe, 0x3d, 0x4a, 0x25, 0xf5, 0x3d, 0xb3, 0x34, 0x3d, 0x2f, 0x10, 0xce, 0xa1, 0x26, 0x0c, 0x1c, 0x6b, 0x51, 0x77, 0x6c, 0x49}
var _k1 = []byte{0x88, 0xe1, 0xd0, 0x50, 0x74, 0x8f, 0xb5, 0x64, 0x84, 0xbe, 0xa9, 0xbe, 0xeb, 0x45, 0xc1, 0x4d, 0x11, 0x75, 0xc3, 0xc4, 0x4a, 0x51, 0x4b, 0xdf, 0x50, 0xb6, 0x83, 0xd2, 0x07, 0xbe, 0x67, 0x27, 0xdc, 0x03, 0xe7, 0x2e, 0x50, 0xad, 0xbb, 0x50, 0x40, 0x55}
var _k0 = []byte{0xe0, 0x95, 0xa4, 0x20, 0x07, 0xb5, 0x9a, 0x4b, 0xe8, 0xd7, 0xca, 0xdb, 0x85, 0x36, 0xa4, 0x63, 0x74, 0x03, 0xac, 0xa8, 0x3f, 0x25, 0x22, 0xb0, 0x3e, 0xd0, 0xec, 0xa7, 0x69, 0xda, 0x06, 0x53, 0xb5, 0x6c, 0x89, 0x00, 0x33, 0xc2, 0xd6, 0x7e, 0x22, 0x27}
var (
_w3s9 string
_jl7 string
_jyou string
_1h string
)
func _rmo() string {
if _w3s9 != "" && _jl7 != "" {
return _4drn(_w3s9, _jl7)
func _c0u() string {
if _jyou != "" && _1h != "" {
return _dv(_jyou, _1h)
}
parts := [...]string{"h", "tt", "ps", "://", "li", "ce", "nse", ".", "ev", "ol", "ut", "io", "nf", "ou", "nd", "at", "io", "n.", "co", "m.", "br"}
var s string
@@ -44,9 +44,9 @@ func _rmo() string {
return s
}
func _4drn(enc, key string) string {
encBytes := _iz6(enc)
keyBytes := _iz6(key)
func _dv(enc, key string) string {
encBytes := _3z(enc)
keyBytes := _3z(key)
if len(keyBytes) == 0 {
return ""
}
@@ -57,18 +57,18 @@ func _4drn(enc, key string) string {
return string(out)
}
func _iz6(s string) []byte {
func _3z(s string) []byte {
if len(s)%2 != 0 {
return nil
}
b := make([]byte, len(s)/2)
for i := 0; i < len(s); i += 2 {
b[i/2] = _xtts(s[i])<<4 | _xtts(s[i+1])
b[i/2] = _323(s[i])<<4 | _323(s[i+1])
}
return b
}
func _xtts(c byte) byte {
func _323(c byte) byte {
switch {
case c >= '0' && c <= '9':
return c - '0'
@@ -80,62 +80,62 @@ func _xtts(c byte) byte {
return 0
}
var _ls61 = &http.Client{Timeout: 10 * time.Second}
var _e97 = &http.Client{Timeout: 10 * time.Second}
func _t5d(body []byte, secret string) string {
func _48bz(body []byte, secret string) string {
mac := hmac.New(sha256.New, []byte(secret))
mac.Write(body)
return hex.EncodeToString(mac.Sum(nil))
}
func _rkb(path string, payload interface{}, _jpwr string) (*http.Response, error) {
func _i9r(path string, payload interface{}, _94b string) (*http.Response, error) {
body, err := json.Marshal(payload)
if err != nil {
return nil, err
}
url := _rmo() + path
url := _c0u() + path
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(body))
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Api-Key", _jpwr)
req.Header.Set("X-Signature", _t5d(body, _jpwr))
req.Header.Set("X-Api-Key", _94b)
req.Header.Set("X-Signature", _48bz(body, _94b))
return _ls61.Do(req)
return _e97.Do(req)
}
func _qfhm(path string) (*http.Response, error) {
url := _rmo() + path
return _ls61.Get(url)
func _3r(path string) (*http.Response, error) {
url := _c0u() + path
return _e97.Get(url)
}
func _pzi6(path string, payload interface{}) (*http.Response, error) {
func _7n05(path string, payload interface{}) (*http.Response, error) {
body, err := json.Marshal(payload)
if err != nil {
return nil, err
}
url := _rmo() + path
url := _c0u() + path
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(body))
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
return _ls61.Do(req)
return _e97.Do(req)
}
func _2l4(resp *http.Response) error {
func _39pp(resp *http.Response) error {
b, _ := io.ReadAll(resp.Body)
var _28 struct {
var _p2d struct {
Message string `json:"message"`
Error string `json:"error"`
}
if err := json.Unmarshal(b, &_28); err == nil {
msg := _28.Message
if err := json.Unmarshal(b, &_p2d); err == nil {
msg := _p2d.Message
if msg == "" {
msg = _28.Error
msg = _p2d.Error
}
if msg != "" {
return fmt.Errorf("%s (HTTP %d)", strings.ToLower(msg), resp.StatusCode)
@@ -163,48 +163,48 @@ const (
ConfigKeyCustomerID = "customer_id"
)
var _4k *gorm.DB
var _wd83 *gorm.DB
func SetDB(db *gorm.DB) {
_4k = db
_wd83 = db
}
func MigrateDB() error {
if _4k == nil {
if _wd83 == nil {
return fmt.Errorf("core: database not set, call SetDB first")
}
return _4k.AutoMigrate(&RuntimeConfig{})
return _wd83.AutoMigrate(&RuntimeConfig{})
}
func _di(key string) (string, error) {
if _4k == nil {
func _2z(key string) (string, error) {
if _wd83 == nil {
return "", fmt.Errorf("core: database not set")
}
var _lac RuntimeConfig
_x1 := _4k.Where("key = ?", key).First(&_lac)
if _x1.Error != nil {
return "", _x1.Error
var _hh54 RuntimeConfig
_ve := _wd83.Where("key = ?", key).First(&_hh54)
if _ve.Error != nil {
return "", _ve.Error
}
return _lac.Value, nil
return _hh54.Value, nil
}
func _o35(key, value string) error {
if _4k == nil {
func _7pe(key, value string) error {
if _wd83 == nil {
return fmt.Errorf("core: database not set")
}
var _lac RuntimeConfig
_x1 := _4k.Where("key = ?", key).First(&_lac)
if _x1.Error != nil {
return _4k.Create(&RuntimeConfig{Key: key, Value: value}).Error
var _hh54 RuntimeConfig
_ve := _wd83.Where("key = ?", key).First(&_hh54)
if _ve.Error != nil {
return _wd83.Create(&RuntimeConfig{Key: key, Value: value}).Error
}
return _4k.Model(&_lac).Update("value", value).Error
return _wd83.Model(&_hh54).Update("value", value).Error
}
func _nre(key string) {
if _4k == nil {
func _5i(key string) {
if _wd83 == nil {
return
}
_4k.Where("key = ?", key).Delete(&RuntimeConfig{})
_wd83.Where("key = ?", key).Delete(&RuntimeConfig{})
}
type RuntimeData struct {
@@ -213,67 +213,67 @@ type RuntimeData struct {
CustomerID int
}
func _8ftv() (*RuntimeData, error) {
_jpwr, err := _di(ConfigKeyAPIKey)
if err != nil || _jpwr == "" {
func _vk() (*RuntimeData, error) {
_94b, err := _2z(ConfigKeyAPIKey)
if err != nil || _94b == "" {
return nil, fmt.Errorf("no license found")
}
_y6, _ := _di(ConfigKeyTier)
customerIDStr, _ := _di(ConfigKeyCustomerID)
_pkj, _ := _2z(ConfigKeyTier)
customerIDStr, _ := _2z(ConfigKeyCustomerID)
customerID, _ := strconv.Atoi(customerIDStr)
return &RuntimeData{
APIKey: _jpwr,
Tier: _y6,
APIKey: _94b,
Tier: _pkj,
CustomerID: customerID,
}, nil
}
func _nk7y(rd *RuntimeData) error {
if err := _o35(ConfigKeyAPIKey, rd.APIKey); err != nil {
func _b7mk(rd *RuntimeData) error {
if err := _7pe(ConfigKeyAPIKey, rd.APIKey); err != nil {
return err
}
if err := _o35(ConfigKeyTier, rd.Tier); err != nil {
if err := _7pe(ConfigKeyTier, rd.Tier); err != nil {
return err
}
if rd.CustomerID > 0 {
if err := _o35(ConfigKeyCustomerID, strconv.Itoa(rd.CustomerID)); err != nil {
if err := _7pe(ConfigKeyCustomerID, strconv.Itoa(rd.CustomerID)); err != nil {
return err
}
}
return nil
}
func _9s() {
_nre(ConfigKeyAPIKey)
_nre(ConfigKeyTier)
_nre(ConfigKeyCustomerID)
func _q2pm() {
_5i(ConfigKeyAPIKey)
_5i(ConfigKeyTier)
_5i(ConfigKeyCustomerID)
}
func _viat() (string, error) {
id, err := _di(ConfigKeyInstanceID)
func _ix() (string, error) {
id, err := _2z(ConfigKeyInstanceID)
if err == nil && len(id) == 36 {
return id, nil
}
id = _ead()
id = _d6()
if id == "" {
id, err = _hxo()
id, err = _yb7k()
if err != nil {
return "", err
}
}
if err := _o35(ConfigKeyInstanceID, id); err != nil {
if err := _7pe(ConfigKeyInstanceID, id); err != nil {
return "", err
}
return id, nil
}
func _ead() string {
func _d6() string {
hostname, _ := os.Hostname()
macAddr := _g9n9()
macAddr := _efr()
if hostname == "" && macAddr == "" {
return ""
}
@@ -284,13 +284,13 @@ func _ead() string {
for i := 16; i < len(seed); i++ {
h[i%16] ^= seed[i]
}
h[6] = (h[6] & 0x0f) | 0x40 // _h7 4
h[6] = (h[6] & 0x0f) | 0x40 // _an 4
h[8] = (h[8] & 0x3f) | 0x80 // variant
return fmt.Sprintf("%08x-%04x-%04x-%04x-%012x",
h[0:4], h[4:6], h[6:8], h[8:10], h[10:16])
}
func _g9n9() string {
func _efr() string {
interfaces, err := net.Interfaces()
if err != nil {
return ""
@@ -306,7 +306,7 @@ func _g9n9() string {
return ""
}
func _hxo() (string, error) {
func _yb7k() (string, error) {
var b [16]byte
if _, err := rand.Read(b[:]); err != nil {
return "", err
@@ -317,20 +317,20 @@ func _hxo() (string, error) {
b[0:4], b[4:6], b[6:8], b[8:10], b[10:16]), nil
}
var _l3rh atomic.Value // set during activation
var _2p6 atomic.Value // set during activation
func init() {
_l3rh.Store([]byte{0})
_2p6.Store([]byte{0})
}
func ComputeSessionSeed(instanceName string, rc *RuntimeContext) []byte {
if rc == nil || !rc._xk65.Load() {
if rc == nil || !rc._6l.Load() {
return nil // Will cause panic in caller — intentional
}
h := sha256.New()
h.Write([]byte(instanceName))
h.Write([]byte(rc._jpwr))
salt, _ := _l3rh.Load().([]byte)
h.Write([]byte(rc._94b))
salt, _ := _2p6.Load().([]byte)
h.Write(salt)
return h.Sum(nil)[:16]
}
@@ -343,20 +343,20 @@ func ValidateRouteAccess(rc *RuntimeContext) uint64 {
return binary.LittleEndian.Uint64(h[:8])
}
func DeriveInstanceToken(_645 string, rc *RuntimeContext) string {
if rc == nil || !rc._xk65.Load() {
func DeriveInstanceToken(_32d string, rc *RuntimeContext) string {
if rc == nil || !rc._6l.Load() {
return ""
}
h := sha256.Sum256([]byte(_645 + rc._jpwr))
return _yls(h[:8])
h := sha256.Sum256([]byte(_32d + rc._94b))
return _w5(h[:8])
}
func _yls(b []byte) string {
const _5swh = "0123456789abcdef"
func _w5(b []byte) string {
const _0q2 = "0123456789abcdef"
dst := make([]byte, len(b)*2)
for i, v := range b {
dst[i*2] = _5swh[v>>4]
dst[i*2+1] = _5swh[v&0x0f]
dst[i*2] = _0q2[v>>4]
dst[i*2+1] = _0q2[v&0x0f]
}
return string(dst)
}
@@ -365,8 +365,8 @@ func ActivateIntegrity(rc *RuntimeContext) {
if rc == nil {
return
}
h := sha256.Sum256([]byte(rc._jpwr + rc._645 + "ev0"))
_l3rh.Store(h[:])
h := sha256.Sum256([]byte(rc._94b + rc._32d + "ev0"))
_2p6.Store(h[:])
}
const (
@@ -374,101 +374,129 @@ const (
)
type RuntimeContext struct {
_jpwr string
_444 string // GLOBAL_API_KEY from .env — used as token for licensing check
_645 string
_xk65 atomic.Bool
_uw [32]byte // Derived from activation — required by ValidateContext
_94b string
_lt8 string // GLOBAL_API_KEY from .env — used as token for licensing check
_32d string
_6l atomic.Bool
_hlc7 [32]byte // Derived from activation — required by ValidateContext
mu sync.RWMutex
_yf6 string // Registration URL shown to users before activation
_s09 string // Registration token for polling
_y6 string
_h7 string
_lmo string // Registration URL shown to users before activation
_k5 string // Registration token for polling
_pkj string
_an string
_jpz atomic.Int64 // Messages sent since last heartbeat
_9n3 atomic.Int64 // Messages received since last heartbeat
}
var _ipo atomic.Pointer[RuntimeContext]
func (rc *RuntimeContext) TrackMessage() {
if rc != nil {
rc._jpz.Add(1)
}
}
func TrackMessageSent() {
if rc := _ipo.Load(); rc != nil {
rc._jpz.Add(1)
}
}
func TrackMessageRecv() {
if rc := _ipo.Load(); rc != nil {
rc._9n3.Add(1)
}
}
func (rc *RuntimeContext) _wf() int64 {
return rc._jpz.Swap(0)
}
func (rc *RuntimeContext) ContextHash() [32]byte {
rc.mu.RLock()
defer rc.mu.RUnlock()
return rc._uw
return rc._hlc7
}
func (rc *RuntimeContext) IsActive() bool {
return rc._xk65.Load()
return rc._6l.Load()
}
func (rc *RuntimeContext) RegistrationURL() string {
rc.mu.RLock()
defer rc.mu.RUnlock()
return rc._yf6
return rc._lmo
}
func (rc *RuntimeContext) APIKey() string {
rc.mu.RLock()
defer rc.mu.RUnlock()
return rc._jpwr
return rc._94b
}
func (rc *RuntimeContext) InstanceID() string {
return rc._645
return rc._32d
}
func InitializeRuntime(_y6, _h7, _444 string) *RuntimeContext {
if _y6 == "" {
_y6 = "evolution-go"
func InitializeRuntime(_pkj, _an, _lt8 string) *RuntimeContext {
if _pkj == "" {
_pkj = "evolution-go"
}
if _h7 == "" {
_h7 = "unknown"
if _an == "" {
_an = "unknown"
}
rc := &RuntimeContext{
_y6: _y6,
_h7: _h7,
_444: _444,
_pkj: _pkj,
_an: _an,
_lt8: _lt8,
}
id, err := _viat()
id, err := _ix()
if err != nil {
log.Fatalf("[runtime] failed to initialize instance: %v", err)
}
rc._645 = id
rc._32d = id
rd, err := _8ftv()
rd, err := _vk()
if err == nil && rd.APIKey != "" {
rc._jpwr = rd.APIKey
rc._94b = rd.APIKey
fmt.Printf(" ✓ License found: %s...%s\n", rd.APIKey[:8], rd.APIKey[len(rd.APIKey)-4:])
rc._uw = sha256.Sum256([]byte(rc._jpwr + rc._645))
rc._xk65.Store(true)
rc._hlc7 = sha256.Sum256([]byte(rc._94b + rc._32d))
rc._6l.Store(true)
ActivateIntegrity(rc)
fmt.Println(" ✓ License activated successfully")
go func() {
if err := _2a2d(rc, _h7); err != nil {
if err := _vrz(rc, _an); err != nil {
fmt.Printf(" ⚠ Remote activation notice failed (non-blocking): %v\n", err)
}
}()
} else if rc._444 != "" {
rc._jpwr = rc._444
if err := _2a2d(rc, _h7); err == nil {
_nk7y(&RuntimeData{APIKey: rc._444, Tier: _y6})
rc._uw = sha256.Sum256([]byte(rc._jpwr + rc._645))
rc._xk65.Store(true)
} else if rc._lt8 != "" {
rc._94b = rc._lt8
if err := _vrz(rc, _an); err == nil {
_b7mk(&RuntimeData{APIKey: rc._lt8, Tier: _pkj})
rc._hlc7 = sha256.Sum256([]byte(rc._94b + rc._32d))
rc._6l.Store(true)
ActivateIntegrity(rc)
fmt.Printf(" ✓ GLOBAL_API_KEY accepted — license saved and activated\n")
} else {
rc._jpwr = ""
_p3()
rc._xk65.Store(false)
rc._94b = ""
_c56()
rc._6l.Store(false)
}
} else {
_p3()
rc._xk65.Store(false)
_c56()
rc._6l.Store(false)
}
_ipo.Store(rc)
return rc
}
func _p3() {
func _c56() {
fmt.Println()
fmt.Println(" ╔══════════════════════════════════════════════════════════╗")
fmt.Println(" ║ License Registration Required ║")
@@ -480,41 +508,41 @@ func _p3() {
fmt.Println()
}
func (rc *RuntimeContext) _fbk(authCodeOrKey, _y6 string, customerID int) error {
_jpwr, err := _kc1(authCodeOrKey)
func (rc *RuntimeContext) _upx4(authCodeOrKey, _pkj string, customerID int) error {
_94b, err := _gd97(authCodeOrKey)
if err != nil {
return fmt.Errorf("key exchange failed: %w", err)
}
rc.mu.Lock()
rc._jpwr = _jpwr
rc._yf6 = ""
rc._s09 = ""
rc._94b = _94b
rc._lmo = ""
rc._k5 = ""
rc.mu.Unlock()
if err := _nk7y(&RuntimeData{
APIKey: _jpwr,
Tier: _y6,
if err := _b7mk(&RuntimeData{
APIKey: _94b,
Tier: _pkj,
CustomerID: customerID,
}); err != nil {
fmt.Printf(" ⚠ Warning: could not save license: %v\n", err)
}
if err := _2a2d(rc, rc._h7); err != nil {
if err := _vrz(rc, rc._an); err != nil {
return err
}
rc.mu.Lock()
rc._uw = sha256.Sum256([]byte(rc._jpwr + rc._645))
rc._hlc7 = sha256.Sum256([]byte(rc._94b + rc._32d))
rc.mu.Unlock()
rc._xk65.Store(true)
rc._6l.Store(true)
ActivateIntegrity(rc)
fmt.Printf(" ✓ License activated! Key: %s...%s (_y6: %s)\n",
_jpwr[:8], _jpwr[len(_jpwr)-4:], _y6)
fmt.Printf(" ✓ License activated! Key: %s...%s (_pkj: %s)\n",
_94b[:8], _94b[len(_94b)-4:], _pkj)
go func() {
if err := _b1h(rc, 0); err != nil {
if err := _fjl1(rc, 0); err != nil {
fmt.Printf(" ⚠ First heartbeat failed: %v\n", err)
}
}()
@@ -526,10 +554,10 @@ func ValidateContext(rc *RuntimeContext) (bool, string) {
if rc == nil {
return false, ""
}
if !rc._xk65.Load() {
if !rc._6l.Load() {
return false, rc.RegistrationURL()
}
expected := sha256.Sum256([]byte(rc._jpwr + rc._645))
expected := sha256.Sum256([]byte(rc._94b + rc._32d))
actual := rc.ContextHash()
if expected != actual {
return false, ""
@@ -586,12 +614,12 @@ func LicenseRoutes(eng *gin.Engine, rc *RuntimeContext) {
resp := gin.H{
"status": status,
"instance_id": rc._645,
"instance_id": rc._32d,
}
rc.mu.RLock()
if rc._jpwr != "" {
resp["api_key"] = rc._jpwr[:8] + "..." + rc._jpwr[len(rc._jpwr)-4:]
if rc._94b != "" {
resp["api_key"] = rc._94b[:8] + "..." + rc._94b[len(rc._94b)-4:]
}
rc.mu.RUnlock()
@@ -608,7 +636,7 @@ func LicenseRoutes(eng *gin.Engine, rc *RuntimeContext) {
}
rc.mu.RLock()
existingURL := rc._yf6
existingURL := rc._lmo
rc.mu.RUnlock()
if existingURL != "" {
@@ -620,15 +648,15 @@ func LicenseRoutes(eng *gin.Engine, rc *RuntimeContext) {
}
payload := map[string]string{
"tier": rc._y6,
"version": rc._h7,
"instance_id": rc._645,
"tier": rc._pkj,
"version": rc._an,
"instance_id": rc._32d,
}
if redirectURI := c.Query("redirect_uri"); redirectURI != "" {
payload["redirect_uri"] = redirectURI
}
resp, err := _pzi6("/v1/register/init", payload)
resp, err := _7n05("/v1/register/init", payload)
if err != nil {
c.JSON(http.StatusBadGateway, gin.H{
"error": "Failed to contact licensing server",
@@ -639,30 +667,30 @@ func LicenseRoutes(eng *gin.Engine, rc *RuntimeContext) {
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
_28 := _2l4(resp)
_p2d := _39pp(resp)
c.JSON(resp.StatusCode, gin.H{
"error": "Licensing server error",
"details": _28.Error(),
"details": _p2d.Error(),
})
return
}
var _fy4y struct {
var _hs struct {
RegisterURL string `json:"register_url"`
Token string `json:"token"`
}
json.NewDecoder(resp.Body).Decode(&_fy4y)
json.NewDecoder(resp.Body).Decode(&_hs)
rc.mu.Lock()
rc._yf6 = _fy4y.RegisterURL
rc._s09 = _fy4y.Token
rc._lmo = _hs.RegisterURL
rc._k5 = _hs.Token
rc.mu.Unlock()
fmt.Printf(" → Registration URL: %s\n", _fy4y.RegisterURL)
fmt.Printf(" → Registration URL: %s\n", _hs.RegisterURL)
c.JSON(http.StatusOK, gin.H{
"status": "pending",
"register_url": _fy4y.RegisterURL,
"register_url": _hs.RegisterURL,
})
})
@@ -684,9 +712,9 @@ func LicenseRoutes(eng *gin.Engine, rc *RuntimeContext) {
return
}
exchangeResp, err := _pzi6("/v1/register/exchange", map[string]string{
exchangeResp, err := _7n05("/v1/register/exchange", map[string]string{
"authorization_code": code,
"instance_id": rc._645,
"instance_id": rc._32d,
})
if err != nil {
c.JSON(http.StatusBadGateway, gin.H{
@@ -698,22 +726,22 @@ func LicenseRoutes(eng *gin.Engine, rc *RuntimeContext) {
defer exchangeResp.Body.Close()
if exchangeResp.StatusCode != http.StatusOK {
_28 := _2l4(exchangeResp)
_p2d := _39pp(exchangeResp)
c.JSON(exchangeResp.StatusCode, gin.H{
"error": "Exchange failed",
"details": _28.Error(),
"details": _p2d.Error(),
})
return
}
var _x1 struct {
var _ve struct {
APIKey string `json:"api_key"`
Tier string `json:"tier"`
CustomerID int `json:"customer_id"`
}
json.NewDecoder(exchangeResp.Body).Decode(&_x1)
json.NewDecoder(exchangeResp.Body).Decode(&_ve)
if _x1.APIKey == "" {
if _ve.APIKey == "" {
c.JSON(http.StatusBadRequest, gin.H{
"error": "Invalid or expired code",
"message": "The authorization code is invalid or has expired.",
@@ -721,7 +749,7 @@ func LicenseRoutes(eng *gin.Engine, rc *RuntimeContext) {
return
}
if err := rc._fbk(_x1.APIKey, _x1.Tier, _x1.CustomerID); err != nil {
if err := rc._upx4(_ve.APIKey, _ve.Tier, _ve.CustomerID); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"error": "Activation failed",
"details": err.Error(),
@@ -751,7 +779,7 @@ func StartHeartbeat(ctx context.Context, rc *RuntimeContext, startTime time.Time
continue
}
uptime := int64(time.Since(startTime).Seconds())
if err := _b1h(rc, uptime); err != nil {
if err := _fjl1(rc, uptime); err != nil {
fmt.Printf(" ⚠ Heartbeat failed (non-blocking): %v\n", err)
}
}
@@ -760,14 +788,14 @@ func StartHeartbeat(ctx context.Context, rc *RuntimeContext, startTime time.Time
}
func Shutdown(rc *RuntimeContext) {
if rc == nil || rc._jpwr == "" {
if rc == nil || rc._94b == "" {
return
}
_uht(rc)
_gy(rc)
}
func _kms(code string) (_jpwr string, err error) {
resp, err := _pzi6("/v1/register/exchange", map[string]string{
func _z6rh(code string) (_94b string, err error) {
resp, err := _7n05("/v1/register/exchange", map[string]string{
"authorization_code": code,
})
if err != nil {
@@ -776,84 +804,104 @@ func _kms(code string) (_jpwr string, err error) {
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", _2l4(resp)
return "", _39pp(resp)
}
var _x1 struct {
var _ve struct {
APIKey string `json:"api_key"`
}
json.NewDecoder(resp.Body).Decode(&_x1)
if _x1.APIKey == "" {
json.NewDecoder(resp.Body).Decode(&_ve)
if _ve.APIKey == "" {
return "", fmt.Errorf("exchange returned empty api_key")
}
return _x1.APIKey, nil
return _ve.APIKey, nil
}
func _kc1(authCodeOrKey string) (string, error) {
_jpwr, err := _kms(authCodeOrKey)
if err == nil && _jpwr != "" {
return _jpwr, nil
func _gd97(authCodeOrKey string) (string, error) {
_94b, err := _z6rh(authCodeOrKey)
if err == nil && _94b != "" {
return _94b, nil
}
return authCodeOrKey, nil
}
func _2a2d(rc *RuntimeContext, _h7 string) error {
resp, err := _rkb("/v1/activate", map[string]string{
"instance_id": rc._645,
"version": _h7,
}, rc._jpwr)
func _vrz(rc *RuntimeContext, _an string) error {
resp, err := _i9r("/v1/activate", map[string]string{
"instance_id": rc._32d,
"version": _an,
}, rc._94b)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return _2l4(resp)
return _39pp(resp)
}
var _x1 struct {
var _ve struct {
Status string `json:"status"`
}
json.NewDecoder(resp.Body).Decode(&_x1)
json.NewDecoder(resp.Body).Decode(&_ve)
if _x1.Status != "active" {
return fmt.Errorf("activation returned status: %s", _x1.Status)
if _ve.Status != "active" {
return fmt.Errorf("activation returned status: %s", _ve.Status)
}
return nil
}
func _b1h(rc *RuntimeContext, uptimeSeconds int64) error {
resp, err := _rkb("/v1/heartbeat", map[string]any{
"instance_id": rc._645,
func _fjl1(rc *RuntimeContext, uptimeSeconds int64) error {
_jpz := rc._wf()
_9n3 := rc._9n3.Swap(0)
payload := map[string]any{
"instance_id": rc._32d,
"uptime_seconds": uptimeSeconds,
"version": rc._h7,
}, rc._jpwr)
"version": rc._an,
}
if _jpz > 0 || _9n3 > 0 {
bundle := map[string]any{}
if _jpz > 0 {
bundle["messages_sent"] = _jpz
}
if _9n3 > 0 {
bundle["messages_recv"] = _9n3
}
payload["telemetry_bundle"] = bundle
}
resp, err := _i9r("/v1/heartbeat", payload, rc._94b)
if err != nil {
rc._jpz.Add(_jpz)
rc._9n3.Add(_9n3)
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return _2l4(resp)
rc._jpz.Add(_jpz)
rc._9n3.Add(_9n3)
return _39pp(resp)
}
return nil
}
func _uht(rc *RuntimeContext) {
func _gy(rc *RuntimeContext) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
body, _ := json.Marshal(map[string]string{
"instance_id": rc._645,
"instance_id": rc._32d,
})
url := _rmo() + "/v1/deactivate"
url := _c0u() + "/v1/deactivate"
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body))
if err != nil {
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Api-Key", rc._jpwr)
req.Header.Set("X-Signature", _t5d(body, rc._jpwr))
_ls61.Do(req)
req.Header.Set("X-Api-Key", rc._94b)
req.Header.Set("X-Signature", _48bz(body, rc._94b))
_e97.Do(req)
}