当前位置: 首页>>代码示例>>Golang>>正文


Golang KeyFileStore.RemoveKey方法代码示例

本文整理汇总了Golang中github.com/docker/notary/trustmanager.KeyFileStore.RemoveKey方法的典型用法代码示例。如果您正苦于以下问题:Golang KeyFileStore.RemoveKey方法的具体用法?Golang KeyFileStore.RemoveKey怎么用?Golang KeyFileStore.RemoveKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/docker/notary/trustmanager.KeyFileStore的用法示例。


在下文中一共展示了KeyFileStore.RemoveKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: keysRemoveKey

// keysRemoveKey deletes a private key based on ID
func keysRemoveKey(cmd *cobra.Command, args []string) {
	if len(args) < 1 {
		cmd.Usage()
		fatalf("must specify the key ID of the key to remove")
	}

	parseConfig()

	keyStoreManager, err := keystoremanager.NewKeyStoreManager(trustDir, retriever)
	if err != nil {
		fatalf("failed to create a new truststore manager with directory: %s", trustDir)
	}

	keyID := args[0]

	// This is an invalid ID
	if len(keyID) != idSize {
		fatalf("invalid key ID provided: %s", keyID)
	}

	// List the key about to be removed
	fmt.Println("Are you sure you want to remove the following key?")
	fmt.Printf("%s\n(yes/no)\n", keyID)

	// Ask for confirmation before removing the key, unless -y is passed
	if !keyRemoveYes {
		confirmed := askConfirm()
		if !confirmed {
			fatalf("aborting action.")
		}
	}

	// Choose the correct filestore to remove the key from
	var keyStoreToRemove *trustmanager.KeyFileStore
	var keyMap map[string]string
	if keyRemoveRoot {
		keyStoreToRemove = keyStoreManager.RootKeyStore()
		keyMap = keyStoreManager.RootKeyStore().ListKeys()
	} else {
		keyStoreToRemove = keyStoreManager.NonRootKeyStore()
		keyMap = keyStoreManager.NonRootKeyStore().ListKeys()
	}

	// Attempt to find the full GUN to the key in the map
	// This is irrelevant for removing root keys, but does no harm
	var keyWithGUN string
	for k := range keyMap {
		if filepath.Base(k) == keyID {
			keyWithGUN = k
		}
	}

	// If empty, we didn't find any matches
	if keyWithGUN == "" {
		fatalf("key with key ID: %s not found\n", keyID)
	}

	// Attempt to remove the key
	err = keyStoreToRemove.RemoveKey(keyWithGUN)
	if err != nil {
		fatalf("failed to remove key with key ID: %s, %v", keyID, err)
	}
}
开发者ID:pombredanne,项目名称:notary,代码行数:64,代码来源:keys.go


注:本文中的github.com/docker/notary/trustmanager.KeyFileStore.RemoveKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。