settings

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var ApplyCmd = &cobra.Command{
	Use:   "apply [path]",
	Short: "Add NoCloud Setting",
	Long: `Add NoCloud Setting from yaml/json config, like:
key: setting_key
value: some value
description: Just a setting Key
public: setting visibility for non-root accounts
`,
	Args: cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		var format string
		{
			pathSlice := strings.Split(args[0], ".")
			format = pathSlice[len(pathSlice)-1]
		}
		template, err := os.ReadFile(args[0])
		switch format {
		case "json":
		case "yml", "yaml":
			template, err = yaml.YAMLToJSON(template)
		default:
			return errors.New("Unsupported template format " + format)
		}
		if err != nil {
			fmt.Println("Error while parsing template")
			return err
		}

		var request pb.PutRequest
		err = json.Unmarshal(template, &request)
		if err != nil {
			fmt.Println("Error while parsing template")
			return err
		}

		ctx, client := MakeSettingsServiceClientOrFail()
		res, err := client.Put(ctx, &request)
		if err != nil {
			return err
		}

		if printJson, _ := cmd.Flags().GetBool("json"); printJson {
			data, err := json.Marshal(res)
			if err != nil {
				return err
			}
			fmt.Println(string(data))
		} else {
			fmt.Println("Added:", res.GetKey())
		}

		return nil
	},
}

ApplyCmd represents the list command

View Source
var GetCmd = &cobra.Command{
	Use:   "get [...keys]",
	Short: "Get NoCloud Settings",
	Args:  cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, client := MakeSettingsServiceClientOrFail()
		request := pb.GetRequest{
			Keys: args,
		}

		res, err := client.Get(ctx, &request)

		if err != nil {
			return err
		}

		result := res.AsMap()
		if printJson, _ := cmd.Flags().GetBool("json"); printJson {
			data, err := json.Marshal(result)
			if err != nil {
				return err
			}
			fmt.Println(string(data))
		} else {
			data, err := yaml.Marshal(result)
			if err != nil {
				return err
			}
			fmt.Print(string(data))
		}

		return nil
	},
}

GetCmd represents the list command

View Source
var ListCmd = &cobra.Command{
	Use:   "list",
	Short: "List NoCloud Settings Keys",
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, client := MakeSettingsServiceClientOrFail()
		request := pb.KeysRequest{}

		res, err := client.Keys(ctx, &request)

		if err != nil {
			return err
		}

		if printJson, _ := cmd.Flags().GetBool("json"); printJson {
			data, err := json.Marshal(res)
			if err != nil {
				return err
			}
			fmt.Println(string(data))
		} else {
			PrintKeys(res)
		}

		return nil
	},
}

ListCmd represents the list command

Functions

func MakeSettingsServiceClientOrFail

func MakeSettingsServiceClientOrFail() (context.Context, pb.SettingsServiceClient)

func PrintKeys

func PrintKeys(res *pb.KeysResponse)

Types

This section is empty.

Jump to

Keyboard shortcuts

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