-
Notifications
You must be signed in to change notification settings - Fork 88
/
platform_license.go
45 lines (37 loc) · 1023 Bytes
/
platform_license.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package handlers
import (
"encoding/json"
"net/http"
"os"
"github.com/replicatedhq/kots/pkg/kotsadmlicense"
"github.com/replicatedhq/kots/pkg/logger"
)
const (
DefaultAPIEndpoint = "https://replicated.app"
)
type ExchangePlatformLicenseRequest struct {
LicenseData string `json:"licenseData"`
}
type ExchangePlatformLicenseResponse struct {
LicenseData string `json:"licenseData"`
}
func (h *Handler) ExchangePlatformLicense(w http.ResponseWriter, r *http.Request) {
request := ExchangePlatformLicenseRequest{}
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
logger.Error(err)
w.WriteHeader(400)
return
}
apiEndpoint := os.Getenv("REPLICATED_API_ENDPOINT")
if apiEndpoint == "" {
apiEndpoint = DefaultAPIEndpoint
}
kotsLicenseData, err := license.GetFromPlatformLicense(apiEndpoint, request.LicenseData)
if err != nil {
logger.Error(err)
w.WriteHeader(500)
return
}
response := ExchangePlatformLicenseResponse{LicenseData: kotsLicenseData}
JSON(w, 200, response)
}