Skip to content

Commit

Permalink
Air-gapped mode (#926)
Browse files Browse the repository at this point in the history
  • Loading branch information
mieciu authored Oct 29, 2024
1 parent 1f434d4 commit e716c29
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion quesma/licensing/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package licensing

import (
"crypto/sha256"
"encoding/hex"
"fmt"
"github.com/google/uuid"
"github.com/rs/zerolog"
Expand All @@ -19,14 +21,33 @@ type LicenseModule struct {
}

const (
installationIdFile = ".installation_id"
installationIdFile = ".installation_id"
quesmaAirGapModeEnvVar = "QUESMA_AIRGAP_KEY"
)

func isAirgapKeyValid(key string) bool {
hasher := sha256.New()
hasher.Write([]byte(key))
keyHash := hex.EncodeToString(hasher.Sum(nil))
return keyHash == "78b14371a310f4e4f7e6c19a444f771bbe5d2c4f2154715191334bcf58420435"
}

func Init(config *config.QuesmaConfiguration) *LicenseModule {
l := &LicenseModule{
Config: config,
LicenseKey: []byte(config.LicenseKey),
}
if airgapKey, isSet := os.LookupEnv(quesmaAirGapModeEnvVar); isSet {
if isAirgapKeyValid(airgapKey) {
l.logInfo("Running Quesma in airgapped mode")
l.License = &License{
InstallationID: "air-gapped-installation-id",
ClientID: "air-gapped-client-id",
}
return l
}
}
l.logInfo("Initializing license module")
l.Run()
return l
}
Expand Down

0 comments on commit e716c29

Please sign in to comment.