Updating Connnect dependencies to latest

This commit is contained in:
jillianwilson
2021-04-12 09:37:32 -03:00
parent 9946ce7ba6
commit 42e348de91
7 changed files with 79 additions and 184 deletions

View File

@@ -18,7 +18,7 @@ import (
)
const (
defaultUserAgent = "connect-sdk-go/0.0.1"
defaultUserAgent = "connect-sdk-go/%s"
)
// Client Represents an available 1Password Connect API to connect to
@@ -61,7 +61,7 @@ func NewClientFromEnvironment() (Client, error) {
// NewClient Returns a Secret Service client for a given url and jwt
func NewClient(url string, token string) Client {
return NewClientWithUserAgent(url, token, defaultUserAgent)
return NewClientWithUserAgent(url, token, fmt.Sprintf(defaultUserAgent, SDKVersion))
}
// NewClientWithUserAgent Returns a Secret Service client for a given url and jwt and identifies with userAgent

View File

@@ -0,0 +1,5 @@
package connect
// SDKVersion is the latest Semantic Version of the library
// Do not rename this variable without changing the regex in the Makefile
const SDKVersion = "1.0.1"

View File

@@ -2,6 +2,7 @@ package onepassword
import (
"encoding/json"
"strings"
"time"
)
@@ -104,3 +105,54 @@ type ItemField struct {
Recipe *GeneratorRecipe `json:"recipe,omitempty"`
Entropy float64 `json:"entropy,omitempty"`
}
// Get Retrieve the value of a field on the item by its label. To specify a
// field from a specific section pass in <section label>.<field label>. If
// no field matching the selector is found return "".
func (i *Item) GetValue(field string) string {
if i == nil || len(i.Fields) == 0 {
return ""
}
sectionFilter := false
sectionLabel := ""
fieldLabel := field
if strings.Contains(field, ".") {
parts := strings.Split(field, ".")
// Test to make sure the . isn't the last character
if len(parts) == 2 {
sectionFilter = true
sectionLabel = parts[0]
fieldLabel = parts[1]
}
}
for _, f := range i.Fields {
if sectionFilter {
if f.Section != nil {
if sectionLabel != i.SectionLabelForID(f.Section.ID) {
continue
}
}
}
if fieldLabel == f.Label {
return f.Value
}
}
return ""
}
func (i *Item) SectionLabelForID(id string) string {
if i != nil || len(i.Sections) > 0 {
for _, s := range i.Sections {
if s.ID == id {
return s.Label
}
}
}
return ""
}