Esempio n. 1
0
File: client.go Progetto: gaku/1pass
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)
}
Esempio n. 2
0
File: client.go Progetto: gaku/1pass
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)
}
Esempio n. 3
0
File: client.go Progetto: gaku/1pass
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)
}
Esempio n. 4
0
File: client.go Progetto: gaku/1pass
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)
	}
}
Esempio n. 5
0
File: client.go Progetto: gaku/1pass
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
}
Esempio n. 6
0
File: client.go Progetto: gaku/1pass
// 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))
}