Skip to content

Commit

Permalink
Merge pull request #125 from 1Password/release/v1.4.1-beta01
Browse files Browse the repository at this point in the history
Prepare Release - v1.4.1-beta01
  • Loading branch information
volodymyrZotov authored Dec 13, 2023
2 parents d705447 + d27abbd commit 1b0a164
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.0
1.4.1-beta01
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@

---

[//]: # (START/v1.4.1-beta01)
# v1.4.1-beta01

## Fixes
* Using provider on Terraform Cloud. {#116}

---

[//]: # (START/v1.4.0)
# v1.4.0

Expand Down
39 changes: 39 additions & 0 deletions onepassword/cli/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
"github.com/hashicorp/terraform-plugin-log/tflog"
)

const (
minimumOpCliVersion = "2.23.0" // introduction of stdin json support for `op item update`
)

type OP struct {
binaryPath string
serviceAccountToken string
Expand Down Expand Up @@ -41,7 +45,22 @@ func (op *OP) GetVersion(ctx context.Context) (*semver.Version, error) {
return version, nil
}

func (op *OP) checkCliVersion(ctx context.Context) error {
cliVersion, err := op.GetVersion(ctx)
if err != nil {
return fmt.Errorf("failed to get version of op CLI: %w", err)
}
if cliVersion.LessThan(semver.MustParse(minimumOpCliVersion)) {
return fmt.Errorf("current 1Password CLI version is \"%s\". Please upgrade to at least \"%s\"", cliVersion, minimumOpCliVersion)
}
return nil
}

func (op *OP) GetVault(ctx context.Context, uuid string) (*onepassword.Vault, error) {
versionErr := op.checkCliVersion(ctx)
if versionErr != nil {
return nil, versionErr
}
var res *onepassword.Vault
err := op.execJson(ctx, &res, nil, p("vault"), p("get"), p(uuid))
if err != nil {
Expand All @@ -51,6 +70,10 @@ func (op *OP) GetVault(ctx context.Context, uuid string) (*onepassword.Vault, er
}

func (op *OP) GetVaultsByTitle(ctx context.Context, title string) ([]onepassword.Vault, error) {
versionErr := op.checkCliVersion(ctx)
if versionErr != nil {
return nil, versionErr
}
var allVaults []onepassword.Vault
err := op.execJson(ctx, &allVaults, nil, p("vault"), p("list"))
if err != nil {
Expand All @@ -67,6 +90,10 @@ func (op *OP) GetVaultsByTitle(ctx context.Context, title string) ([]onepassword
}

func (op *OP) GetItem(ctx context.Context, itemUuid, vaultUuid string) (*onepassword.Item, error) {
versionErr := op.checkCliVersion(ctx)
if versionErr != nil {
return nil, versionErr
}
var res *onepassword.Item
err := op.execJson(ctx, &res, nil, p("item"), p("get"), p(itemUuid), f("vault", vaultUuid))
if err != nil {
Expand All @@ -80,6 +107,10 @@ func (op *OP) GetItemByTitle(ctx context.Context, title string, vaultUuid string
}

func (op *OP) CreateItem(ctx context.Context, item *onepassword.Item, vaultUuid string) (*onepassword.Item, error) {
versionErr := op.checkCliVersion(ctx)
if versionErr != nil {
return nil, versionErr
}
return op.withRetry(func() (*onepassword.Item, error) {
return op.create(ctx, item, vaultUuid)
})
Expand Down Expand Up @@ -116,6 +147,10 @@ func (op *OP) create(ctx context.Context, item *onepassword.Item, vaultUuid stri
}

func (op *OP) UpdateItem(ctx context.Context, item *onepassword.Item, vaultUuid string) (*onepassword.Item, error) {
versionErr := op.checkCliVersion(ctx)
if versionErr != nil {
return nil, versionErr
}
return op.withRetry(func() (*onepassword.Item, error) {
return op.update(ctx, item, vaultUuid)
})
Expand All @@ -141,6 +176,10 @@ func (op *OP) update(ctx context.Context, item *onepassword.Item, vaultUuid stri
}

func (op *OP) DeleteItem(ctx context.Context, item *onepassword.Item, vaultUuid string) error {
versionErr := op.checkCliVersion(ctx)
if versionErr != nil {
return versionErr
}
_, err := op.withRetry(func() (*onepassword.Item, error) {
return op.delete(ctx, item, vaultUuid)
})
Expand Down
10 changes: 0 additions & 10 deletions onepassword/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ import (
"github.com/1Password/terraform-provider-onepassword/onepassword/cli"
"github.com/1Password/terraform-provider-onepassword/onepassword/connectctx"
"github.com/1Password/terraform-provider-onepassword/version"
"github.com/Masterminds/semver/v3"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

const (
terraformProviderUserAgent = "terraform-provider-connect/%s"
minimumOpCliVersion = "2.23.0" // introduction of stdin json support for `op item update`
)

func init() {
Expand Down Expand Up @@ -124,14 +122,6 @@ func initializeCLI(ctx context.Context, serviceAccountToken, account, opCliPath
op = cli.New(serviceAccountToken, opCliPath, "")
}

cliVersion, err := op.GetVersion(ctx)
if err != nil {
return nil, diag.FromErr(fmt.Errorf("failed to get version of op CLI: %w", err))
}
if cliVersion.LessThan(semver.MustParse(minimumOpCliVersion)) {
return nil, diag.Errorf("Current 1Password CLI version is \"%s\". Please upgrade to at least \"%s\".", cliVersion, minimumOpCliVersion)
}

return op, nil
}

Expand Down

0 comments on commit 1b0a164

Please sign in to comment.