mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-11-12 16:47:25 -05:00
AB#2299 License check in CLI during init (#366)
* license server interaction * logic to read from license file * print license information during init Signed-off-by: Fabian Kammel <fk@edgeless.systems> Co-authored-by: Moritz Eckert <m1gh7ym0@gmail.com>
This commit is contained in:
parent
170a8bf5e0
commit
82eb9f4544
8 changed files with 387 additions and 4 deletions
28
internal/license/file.go
Normal file
28
internal/license/file.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package license
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
|
||||
"github.com/edgelesssys/constellation/internal/file"
|
||||
)
|
||||
|
||||
func FromFile(fileHandler file.Handler, path string) (string, error) {
|
||||
readBytes, err := fileHandler.Read(path)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to read from '%s': %w", path, err)
|
||||
}
|
||||
|
||||
maxSize := base64.StdEncoding.DecodedLen(len(readBytes))
|
||||
decodedLicense := make([]byte, maxSize)
|
||||
n, err := base64.StdEncoding.Decode(decodedLicense, readBytes)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to base64 decode license file: %w", err)
|
||||
}
|
||||
if n != 36 { // length of UUID
|
||||
return "", fmt.Errorf("license file corrupt: wrong length")
|
||||
}
|
||||
decodedLicense = decodedLicense[:n]
|
||||
|
||||
return string(decodedLicense), nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue