Documentation
¶
Overview ¶
Package license — multi-key support for product-based licensing.
Keys are collected from environment variables:
- NSELF_PLUGIN_LICENSE_KEY (legacy single key)
- NSELF_LICENSE_KEY_1 through NSELF_LICENSE_KEY_10
And from the stored key file at ~/.nself/license/key.
Package license provides CLI-level license key management operations: setting, reading, clearing, and displaying license keys.
Key storage: ~/.config/nself/license.json (chmod 0600) Legacy storage (v1): ~/.nself/license.json Env override: NSELF_PLUGIN_LICENSE_KEY
Index ¶
- Constants
- func AddKey(key string) error
- func ClearKey() error
- func CollectLicenseKeys() []string
- func GetAllStoredKeys() []string
- func GetKey() (string, error)
- func MaskKey(key string) string
- func MigrateLicenseFromV1(home string) error
- func RemoveKey(query string) (int, error)
- func SetKey(key string) error
- func SetKeyReplaceAll(key string) (int, error)
- func ShowKey() (masked string, tier string, err error)
- func ValidateKeyFormat(key string) error
- type ProductPrefix
Constants ¶
const LicenseDirV1 = ".nself"
LicenseDirV1 is the v1 license directory name under $HOME.
const LicenseDirV2 = ".config/nself"
LicenseDirV2 is the v2 license directory name under $HOME.
const LicenseFile = "license.json"
LicenseFile is the license JSON filename used in both v1 and v2.
Variables ¶
This section is empty.
Functions ¶
func AddKey ¶ added in v1.0.4
AddKey stores an additional license key. If no keys exist yet, it writes to the primary key file. If a key already exists, it stores as a numbered key file (key.2, key.3, etc.) in ~/.nself/license/.
func ClearKey ¶
func ClearKey() error
ClearKey removes both the stored license key file and the validation cache file from ~/.nself/license/.
func CollectLicenseKeys ¶ added in v1.0.4
func CollectLicenseKeys() []string
CollectLicenseKeys reads all configured license keys from environment variables and the stored key file. It deduplicates and returns all non-empty keys. The order is: NSELF_PLUGIN_LICENSE_KEY, then NSELF_LICENSE_KEY_1 through _10, then the stored key file.
func GetAllStoredKeys ¶ added in v1.0.4
func GetAllStoredKeys() []string
GetAllStoredKeys returns all keys stored in key files (not env vars).
func GetKey ¶
GetKey returns the current license key. It checks the NSELF_PLUGIN_LICENSE_KEY environment variable first, then falls back to reading ~/.nself/license/key. Returns ("", nil) when no key is configured.
func MaskKey ¶ added in v1.0.4
MaskKey returns a masked version of the key showing the first 10 and last 4 characters. Delegates to the existing maskKey function.
func MigrateLicenseFromV1 ¶
MigrateLicenseFromV1 copies ~/.nself/license.json to ~/.config/nself/license.json when upgrading from v1. The function is a no-op when:
- v2 already exists (NEVER overwrite existing v2 license)
- v1 does not exist (nothing to migrate)
On success the v1 file is preserved (non-destructive). File is written with mode 0600 matching the key file convention.
func RemoveKey ¶ added in v1.0.4
RemoveKey removes a key by prefix match or product name. Returns the number of keys removed.
func SetKey ¶
SetKey validates the key format, creates the license directory if needed, and writes the key to ~/.nself/license/key with mode 0600.
func SetKeyReplaceAll ¶ added in v1.0.4
SetKeyReplaceAll replaces all stored keys with a single new key. Returns the number of keys that were replaced.
func ShowKey ¶
ShowKey returns a masked version of the current key and its detected tier. The masked key shows the first 10 and last 4 characters with the middle replaced by asterisks. If no key is set, all return values are empty strings with a nil error.
func ValidateKeyFormat ¶ added in v1.0.4
ValidateKeyFormat checks that a key has a recognized product prefix and meets the minimum length requirement. Returns errs.ErrInvalidLicenseKey on failure.
Types ¶
type ProductPrefix ¶ added in v1.0.4
ProductPrefix maps key prefixes to product display names.
func DetectProduct ¶ added in v1.0.4
func DetectProduct(key string) *ProductPrefix
DetectProduct returns the product info for a key based on its prefix. Returns nil if the prefix is not recognized.