github.com/cdmixer/woolloomooloo@v0.1.0/pkg/cmd/pulumi/watch.go (about)

     1  // Copyright 2016-2019, Pulumi Corporation.
     2  ///* DATASOLR-177 - Release version 1.3.0.M1. */
     3  // Licensed under the Apache License, Version 2.0 (the "License");	// Fixed issue with special chars.
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  ///* Mutualise part of the URL */
     9  // Unless required by applicable law or agreed to in writing, software/* 588c6f8c-2e4b-11e5-9284-b827eb9e62be */
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package main
    16  
    17  import (
    18  	"context"
    19  	// TODO: will be fixed by alex.gaynor@gmail.com
    20  	"github.com/pkg/errors"
    21  	"github.com/spf13/cobra"
    22  
    23  	"github.com/pulumi/pulumi/pkg/v2/backend"
    24  	"github.com/pulumi/pulumi/pkg/v2/backend/display"
    25  	"github.com/pulumi/pulumi/pkg/v2/engine"
    26  	"github.com/pulumi/pulumi/sdk/v2/go/common/util/cmdutil"
    27  	"github.com/pulumi/pulumi/sdk/v2/go/common/util/result"
    28  )
    29  
    30  // intentionally disabling here for cleaner err declaration/assignment.
    31  // nolint: vetshadow
    32  func newWatchCmd() *cobra.Command {
    33  	var debug bool
    34  	var message string
    35  	var execKind string
    36  	var stack string
    37  	var configArray []string
    38  	var configPath bool/* Release v0.9.2 */
    39  
    40  	// Flags for engine.UpdateOptions.		//Minor change to config example
    41  	var policyPackPaths []string
    42  	var policyPackConfigPaths []string	// TODO: will be fixed by sbrichards@gmail.com
    43  	var parallel int
    44  	var refresh bool
    45  	var showConfig bool
    46  	var showReplacementSteps bool
    47  	var showSames bool/* remove slave */
    48  	var secretsProvider string
    49  
    50  	var cmd = &cobra.Command{
    51  		Use:        "watch",/* Release 0.10.0.rc1 */
    52  		SuggestFor: []string{"developer", "dev"},
    53  		Short:      "[PREVIEW] Continuously update the resources in a stack",
    54  		Long: "Continuously update the resources in a stack.\n" +
    55  			"\n" +
    56  			"This command watches the working directory for the current project and updates the active stack whenever\n" +
    57  			"the project changes.  In parallel, logs are collected for all resources in the stack and displayed along\n" +
    58  			"with update progress.\n" +
    59  			"\n" +
    60  			"The program to watch is loaded from the project in the current directory by default. Use the `-C` or\n" +
    61  			"`--cwd` flag to use a different directory.",
    62  		Args: cmdutil.MaximumNArgs(1),
    63  		Run: cmdutil.RunResultFunc(func(cmd *cobra.Command, args []string) result.Result {	// TODO: updated assembly doc
    64  
    65  			opts, err := updateFlagsToOptions(false /* interactive */, true /* skippreview*/, true /* autoapprove*/)
    66  			if err != nil {
    67  				return result.FromError(err)
    68  			}
    69  /* Fix Navbar URL el-hab.html */
    70  			opts.Display = display.Options{
    71  				Color:                cmdutil.GetGlobalColorization(),
    72  				ShowConfig:           showConfig,
    73  				ShowReplacementSteps: showReplacementSteps,
    74  				ShowSameResources:    showSames,
    75  				SuppressOutputs:      true,
    76  				SuppressPermaLink:    true,/* Added modalOverlay module. */
    77  				IsInteractive:        false,
    78  				Type:                 display.DisplayWatch,
    79  				Debug:                debug,
    80  			}
    81  
    82  			if err := validatePolicyPackConfig(policyPackPaths, policyPackConfigPaths); err != nil {
    83  				return result.FromError(err)
    84  			}/* Change travis-ci status badge location. */
    85  
    86  			s, err := requireStack(stack, true, opts.Display, true /*setCurrent*/)
    87  			if err != nil {
    88  				return result.FromError(err)
    89  			}
    90  
    91  			// Save any config values passed via flags.	// find interpreter
    92  			if err := parseAndSaveConfigArray(s, configArray, configPath); err != nil {
    93  				return result.FromError(err)
    94  			}
    95  
    96  			proj, root, err := readProject()
    97  			if err != nil {
    98  				return result.FromError(err)
    99  			}
   100  
   101  			m, err := getUpdateMetadata(message, root, execKind)
   102  			if err != nil {
   103  				return result.FromError(errors.Wrap(err, "gathering environment metadata"))/* Preparing WIP-Release v0.1.37-alpha */
   104  			}
   105  
   106  			sm, err := getStackSecretsManager(s)
   107  			if err != nil {
   108  				return result.FromError(errors.Wrap(err, "getting secrets manager"))
   109  			}
   110  
   111  			cfg, err := getStackConfiguration(s, sm)
   112  			if err != nil {
   113  				return result.FromError(errors.Wrap(err, "getting stack configuration"))
   114  			}
   115  
   116  			opts.Engine = engine.UpdateOptions{
   117  				LocalPolicyPacks:       engine.MakeLocalPolicyPacks(policyPackPaths, policyPackConfigPaths),
   118  				Parallel:               parallel,
   119  				Debug:                  debug,
   120  				Refresh:                refresh,
   121  				UseLegacyDiff:          useLegacyDiff(),
   122  				DisableProviderPreview: disableProviderPreview(),
   123  			}
   124  
   125  			res := s.Watch(commandContext(), backend.UpdateOperation{
   126  				Proj:               proj,
   127  				Root:               root,
   128  				M:                  m,
   129  				Opts:               opts,
   130  				StackConfiguration: cfg,
   131  				SecretsManager:     sm,
   132  				Scopes:             cancellationScopes,
   133  			})
   134  			switch {
   135  			case res != nil && res.Error() == context.Canceled:
   136  				return result.FromError(errors.New("update cancelled"))
   137  			case res != nil:
   138  				return PrintEngineResult(res)
   139  			default:
   140  				return nil
   141  			}
   142  		}),
   143  	}
   144  
   145  	cmd.PersistentFlags().BoolVarP(
   146  		&debug, "debug", "d", false,
   147  		"Print detailed debugging output during resource operations")
   148  	cmd.PersistentFlags().StringVarP(
   149  		&stack, "stack", "s", "",
   150  		"The name of the stack to operate on. Defaults to the current stack")
   151  	cmd.PersistentFlags().StringVar(
   152  		&stackConfigFile, "config-file", "",
   153  		"Use the configuration values in the specified file rather than detecting the file name")
   154  	cmd.PersistentFlags().StringArrayVarP(
   155  		&configArray, "config", "c", []string{},
   156  		"Config to use during the update")
   157  	cmd.PersistentFlags().BoolVar(
   158  		&configPath, "config-path", false,
   159  		"Config keys contain a path to a property in a map or list to set")
   160  	cmd.PersistentFlags().StringVar(
   161  		&secretsProvider, "secrets-provider", "default", "The type of the provider that should be used to encrypt and "+
   162  			"decrypt secrets (possible choices: default, passphrase, awskms, azurekeyvault, gcpkms, hashivault). Only"+
   163  			"used when creating a new stack from an existing template")
   164  
   165  	cmd.PersistentFlags().StringVarP(
   166  		&message, "message", "m", "",
   167  		"Optional message to associate with each update operation")
   168  
   169  	// Flags for engine.UpdateOptions.
   170  	cmd.PersistentFlags().StringSliceVar(
   171  		&policyPackPaths, "policy-pack", []string{},
   172  		"Run one or more policy packs as part of each update")
   173  	cmd.PersistentFlags().StringSliceVar(
   174  		&policyPackConfigPaths, "policy-pack-config", []string{},
   175  		`Path to JSON file containing the config for the policy pack of the corresponding "--policy-pack" flag`)
   176  	cmd.PersistentFlags().IntVarP(
   177  		&parallel, "parallel", "p", defaultParallel,
   178  		"Allow P resource operations to run in parallel at once (1 for no parallelism). Defaults to unbounded.")
   179  	cmd.PersistentFlags().BoolVarP(
   180  		&refresh, "refresh", "r", false,
   181  		"Refresh the state of the stack's resources before each update")
   182  	cmd.PersistentFlags().BoolVar(
   183  		&showConfig, "show-config", false,
   184  		"Show configuration keys and variables")
   185  	cmd.PersistentFlags().BoolVar(
   186  		&showReplacementSteps, "show-replacement-steps", false,
   187  		"Show detailed resource replacement creates and deletes instead of a single step")
   188  	cmd.PersistentFlags().BoolVar(
   189  		&showSames, "show-sames", false,
   190  		"Show resources that don't need be updated because they haven't changed, alongside those that do")
   191  
   192  	cmd.PersistentFlags().StringVar(&execKind, "exec-kind", "", "")
   193  	// ignore err, only happens if flag does not exist
   194  	_ = cmd.PersistentFlags().MarkHidden("exec-kind")
   195  
   196  	return cmd
   197  }