Skip to content

Commit

Permalink
Apply formatting to the README
Browse files Browse the repository at this point in the history
These help for visual formatting and content editing.
  • Loading branch information
edif2008 committed May 11, 2022
1 parent 4c2e11a commit c1d4038
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ The 1Password Connect Go SDK provides access to the [1Password Connect](https://
<details>
<summary>Table of Contents</summary>

- [1Password Connect Go SDK](#1password-connect-go-sdk)
* [Prerequisites](#prerequisites)
* [Installation](#installation)
* [Usage](#usage)
Expand Down Expand Up @@ -49,7 +48,7 @@ go get github.com/1Password/connect-sdk-go
To import the 1Password Connect SDK in your Go project:
```go
import (
"github.com/1Password/connect-sdk-go/connect"
"github.com/1Password/connect-sdk-go/connect"
"github.com/1Password/connect-sdk-go/onepassword"
)
```
Expand All @@ -76,19 +75,19 @@ func main () {
Writing a secret:
```go
import (
"github.com/1Password/connect-sdk-go/connect"
"github.com/1Password/connect-sdk-go/connect"
"github.com/1Password/connect-sdk-go/onepassword"
)

func main () {
client := connect.NewClient("<your_connect_host>", "<your_connect_token>")
item := &onepassword.Item{
Title: "Secret String",
Category: onepassword.Login,
Fields: []*onepassword.ItemField{{
Value: "mysecret",
Type: "STRING",
Type: "STRING",
}},
Category: onepassword.Login,
Title: "Secret String",
}

postedItem, err := client.CreateItem(item, "<vault-uuid>")
Expand Down Expand Up @@ -156,20 +155,23 @@ The `connect.Client` supports methods for:
log.Fatal(err)
}
```

#### Retrieving a vault:
```go
vault, err := client.GetVault("vault-uuid")
if err != nil {
log.Fatal(err)
}
```

#### Retrieving all items in a vault
```go
items, err := client.GetItems("vault-uuid")
if err != nil {
log.Fatal(err)
}
```

#### Retrieving an item by title
To retrieve all items in a vault with a given title:
```go
Expand All @@ -178,95 +180,109 @@ To retrieve all items in a vault with a given title:
log.Fatal(err)
}
```

In case the item title is unique for a vault, another function is available as well, returning only one item, instead of a slice:
```go
item, err := client.GetItemByTitle("item-title", "vault-uuid")
if err != nil {
log.Fatal(err)
}
```

#### Retrieving items by vault UUID and item UUID
```go
item, err := client.GetItem("item-uuid", "vault-uuid")
if err != nil {
log.Fatal(err)
}
```

#### Creating an item in a vault
```go
item := &onepassword.Item{
Title: "Secret String",
Category: onepassword.Login,
Tags: []string{"1password-connect"},
Fields: []*onepassword.ItemField{{
Value: "mysecret",
Type: "STRING",
}},
Tags: []string{"1password-connect"},
Category: onepassword.Login,
Title: "Secret String",
}

postedItem, err := client.CreateItem(item, "vault-uuid")
if err != nil {
log.Fatal(err)
}
```

#### Updating an item
```go
item, err := client.GetItem("item-uuid", "vault-uuid")
if err != nil {
log.Fatal(err)
}

item.Title = "new title"
client.UpdateItem(item, "vault-uuid")
```

#### Deleting an item
```go
item, err := client.GetItem("item-uuid", "vault-uuid")
if err != nil {
log.Fatal(err)
}

err = client.DeleteItem(item, "vault-uuid")
if err != nil {
log.Fatal(err)
}
```

#### Deleting an item by UUID
```go
err := client.DeleteItemByID("item-uuid", "vault-uuid")
if err != nil {
log.Fatal(err)
}
```

#### Retrieving a file from an item
```go
file, err := client.GetFile("<file-uuid>", "item-uuid", "vault-uuid")
if err != nil {
log.Fatal(err)
}
```

#### Retrieving the contents of a file from an item
```go
file, err := client.GetFile("file-uuid", "item-uuid", "vault-uuid")
if err != nil {
log.Fatal(err)
}

content, err := client.GetFileContent(file)
if err != nil {
log.Fatal(err)
}
```

#### Retrieving all files under an item
```go
files, err := client.GetFiles("item-uuid", "vault-uuid")
if err != nil {
log.Fatal(err)
}
```

#### Downloading a file
```go
file, err := client.GetFile("file-uuid", "item-uuid", "vault-uuid")
if err != nil {
log.Fatal(err)
}

path, err := client.DownloadFile(file, "local/path/to/file", true)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -301,7 +317,7 @@ import (
type Config struct {
Username string `opitem:"Demo TF Database" opfield:"username"`
Password string `opitem:"Demo TF Database" opfield:"password"`
Host string `opitem:"Demo TF Database" opsection:"details" opfield:"hostname"`
Host string `opitem:"Demo TF Database" opsection:"details" opfield:"hostname"`
APIKey onepassword.Item `opvault:"7vs66j55o6md5btwcph272mva4" opitem:"API Key"`
}

Expand Down

0 comments on commit c1d4038

Please sign in to comment.