2022-10-06 20:13:30 +05:30
|
|
|
package signozio
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
|
2025-03-20 21:01:41 +05:30
|
|
|
"github.com/SigNoz/signoz/ee/query-service/model"
|
2025-04-28 19:50:47 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/zeus"
|
|
|
|
|
"github.com/tidwall/gjson"
|
2022-10-06 20:13:30 +05:30
|
|
|
)
|
|
|
|
|
|
2025-04-28 19:50:47 +05:30
|
|
|
func ValidateLicenseV3(ctx context.Context, licenseKey string, zeus zeus.Zeus) (*model.LicenseV3, error) {
|
|
|
|
|
data, err := zeus.GetLicense(ctx, licenseKey)
|
2024-11-12 01:40:10 +05:30
|
|
|
if err != nil {
|
2025-04-28 19:50:47 +05:30
|
|
|
return nil, err
|
2024-11-12 01:40:10 +05:30
|
|
|
}
|
|
|
|
|
|
2025-04-28 19:50:47 +05:30
|
|
|
var m map[string]any
|
|
|
|
|
if err = json.Unmarshal(data, &m); err != nil {
|
|
|
|
|
return nil, err
|
2024-11-12 01:40:10 +05:30
|
|
|
}
|
|
|
|
|
|
2025-04-28 19:50:47 +05:30
|
|
|
license, err := model.NewLicenseV3(m)
|
2022-10-06 20:13:30 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-28 19:50:47 +05:30
|
|
|
return license, nil
|
2022-10-06 20:13:30 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SendUsage reports the usage of signoz to license server
|
2025-04-28 19:50:47 +05:30
|
|
|
func SendUsage(ctx context.Context, usage model.UsagePayload, zeus zeus.Zeus) error {
|
|
|
|
|
body, err := json.Marshal(usage)
|
2022-10-06 20:13:30 +05:30
|
|
|
if err != nil {
|
2025-04-28 19:50:47 +05:30
|
|
|
return err
|
2022-10-06 20:13:30 +05:30
|
|
|
}
|
|
|
|
|
|
2025-04-28 19:50:47 +05:30
|
|
|
return zeus.PutMeters(ctx, usage.LicenseKey.String(), body)
|
2022-10-06 20:13:30 +05:30
|
|
|
}
|
2025-03-17 15:22:04 +05:30
|
|
|
|
2025-04-28 19:50:47 +05:30
|
|
|
func CheckoutSession(ctx context.Context, checkoutRequest *model.CheckoutRequest, licenseKey string, zeus zeus.Zeus) (string, error) {
|
|
|
|
|
body, err := json.Marshal(checkoutRequest)
|
2025-03-17 15:22:04 +05:30
|
|
|
if err != nil {
|
2025-04-28 19:50:47 +05:30
|
|
|
return "", err
|
2025-03-17 15:22:04 +05:30
|
|
|
}
|
|
|
|
|
|
2025-04-28 19:50:47 +05:30
|
|
|
response, err := zeus.GetCheckoutURL(ctx, licenseKey, body)
|
2025-03-17 15:22:04 +05:30
|
|
|
if err != nil {
|
2025-04-28 19:50:47 +05:30
|
|
|
return "", err
|
2025-03-17 15:22:04 +05:30
|
|
|
}
|
|
|
|
|
|
2025-04-28 19:50:47 +05:30
|
|
|
return gjson.GetBytes(response, "url").String(), nil
|
2025-03-17 15:22:04 +05:30
|
|
|
}
|
|
|
|
|
|
2025-04-28 19:50:47 +05:30
|
|
|
func PortalSession(ctx context.Context, portalRequest *model.PortalRequest, licenseKey string, zeus zeus.Zeus) (string, error) {
|
|
|
|
|
body, err := json.Marshal(portalRequest)
|
2025-03-17 15:22:04 +05:30
|
|
|
if err != nil {
|
2025-04-28 19:50:47 +05:30
|
|
|
return "", err
|
2025-03-17 15:22:04 +05:30
|
|
|
}
|
|
|
|
|
|
2025-04-28 19:50:47 +05:30
|
|
|
response, err := zeus.GetPortalURL(ctx, licenseKey, body)
|
2025-03-17 15:22:04 +05:30
|
|
|
if err != nil {
|
2025-04-28 19:50:47 +05:30
|
|
|
return "", err
|
2025-03-17 15:22:04 +05:30
|
|
|
}
|
|
|
|
|
|
2025-04-28 19:50:47 +05:30
|
|
|
return gjson.GetBytes(response, "url").String(), nil
|
2025-03-17 15:22:04 +05:30
|
|
|
}
|