account

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: 15 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.

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 CreateCmd = &cobra.Command{
	Use:     "create [title] [namespace UUID] [flags]",
	Aliases: []string{"crt", "c"},
	Short:   "Create NoCloud Account",
	Long:    "Authorization data flags must be given('auth-type', 'auth-data')",
	Args:    cobra.MinimumNArgs(2),
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, client := MakeAccountsServiceClientOrFail()

		authType, _ := cmd.Flags().GetString("auth-type")
		authData, _ := cmd.Flags().GetStringSlice("auth-data")
		if strings.Join(authData, "") == "" {
			return errors.New("Authorization Data wasn't given")
		}
		credentials := accountspb.Credentials{
			Type: (authType), Data: authData,
		}

		access, _ := cmd.Flags().GetInt32("access-level")

		req := accountspb.CreateRequest{
			Title: args[0], Namespace: args[1],
			Auth: &credentials, Access: &access,
		}
		res, err := client.Create(ctx, &req)
		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("UUID:", res.GetUuid())
		}

		return nil
	},
}

CreateCmd represents the create command

View Source
var DeleteCmd = &cobra.Command{
	Use:     "delete [UUID]",
	Aliases: []string{"del", "d"},
	Short:   "Delete NoCloud Account",
	Args:    cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, client := MakeAccountsServiceClientOrFail()
		res, err := client.Delete(ctx, &accountspb.DeleteRequest{
			Uuid: args[0],
		})
		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.Printf("Result: %t\n", res.GetResult())
		}

		return nil
	},
}

DeleteCmd represents the delete command

View Source
var GetCmd = &cobra.Command{
	Use:   "get [UUID]",
	Short: "Get NoCloud Account Data",
	Args:  cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, client := MakeAccountsServiceClientOrFail()
		res, err := client.Get(ctx, &accountspb.GetRequest{
			Uuid: args[0],
		})
		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 {
			PrintAccount(res)
		}

		return nil
	},
}

GetCmd represents the get command

View Source
var ListCmd = &cobra.Command{
	Use:     "list [[NAMESPACE]] [[flags]]",
	Aliases: []string{"l", "ls"},
	Short:   "List NoCloud Accounts",
	Long:    `Add namespace UUID after list command, to filter accounts by namespace`,
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, client := MakeAccountsServiceClientOrFail()
		request := accountspb.ListRequest{}
		if len(args) > 0 {
			request.Namespace = &args[0]
		}

		d, _ := cmd.Flags().GetInt32("depth")
		request.Depth = &d

		res, err := client.List(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 {
			PrintAccountsPool(res.Pool)
		}

		return nil
	},
}

ListCmd represents the list command

View Source
var UpdateCmd = &cobra.Command{
	Use:     "update [account UUID] [flags]",
	Aliases: []string{"upd"},
	Short:   "Update NoCloud Account",
	Long:    "In order to execute request you must change at least one field.",
	Args:    cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, client := MakeAccountsServiceClientOrFail()

		updated := false
		req := accountspb.Account{
			Uuid: args[0],
		}
		title, _ := cmd.Flags().GetString("title")
		if title != "" {
			req.Title = title
			updated = true
		}

		if !updated {
			return errors.New("No fields updated, exiting")
		}

		res, err := client.Update(ctx, &req)
		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.Printf("Result: %t\n", res.GetResult())
		}

		return nil
	},
}

UpdateCmd represents the update command

Functions

func MakeAccountsServiceClientOrFail

func MakeAccountsServiceClientOrFail() (context.Context, regpb.AccountsServiceClient)

func PrintAccount

func PrintAccount(acc *pb.Account)

func PrintAccountsPool

func PrintAccountsPool(pool []*pb.Account)

Types

This section is empty.

Jump to

Keyboard shortcuts

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