github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ccl/cliccl/start.go (about)

     1  // Copyright 2017 The Cockroach Authors.
     2  //
     3  // Licensed as a CockroachDB Enterprise file under the Cockroach Community
     4  // License (the "License"); you may not use this file except in compliance with
     5  // the License. You may obtain a copy of the License at
     6  //
     7  //     https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt
     8  
     9  package cliccl
    10  
    11  import (
    12  	"github.com/cockroachdb/cockroach/pkg/ccl/baseccl"
    13  	"github.com/cockroachdb/cockroach/pkg/ccl/cliccl/cliflagsccl"
    14  	"github.com/cockroachdb/cockroach/pkg/cli"
    15  	"github.com/spf13/cobra"
    16  )
    17  
    18  // This does not define a `start` command, only modifications to the existing command
    19  // in `pkg/cli/start.go`.
    20  
    21  var storeEncryptionSpecs baseccl.StoreEncryptionSpecList
    22  
    23  func init() {
    24  	for _, cmd := range cli.StartCmds {
    25  		cli.VarFlag(cmd.Flags(), &storeEncryptionSpecs, cliflagsccl.EnterpriseEncryption)
    26  
    27  		// Add a new pre-run command to match encryption specs to store specs.
    28  		cli.AddPersistentPreRunE(cmd, func(cmd *cobra.Command, _ []string) error {
    29  			return populateStoreSpecsEncryption()
    30  		})
    31  	}
    32  }
    33  
    34  // populateStoreSpecsEncryption is a PreRun hook that matches store encryption specs with the
    35  // parsed stores and populates some fields in the StoreSpec.
    36  func populateStoreSpecsEncryption() error {
    37  	return baseccl.PopulateStoreSpecWithEncryption(cli.GetServerCfgStores(), storeEncryptionSpecs)
    38  }