store

package
v0.0.0-...-c4b491b Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2021 License: GPL-3.0, GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Destroy = cobra.Command{
	Use:   "destroy",
	Short: "Destroys the store",

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

		ctx, cancel := context.WithCancel(context.Background())
		defer cancel()

		buckets := []string{
			"root",
			"generic",
		}

		for _, bucket := range buckets {
			logrus.Infof("Remove all items in: %s", bucket)
			deleteAllItemsInBucket(minioClient, bucket)
			logrus.Infof("Removing bucket: %s", bucket)
			err := minioClient.RemoveBucket(ctx, bucket)
			if err != nil {
				logrus.Error(err)
			}
		}

		db, _ := database.CreateDatabase()
		tables := []string{
			"schema_migrations",
			"snap_branches",
			"snap_risks",
			"snap_tracks",
			"ssh_keys",
			"snap_revisions",
			"snap_entries",
			"keys",
			"accounts",
		}
		for _, t := range tables {
			db.Exec("DROP TABLE " + t)
		}

		sequences := []string{
			"accounts_id_seq",
			"keys_id_seq",
			"snap_entries_id_seq",
			"snap_revisions_id_seq",
			"ssh_keys_id_seq",
		}
		for _, s := range sequences {
			db.Exec("DROP SEQUENCE " + s)
		}
	},
}
View Source
var Initialize = cobra.Command{
	Use:   "initialize",
	Short: "Initializes the store",

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

		minioClient := getMinioClient()

		exists, err := minioClient.BucketExists(context.Background(), "root")
		if err != nil {
			panic(err)
		}

		if exists {
			fmt.Println("Bucket exists, please use destroy command if you are sure you want to start over.")
			return
		}

		exists, err = minioClient.BucketExists(context.Background(), "generic")
		if err != nil {
			panic(err)
		}

		if exists {
			fmt.Println("Bucket exists, please use destroy command if you are sure you want to start over.")
			return
		}

		var initConfig InitializationConfig
		bytes, _ := ioutil.ReadFile(initializationConfigPath)
		_ = json.Unmarshal(bytes, &initConfig)

		fmt.Printf("%+v\n", initConfig)

		makeBucketAndAddKey(minioClient, "root", initConfig.RootKeyPath, "private-key.pem")
		makeBucketAndAddKey(minioClient, "generic", initConfig.GenericKeyPath, "private-key.pem")

		rootKey := crypto.GetPrivateKeyFromPEMFile(initConfig.RootKeyPath)

		signingDB := assertstest.NewSigningDB(initConfig.AuthorityId, rootKey)
		db, _ := database.CreateDatabase()

		createTrustedAccountExt(minioClient, rootKey, rootKey.PublicKey().ID(), signingDB, initConfig.RootAccountInit.Id, initConfig.RootAccountInit.Username, "root", "default")
		rootAccount := models.Account{
			AccountId:   initConfig.RootAccountInit.Id,
			DisplayName: initConfig.RootAccountInit.DisplayName,
			Username:    initConfig.RootAccountInit.Username,
			Email:       initConfig.RootAccountInit.Email,
		}
		db.Save(&rootAccount)
		rootAccountKey := models.Key{
			Name: "default",

			SHA3384:          rootKey.PublicKey().ID(),
			EncodedPublicKey: rootKey.PublicKey().ID(),
			AccountID:        rootAccount.ID,
		}
		db.Save(&rootAccountKey)

		genericKey := crypto.GetPrivateKeyFromPEMFile(initConfig.GenericKeyPath)

		createTrustedAccountExt(minioClient, genericKey, rootKey.PublicKey().ID(), signingDB, initConfig.GenericAccountInit.Id, initConfig.GenericAccountInit.Username, "generic", "default")
		genericAccount := models.Account{
			AccountId:   initConfig.GenericAccountInit.Id,
			DisplayName: initConfig.GenericAccountInit.DisplayName,
			Username:    initConfig.GenericAccountInit.Username,
			Email:       initConfig.GenericAccountInit.Email,
		}
		db.Save(&genericAccount)
		genericAccountKey := models.Key{
			Name: "default",

			SHA3384:          genericKey.PublicKey().ID(),
			EncodedPublicKey: genericKey.PublicKey().ID(),
			AccountID:        genericAccount.ID,
		}
		db.Save(&genericAccountKey)

		fmt.Println("*******************************")
		fmt.Printf("ALL DONE. Browse to %s/%s to view your assertions.\n", viper.GetString(configkey.MinioHost), "minio/root/")
		fmt.Println("*******************************")
	},
}
View Source
var Store = &cobra.Command{
	Use:              "store",
	Long:             "store",
	Short:            "store",
	TraverseChildren: true,
}

Functions

This section is empty.

Types

type AccountInit

type AccountInit struct {
	Id          string `json:"id"`
	DisplayName string `json:"display_name"`
	Username    string `json:"username"`
	Email       string `json:"email"`
}

type InitializationConfig

type InitializationConfig struct {
	AuthorityId        string      `json:"authority_id"`
	RootKeyPath        string      `json:"root_key_path"`
	GenericKeyPath     string      `json:"generic_key_path"`
	RootAccountInit    AccountInit `json:"root_account_init"`
	GenericAccountInit AccountInit `json:"generic_account_init"`
}

Jump to

Keyboard shortcuts

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