github.com/coincircle/mattermost-server@v4.8.1-0.20180321182714-9d701c704416+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  
    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  	cmd.CommandPrettyPrintln("Uploaded license file")
    52  
    53  	return nil
    54  }