33package licensing
44
55import (
6- "bytes"
76 "fmt"
8- "github.com/goccy/go-json"
9- "io"
10- "net/http"
11- "time"
127)
138
14- const (
15- obtainLicenseEndpoint = "https://licensing.quesma.com/api/license/obtain"
16- verifyLicenseEndpoint = "https://licensing.quesma.com/api/license/verify"
17- )
9+ // const (
10+ // obtainLicenseEndpoint = "https://licensing.quesma.com/api/license/obtain"
11+ // verifyLicenseEndpoint = "https://licensing.quesma.com/api/license/verify"
12+ // )
1813
1914type InstallationIDPayload struct {
2015 InstallationID string `json:"installation_id"`
@@ -25,31 +20,31 @@ type LicensePayload struct {
2520}
2621
2722// obtainLicenseKey presents an InstallationId to the license server and receives a LicenseKey in return
28- func (l * LicenseModule ) obtainLicenseKey () (err error ) {
29- l .logDebug ("Obtaining license key for installation ID [%s]" , l .InstallationID )
30- var payloadBytes []byte
31- if payloadBytes , err = json .Marshal (InstallationIDPayload {InstallationID : l .InstallationID }); err != nil {
32- return err
33- }
34- resp , err := http .Post (obtainLicenseEndpoint , "application/json" , bytes .NewReader (payloadBytes ))
35- if err != nil {
36- return err
37- }
38- defer resp .Body .Close ()
39-
40- body , err := io .ReadAll (resp .Body )
41- if err != nil {
42- return err
43- }
44-
45- var licenseResponse LicensePayload
46- if err = json .Unmarshal (body , & licenseResponse ); err != nil {
47- return err
48- }
49- l .LicenseKey = []byte (licenseResponse .LicenseKey )
50- fmt .Printf ("License key obtained and set successfully, key=[%s.....%s]\n " , string (l .LicenseKey [:8 ]), string (l .LicenseKey [len (l .LicenseKey )- 8 :]))
51- return nil
52- }
23+ // func (l *LicenseModule) obtainLicenseKey() (err error) {
24+ // l.logDebug("Obtaining license key for installation ID [%s]", l.InstallationID)
25+ // var payloadBytes []byte
26+ // if payloadBytes, err = json.Marshal(InstallationIDPayload{InstallationID: l.InstallationID}); err != nil {
27+ // return err
28+ // }
29+ // resp, err := http.Post(obtainLicenseEndpoint, "application/json", bytes.NewReader(payloadBytes))
30+ // if err != nil {
31+ // return err
32+ // }
33+ // defer resp.Body.Close()
34+ //
35+ // body, err := io.ReadAll(resp.Body)
36+ // if err != nil {
37+ // return err
38+ // }
39+ //
40+ // var licenseResponse LicensePayload
41+ // if err = json.Unmarshal(body, &licenseResponse); err != nil {
42+ // return err
43+ // }
44+ // l.LicenseKey = []byte(licenseResponse.LicenseKey)
45+ // fmt.Printf("License key obtained and set successfully, key=[%s.....%s]\n", string(l.LicenseKey[:8]), string(l.LicenseKey[len(l.LicenseKey)-8:]))
46+ // return nil
47+ // }
5348
5449func FormatLicenseKey (licenseKey []byte ) string {
5550 if len (licenseKey ) < 8 { // too short to be obfuscated, most probably it's invalid anyway
@@ -59,41 +54,41 @@ func FormatLicenseKey(licenseKey []byte) string {
5954}
6055
6156// processLicense presents the license to the license server and receives an AllowList in return
62- func (l * LicenseModule ) processLicense () error {
63- if fetchedLicense , err := l .fetchLicense (); err != nil {
64- return fmt .Errorf ("license validation failed with: %v" , err )
65- } else {
66- l .License = fetchedLicense
67- l .logDebug ("Allowlist loaded successfully" )
68- l .logDebug ("%s" , fetchedLicense .String ())
69- }
70- if l .License .ExpirationDate .Before (time .Now ()) {
71- return fmt .Errorf ("license expired on %s" , l .License .ExpirationDate )
72- }
73- return nil
74- }
57+ // func (l *LicenseModule) processLicense() error {
58+ // if fetchedLicense, err := l.fetchLicense(); err != nil {
59+ // return fmt.Errorf("license validation failed with: %v", err)
60+ // } else {
61+ // l.License = fetchedLicense
62+ // l.logDebug("Allowlist loaded successfully")
63+ // l.logDebug("%s", fetchedLicense.String())
64+ // }
65+ // if l.License.ExpirationDate.Before(time.Now()) {
66+ // return fmt.Errorf("license expired on %s", l.License.ExpirationDate)
67+ // }
68+ // return nil
69+ // }
7570
76- func (l * LicenseModule ) fetchLicense () (a * License , err error ) {
77- var payloadBytes []byte
78- if payloadBytes , err = json .Marshal (LicensePayload {LicenseKey : string (l .LicenseKey )}); err != nil {
79- return nil , err
80- }
81- resp , err := http .Post (verifyLicenseEndpoint , "application/json" , bytes .NewReader (payloadBytes ))
82- if resp .StatusCode == http .StatusUnauthorized {
83- return nil , fmt .Errorf ("license key rejected by the License server" )
84- }
85- if err != nil {
86- return nil , err
87- }
88- defer resp .Body .Close ()
89- body , err := io .ReadAll (resp .Body )
90- if err != nil {
91- return nil , err
92- }
93-
94- if err = json .Unmarshal (body , & a ); err != nil {
95- return nil , err
96- } else {
97- return a , nil
98- }
99- }
71+ // func (l *LicenseModule) fetchLicense() (a *License, err error) {
72+ // var payloadBytes []byte
73+ // if payloadBytes, err = json.Marshal(LicensePayload{LicenseKey: string(l.LicenseKey)}); err != nil {
74+ // return nil, err
75+ // }
76+ // resp, err := http.Post(verifyLicenseEndpoint, "application/json", bytes.NewReader(payloadBytes))
77+ // if resp.StatusCode == http.StatusUnauthorized {
78+ // return nil, fmt.Errorf("license key rejected by the License server")
79+ // }
80+ // if err != nil {
81+ // return nil, err
82+ // }
83+ // defer resp.Body.Close()
84+ // body, err := io.ReadAll(resp.Body)
85+ // if err != nil {
86+ // return nil, err
87+ // }
88+ //
89+ // if err = json.Unmarshal(body, &a); err != nil {
90+ // return nil, err
91+ // } else {
92+ // return a, nil
93+ // }
94+ // }
0 commit comments