param

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetParamCmd = &cobra.Command{
	Use:   "get <globalParameterName>",
	Short: "Get a global parameter by name from a data factory.",
	Run: func(cmd *cobra.Command, args []string) {
		var subscriptionId, resourceGroupName, factoryName = GetArgs(cmd, args)
		parameterGroupName := cmd.Flag("group").Value.String()
		globalParameterName := args[0]

		clientFactory, err := GetClientFactory(subscriptionId)
		if err != nil {
			log.Fatalf("failed to create client: %v", err)
		}

		ctx := context.Background()
		res, err := clientFactory.NewGlobalParametersClient().Get(ctx, resourceGroupName, factoryName, parameterGroupName, nil)
		if err != nil {
			log.Fatalf("failed to finish the request: %v", err)
		}

		if val, ok := res.Properties[globalParameterName]; !ok {
			log.Fatalf("Parameter %q not found in group %q", globalParameterName, parameterGroupName)
		} else {
			log.Printf("Parameter %q has type %s with value %q", globalParameterName, *val.Type, val.Value)
		}
	},
}

getCmd represents the get command

View Source
var ListParamCmd = &cobra.Command{
	Use:   "list <globalParameterName>",
	Short: "List all global parameters from a factory",
	Run: func(cmd *cobra.Command, args []string) {
		var subscriptionId, resourceGroupName, factoryName = GetArgs(cmd, args)

		clientFactory, err := GetClientFactory(subscriptionId)
		if err != nil {
			log.Fatalf("failed to create client: %v", err)
		}

		ctx := context.Background()
		pager := clientFactory.NewGlobalParametersClient().NewListByFactoryPager(resourceGroupName, factoryName, nil)
		for pager.More() {
			page, err := pager.NextPage(ctx)
			if err != nil {
				log.Fatalf("failed to advance page: %v", err)
			}
			for _, v := range page.Value {
				fmt.Printf("%q {\n", *v.Name)

				for k, v := range v.Properties {
					fmt.Printf("    %q: %q,\n", k, v.Value)
				}

				fmt.Println("}")
			}

		}
	},
}

getCmd represents the get command

View Source
var ParamCmd = &cobra.Command{
	Use: "param [command]",
	Run: func(cmd *cobra.Command, args []string) {

		fmt.Println("param needs a subcommand. Available subcommands are:")
		for _, cmd := range cmd.Commands() {
			fmt.Printf("  %s\n", cmd.Use)
		}
	},
}

triggerCmd represents the trigger command

View Source
var UpdateParamCmd = &cobra.Command{
	Use:   "update <globalParameterName>",
	Short: "Create or update a global parameter in a data factory",
	Args:  cobra.MinimumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		var subscriptionId, resourceGroupName, factoryName = GetArgs(cmd, args)

		var paramType *armdatafactory.GlobalParameterType
		switch tmp_type := cmd.Flag("type").Value.String(); tmp_type {
		case "int":
			paramType = to.Ptr(armdatafactory.GlobalParameterTypeInt)
		case "string":
			paramType = to.Ptr(armdatafactory.GlobalParameterTypeString)
		case "bool":
			paramType = to.Ptr(armdatafactory.GlobalParameterTypeBool)
		case "array":
			paramType = to.Ptr(armdatafactory.GlobalParameterTypeArray)
		default:
			log.Fatalf("Invalid parameter type")
		}

		paramValue := cmd.Flag("value").Value.String()
		paramGroup := cmd.Flag("group").Value.String()

		var globalParameterName = args[0]

		clientFactory, err := GetClientFactory(subscriptionId)
		if err != nil {
			log.Fatalf("failed to create client: %v", err)
		}

		ctx := context.Background()
		res, err := clientFactory.NewGlobalParametersClient().CreateOrUpdate(ctx, resourceGroupName, factoryName, paramGroup, armdatafactory.GlobalParameterResource{
			Properties: map[string]*armdatafactory.GlobalParameterSpecification{
				globalParameterName: {
					Type:  paramType,
					Value: paramValue,
				},
			},
		}, nil)
		if err != nil {
			log.Fatalf("failed to finish the request: %v", err)
		}

		_ = res

		log.Printf("Variable %q from group %q set to %q successfully", globalParameterName, paramGroup, paramValue)
	},
}

getCmd represents the get command

Functions

func GetArgs

func GetArgs(cmd *cobra.Command, args []string) (string, string, string)

Get the subscriptionId, resourceGroupName, and factoryName from the environment variables or command line flags. If the values are not set, the program will exit.

func GetClientFactory

func GetClientFactory(subscriptionId string) (*armdatafactory.ClientFactory, error)

Create a new client factory with the default Azure credential If the credential cannot be obtained, the program will exit.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL