github.com/spline-fu/mattermost-server@v4.10.10+incompatible/cmd/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/mattermost/mattermost-server/cmd"
    11  	"github.com/spf13/cobra"
    12  )
    13  
    14  var LicenseCmd = &cobra.Command{
    15  	Use:   "license",
    16  	Short: "Licensing commands",
    17  }
    18  
    19  var UploadLicenseCmd = &cobra.Command{
    20  	Use:     "upload [license]",
    21  	Short:   "Upload a license.",
    22  	Long:    "Upload a license. Replaces current license.",
    23  	Example: "  license upload /path/to/license/mylicensefile.mattermost-license",
    24  	RunE:    uploadLicenseCmdF,
    25  }
    26  
    27  func init() {
    28  	LicenseCmd.AddCommand(UploadLicenseCmd)
    29  	cmd.RootCmd.AddCommand(LicenseCmd)
    30  }
    31  
    32  func uploadLicenseCmdF(command *cobra.Command, args []string) error {
    33  	a, err := cmd.InitDBCommandContextCobra(command)
    34  	if err != nil {
    35  		return err
    36  	}
    37  	defer a.Shutdown()
    38  
    39  	if len(args) != 1 {
    40  		return errors.New("Enter one license file to upload")
    41  	}
    42  
    43  	var fileBytes []byte
    44  	if fileBytes, err = ioutil.ReadFile(args[0]); err != nil {
    45  		return err
    46  	}
    47  
    48  	if _, err := a.SaveLicense(fileBytes); err != nil {
    49  		return err
    50  	}
    51  
    52  	cmd.CommandPrettyPrintln("Uploaded license file")
    53  
    54  	return nil
    55  }