github.com/iDevoid/mattermost-server@v5.11.1+incompatible/cmd/mattermost/commands/license.go (about)

     1  // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package commands
     5  
     6  import (
     7  	"errors"
     8  	"io/ioutil"
     9  
    10  	"github.com/spf13/cobra"
    11  )
    12  
    13  var LicenseCmd = &cobra.Command{
    14  	Use:   "license",
    15  	Short: "Licensing commands",
    16  }
    17  
    18  var UploadLicenseCmd = &cobra.Command{
    19  	Use:     "upload [license]",
    20  	Short:   "Upload a license.",
    21  	Long:    "Upload a license. Replaces current license.",
    22  	Example: "  license upload /path/to/license/mylicensefile.mattermost-license",
    23  	RunE:    uploadLicenseCmdF,
    24  }
    25  
    26  func init() {
    27  	LicenseCmd.AddCommand(UploadLicenseCmd)
    28  	RootCmd.AddCommand(LicenseCmd)
    29  }
    30  
    31  func uploadLicenseCmdF(command *cobra.Command, args []string) error {
    32  	a, err := InitDBCommandContextCobra(command)
    33  	if err != nil {
    34  		return err
    35  	}
    36  	defer a.Shutdown()
    37  
    38  	if len(args) != 1 {
    39  		return errors.New("Enter one license file to upload")
    40  	}
    41  
    42  	var fileBytes []byte
    43  	if fileBytes, err = ioutil.ReadFile(args[0]); err != nil {
    44  		return err
    45  	}
    46  
    47  	if _, err := a.SaveLicense(fileBytes); err != nil {
    48  		return err
    49  	}
    50  
    51  	CommandPrettyPrintln("Uploaded license file")
    52  
    53  	return nil
    54  }