-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathgateway_diff.go
More file actions
106 lines (96 loc) · 3.91 KB
/
gateway_diff.go
File metadata and controls
106 lines (96 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var (
diffCmdKongStateFile []string
diffCmdParallelism int
diffCmdNonZeroExitCode bool
diffWorkspace string
diffJSONOutput bool
)
func executeDiff(cmd *cobra.Command, _ []string) error {
return syncMain(cmd.Context(), diffCmdKongStateFile, true,
diffCmdParallelism, 0, diffWorkspace, diffJSONOutput, false)
}
// newDiffCmd represents the diff command
func newDiffCmd(deprecated bool) *cobra.Command {
use := "diff [flags] [kong-state-files...]"
short := "Diff the current entities in Kong with the one on disks"
execute := executeDiff
argsValidator := cobra.MinimumNArgs(0)
preRun := func(_ *cobra.Command, args []string) error {
diffCmdKongStateFile = args
if len(diffCmdKongStateFile) == 0 {
diffCmdKongStateFile = []string{"-"}
}
return preRunSilenceEventsFlag()
}
if deprecated {
use = "diff"
short = "[deprecated] see 'deck gateway diff --help' for changes to the command"
execute = func(cmd *cobra.Command, args []string) error {
fmt.Fprintf(os.Stderr, "Info: 'deck diff' functionality has moved to 'deck gateway diff' and will be removed\n"+
"in a future MAJOR version of deck. Migration to 'deck gateway diff' is recommended.\n"+
" Note: - see 'deck gateway diff --help' for changes to the command\n"+
" - files changed to positional arguments without the '-s/--state' flag\n"+
" - the default changed from 'kong.yaml' to '-' (stdin/stdout)\n")
return executeDiff(cmd, args)
}
argsValidator = validateNoArgs
preRun = func(_ *cobra.Command, _ []string) error {
if len(diffCmdKongStateFile) == 0 {
return fmt.Errorf("a state file with Kong's configuration " +
"must be specified using `-s`/`--state` flag")
}
return preRunSilenceEventsFlag()
}
}
diffCmd := &cobra.Command{
Use: use,
Short: short,
Long: `The diff command is similar to a dry run of the 'decK kong sync' command.
It loads entities from Kong and performs a diff with
the entities in local files. This allows you to see the entities
that will be created, updated, or deleted.
`,
Args: argsValidator,
RunE: execute,
PreRunE: preRun,
}
if deprecated {
diffCmd.Flags().StringSliceVarP(&diffCmdKongStateFile,
"state", "s", []string{"kong.yaml"}, "file(s) containing Kong's configuration.\n"+
"This flag can be specified multiple times for multiple files.\n"+
"Use `-` to read from stdin.")
}
diffCmd.Flags().StringVarP(&diffWorkspace, "workspace", "w",
"", "Diff configuration with a specific workspace "+
"(Kong Enterprise only).\n"+
"This takes precedence over _workspace fields in state files.")
diffCmd.Flags().BoolVar(&dumpConfig.SkipConsumers, "skip-consumers",
false, "do not diff consumers or "+
"any plugins associated with consumers")
diffCmd.Flags().IntVar(&diffCmdParallelism, "parallelism",
10, "Maximum number of concurrent operations.")
diffCmd.Flags().BoolVar(&noMaskValues, "no-mask-deck-env-vars-value",
false, "do not mask DECK_ environment variable values at diff output.")
diffCmd.Flags().StringSliceVar(&dumpConfig.SelectorTags,
"select-tag", []string{},
"only entities matching tags specified via this flag are diffed.\n"+
"When this setting has multiple tag values, entities must match each of them.")
diffCmd.Flags().BoolVar(&dumpConfig.RBACResourcesOnly, "rbac-resources-only",
false, "sync only the RBAC resources (Kong Enterprise only).")
diffCmd.Flags().BoolVar(&diffCmdNonZeroExitCode, "non-zero-exit-code",
false, "return exit code 2 if there is a diff present,\n"+
"exit code 0 if no diff is found,\n"+
"and exit code 1 if an error occurs.")
diffCmd.Flags().BoolVar(&dumpConfig.SkipCACerts, "skip-ca-certificates",
false, "do not diff CA certificates.")
diffCmd.Flags().BoolVar(&diffJSONOutput, "json-output",
false, "generate command execution report in a JSON format")
addSilenceEventsFlag(diffCmd.Flags())
return diffCmd
}