license

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 6 Imported by: 0

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

View Source
const LicenseDirV1 = ".nself"

LicenseDirV1 is the v1 license directory name under $HOME.

View Source
const LicenseDirV2 = ".config/nself"

LicenseDirV2 is the v2 license directory name under $HOME.

View Source
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

func AddKey(key string) error

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

func GetKey() (string, error)

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

func MaskKey(key string) string

MaskKey returns a masked version of the key showing the first 10 and last 4 characters. Delegates to the existing maskKey function.

func MigrateLicenseFromV1

func MigrateLicenseFromV1(home string) error

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

func RemoveKey(query string) (int, error)

RemoveKey removes a key by prefix match or product name. Returns the number of keys removed.

func SetKey

func SetKey(key string) error

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

func SetKeyReplaceAll(key string) (int, error)

SetKeyReplaceAll replaces all stored keys with a single new key. Returns the number of keys that were replaced.

func ShowKey

func ShowKey() (masked string, tier string, err error)

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

func ValidateKeyFormat(key string) error

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

type ProductPrefix struct {
	Prefix      string
	Product     string
	DisplayName string
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL