Example #1
0
func main() {
	// If not set for some reason, use us-east-1 by default.
	if discfgDBRegion == "" {
		discfgDBRegion = "us-east-1"
	}

	apex.HandleFunc(func(event json.RawMessage, ctx *apex.Context) (interface{}, error) {
		var m message

		if err := json.Unmarshal(event, &m); err != nil {
			return nil, err
		}

		options.Storage.AWS.Region = discfgDBRegion

		if m.Name != "" {
			options.CfgName = m.Name
		}

		var settings map[string]interface{}
		err := json.Unmarshal([]byte(m.Settings), &settings)
		if err != nil {
			return nil, err
		}

		resp := commands.CreateCfg(options, settings)

		return commands.FormatJSONValue(resp), nil
	})
}
Example #2
0
	Long:  `Creates a new discfg distributed configuration`,
	Run: func(cmd *cobra.Command, args []string) {
		var settings map[string]interface{}
		switch len(args) {
		case 1:
			settings = map[string]interface{}{}
			Options.CfgName = args[0]
			break
		case 2:
			Options.CfgName = args[0]
			if err := json.Unmarshal([]byte(args[0]), &settings); err != nil {
				commands.Out(Options, config.ResponseObject{Action: "create", Error: err.Error()})
			}
		}

		resp := commands.CreateCfg(Options, settings)
		commands.Out(Options, resp)
	},
}
var deleteCfgCmd = &cobra.Command{
	Use:   "delete",
	Short: "delete config",
	Long:  `Deletes a discfg distributed configuration`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) > 0 {
			Options.CfgName = args[0]
			// Confirmation
			inputReader := bufio.NewReader(os.Stdin)
			cfgCmd.Print("Are you sure? [Y/n] ")
			input, _ := inputReader.ReadString('\n')
			if input != "Y\n" {