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


Golang Vault.ListItems方法代码示例

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


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

示例1: listTag

func listTag(vault *onepass.Vault, tag string) {
	items, err := vault.ListItems()
	if err != nil {
		fatalErr(err, "Unable to list vault items")
	}
	itemsWithTag := []onepass.Item{}
	for _, item := range items {
		hasTag := rangeutil.Contains(0, len(item.OpenContents.Tags), func(i int) bool {
			return item.OpenContents.Tags[i] == tag
		})
		if hasTag {
			itemsWithTag = append(itemsWithTag, item)
		}
	}
	listItems(vault, itemsWithTag)
}
开发者ID:gaku,项目名称:1pass,代码行数:16,代码来源:client.go

示例2: listMatchingItems

func listMatchingItems(vault *onepass.Vault, pattern string) {
	var items []onepass.Item
	var err error

	if len(pattern) > 0 {
		items, err = lookupItems(vault, pattern)
	} else {
		items, err = vault.ListItems()
	}

	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to list vault items: %v\n", err)
		os.Exit(1)
	}

	listItems(vault, items)
}
开发者ID:gaku,项目名称:1pass,代码行数:17,代码来源:client.go

示例3: listFolder

func listFolder(vault *onepass.Vault, pattern string) {
	pattern = "folder:" + pattern
	folder, err := lookupSingleItem(vault, pattern)
	if err != nil {
		fatalErr(err, "Failed to find folder")
	}
	items, err := vault.ListItems()
	if err != nil {
		fatalErr(err, "Failed to list items")
	}
	itemsInFolder := []onepass.Item{}
	for _, item := range items {
		if item.FolderUuid == folder.Uuid {
			itemsInFolder = append(itemsInFolder, item)
		}
	}
	listItems(vault, itemsInFolder)
}
开发者ID:gaku,项目名称:1pass,代码行数:18,代码来源:client.go

示例4: listTags

func listTags(vault *onepass.Vault) {
	uniqTags := map[string]bool{}
	items, err := vault.ListItems()
	if err != nil {
		fatalErr(err, "Unable to list vault items")
	}
	for _, item := range items {
		for _, tag := range item.OpenContents.Tags {
			uniqTags[tag] = true
		}
	}
	tags := []string{}
	for tag, _ := range uniqTags {
		tags = append(tags, tag)
	}
	sort.Strings(tags)
	for _, tag := range tags {
		fmt.Printf("%s\n", tag)
	}
}
开发者ID:gaku,项目名称:1pass,代码行数:20,代码来源:client.go

示例5: lookupItems

func lookupItems(vault *onepass.Vault, pattern string) ([]onepass.Item, error) {
	typeName := typeFromAlias(pattern)
	if typeName != "" {
		pattern = ""
	}

	if strings.Contains(pattern, ":") {
		parts := strings.SplitN(pattern, ":", 2)
		typeName = typeFromAlias(parts[0])
		pattern = parts[1]

		if typeName == "" {
			fatalErr(nil, fmt.Sprintf("Unknown type name '%s'", parts[0]))
		}
	}

	items, err := vault.ListItems()
	if err != nil {
		return items, err
	}
	patternLower := strings.ToLower(pattern)
	matches := []onepass.Item{}
	for _, item := range items {
		patternMatch := pattern == ""
		typeMatch := typeName == "" || item.TypeName == typeName

		if strings.Contains(strings.ToLower(item.Title), patternLower) ||
			strings.HasPrefix(strings.ToLower(item.Uuid), patternLower) {
			patternMatch = true
		}

		if patternMatch && typeMatch {
			matches = append(matches, item)
		}
	}
	return matches, nil
}
开发者ID:gaku,项目名称:1pass,代码行数:37,代码来源:client.go

示例6: exportItemTemplates

// create a set of item templates based on existing
// items in a vault
func exportItemTemplates(vault *onepass.Vault, pattern string) {
	items, err := vault.ListItems()
	if err != nil {
		fatalErr(err, "Unable to list vault items")
	}

	typeTemplates := map[string]onepass.ItemContent{}
	for _, item := range items {
		typeTemplate := onepass.ItemContent{
			Sections:   []onepass.ItemSection{},
			FormFields: []onepass.WebFormField{},
		}
		if !strings.HasPrefix(strings.ToLower(item.Title), pattern) {
			continue
		}

		content, err := item.Content()
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to decrypt item: %v\n", err)
		}

		// section templates
		for _, section := range content.Sections {
			sectionTemplate := onepass.ItemSection{
				Name:   section.Name,
				Title:  section.Title,
				Fields: []onepass.ItemField{},
			}
			for _, field := range section.Fields {
				fieldTemplate := onepass.ItemField{
					Name:  field.Name,
					Title: field.Title,
					Kind:  field.Kind,
				}
				sectionTemplate.Fields = append(sectionTemplate.Fields, fieldTemplate)
			}
			typeTemplate.Sections = append(typeTemplate.Sections, sectionTemplate)
		}

		// web form field templates
		for _, formField := range content.FormFields {
			formTemplate := onepass.WebFormField{
				Name:        formField.Name,
				Id:          formField.Id,
				Type:        formField.Type,
				Designation: formField.Designation,
			}
			typeTemplate.FormFields = append(typeTemplate.FormFields, formTemplate)
		}

		// URL templates
		for _, url := range content.Urls {
			urlTemplate := onepass.ItemUrl{Label: url.Label}
			typeTemplate.Urls = append(typeTemplate.Urls, urlTemplate)
		}

		typeTemplates[item.TypeName] = typeTemplate
	}

	data, err := json.Marshal(typeTemplates)
	if err != nil {
		fatalErr(err, "Unable to export item templates")
	}
	_, _ = os.Stdout.Write(prettyJson(data))
}
开发者ID:gaku,项目名称:1pass,代码行数:67,代码来源:client.go


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