cmd

package
v0.0.0-...-3f10997 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Copyright © 2023 NAME HERE <EMAIL ADDRESS>

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 © 2023 NAME HERE <EMAIL ADDRESS>

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 © 2023 NAME HERE <EMAIL ADDRESS>

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 © 2023 NAME HERE <EMAIL ADDRESS>

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 SecretsCollectCmd = &cobra.Command{
	Use:     "collect",
	Aliases: []string{"c"},
	Short:   "A brief description of your command",
	Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
	Run: func(cmd *cobra.Command, args []string) {
		ref, _ := cmd.Flags().GetString("reference")
		path, _ := cmd.Flags().GetString("path")
		blob, _ := common.GlobalPigeonHoleClient.DownloadSecretBlobWithResponse(common.GlobalCtx, ref)
		var filename string
		if blob.StatusCode() == 404 {
			fmt.Println("No secret found")
			fmt.Print(path)
		} else {

		}
		filename, _ = common.DecryptBytes(blob.Body, path)
		fmt.Println(filename)
		common.DecompressFile(filename, path)

	},
}

collectCmd represents the collect command

View Source
var SecretsDeleteCmd = &cobra.Command{
	Use:   "delete",
	Short: "A brief description of your command",
	Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
	Run: func(cmd *cobra.Command, args []string) {

		all, _ := cmd.Flags().GetBool("all")
		id, _ := cmd.Flags().GetString("id")

		if id != "" {
			fmt.Println("Testing")
		} else if all {
			resp, _ := common.GlobalPigeonHoleClient.SecretDeleteWithResponse(common.GlobalCtx)
			if resp.StatusCode() == http.StatusOK {
				fmt.Println("All secrets deleted")
			} else {
				fmt.Println("Something went wrong")
			}
		} else {
			common.DisplayHelp(cmd, args)
		}

	},
}

deleteCmd represents the delete command

View Source
var SecretsDropCmd = &cobra.Command{
	Use:     "post",
	Aliases: []string{"send", "drop", "ship"},
	Short:   "A brief description of your command",
	Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
	PreRunE: func(cmd *cobra.Command, args []string) error {

		fileInfo, _ := os.Stdin.Stat()
		if (fileInfo.Mode() & os.ModeCharDevice) == 0 {

		} else {

			requiredFlag, err := cmd.Flags().GetString("path")
			if err != nil || requiredFlag == "" {
				return fmt.Errorf("You must specify a path '-p' or pipe from stdin")
			}
		}
		return nil
	},

	Run: func(cmd *cobra.Command, args []string) {

		recipients, _ := cmd.Flags().GetStringSlice("recipient")

		newSecretRequest := sdk.CreateSecret{
			RecipientIds: recipients,
			Reference:    common.GenerateCodeWord(2),
		}

		s, err := common.GlobalPigeonHoleClient.SecretPostWithResponse(common.GlobalCtx, newSecretRequest)
		if err != nil {
			fmt.Println(err.Error())
		}

		filename, _ := cmd.Flags().GetString("path")
		testFilePath, _ := os.Stat(filename)
		tarballFilePath, _ := ioutil.TempFile(os.TempDir(), "pigeonhole")
		if testFilePath.IsDir() {
			cwd, _ := os.Getwd()
			os.Chdir(filename)
			common.CompressPath("./", tarballFilePath)
			os.Chdir(cwd)
			filename = tarballFilePath.Name()
		} else {

		}

		user_pubs, _ := common.GetUserGPGArmoredPubKeysFromIdSlice(recipients)
		filename, _ = common.EncryptFile(filename, user_pubs)

		errx := uploadFile(*s.JSON200, filename)
		if errx != nil {
			fmt.Println(errx)
		}
		common.ShredFile(filename)

	},
}

dropCmd represents the drop command

View Source
var SecretsListCmd = &cobra.Command{
	Use:     "list",
	Aliases: []string{"l", "ls"},
	Short:   "A brief description of your command",
	Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
	Run: func(cmd *cobra.Command, args []string) {
		query, _ := cmd.Flags().GetString("query")
		s := sdk.SecretGetParams{
			Reference: &query,
		}
		secrets, _ := common.GlobalPigeonHoleClient.SecretGetWithResponse(common.GlobalCtx, &s)
		if len(*secrets.JSON200) > 0 {
			common.OutputData(secrets.JSON200)
		} else {
			fmt.Println("No secrets available")
		}

	},
}

secretsListCmd represents the secretsList command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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