github.com/dschalla/mattermost-server@v4.8.1-rc1+incompatible/cmd/platform/license.go (about)

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