github.com/minio/console@v1.4.1/api/license.go (about)

     1  // This file is part of MinIO Console Server
     2  // Copyright (c) 2023 MinIO, Inc.
     3  //
     4  // This program is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Affero General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // This program is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  // GNU Affero General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Affero General Public License
    15  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package api
    18  
    19  import (
    20  	"net/http"
    21  	"os"
    22  
    23  	"github.com/minio/pkg/v3/licverifier"
    24  	"github.com/minio/pkg/v3/subnet"
    25  )
    26  
    27  type SubnetPlan int
    28  
    29  const (
    30  	PlanAGPL SubnetPlan = iota
    31  	PlanStandard
    32  	PlanEnterprise
    33  )
    34  
    35  func (sp SubnetPlan) String() string {
    36  	switch sp {
    37  	case PlanStandard:
    38  		return "standard"
    39  	case PlanEnterprise:
    40  		return "enterprise"
    41  	default:
    42  		return "agpl"
    43  	}
    44  }
    45  
    46  var InstanceLicensePlan = PlanAGPL
    47  
    48  func getLicenseInfo(client http.Client, license string) (*licverifier.LicenseInfo, error) {
    49  	lv := subnet.LicenseValidator{
    50  		Client:            client,
    51  		ExpiryGracePeriod: 0,
    52  	}
    53  	lv.Init(getConsoleDevMode())
    54  	return lv.ParseLicense(license)
    55  }
    56  
    57  func fetchLicensePlan() {
    58  	client := GetConsoleHTTPClient("127.0.0.1")
    59  	licenseInfo, err := getLicenseInfo(*client, os.Getenv(EnvSubnetLicense))
    60  	if err != nil {
    61  		return
    62  	}
    63  	switch licenseInfo.Plan {
    64  	case "STANDARD":
    65  		InstanceLicensePlan = PlanStandard
    66  	case "ENTERPRISE":
    67  		InstanceLicensePlan = PlanEnterprise
    68  	default:
    69  		InstanceLicensePlan = PlanAGPL
    70  	}
    71  }