Skip to content

Commit

Permalink
auto-genereated rc.5
Browse files Browse the repository at this point in the history
  • Loading branch information
migara committed Feb 14, 2025
1 parent c8c5bfb commit dbf2e36
Show file tree
Hide file tree
Showing 57 changed files with 84,024 additions and 85,405 deletions.
35 changes: 34 additions & 1 deletion docs/ephemeral-resources/api_key.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,40 @@ description: |-




## Example Usage

```terraform
# Allows you to generate an API key based on the provided username and password for the `panos_api_key` ephemeral resource.
# Note: The current implementation still requires you to provide a username/password when configuring the provider.
# If you use the same admin account username/password within the provider configuration and the ephemeral resource,
# you will not be able to use the same provider with other resources. The reason is that when we generate an API key
# with the `panos_api_key` ephemeral resource, the old tokens are invalidated automatically (i.e., the token for the
# provider itself). To avoid conflicts, consider using different credentials for the provider configuration and the
# ephemeral resource.
# Use cases:
# - Store short lived API keys in a Cloud Key Management Service which will also support ephemeral resources
# - Dynamically configure diffferent instances of panos provider instances bound to different admin accounts
provider "panos" {
hostname = "<hostname>"
username = "<username>"
password = "<password>"
}
ephemeral "panos_api_key" "example" {
username = "<user-1>"
password = "<password>"
}
# Use case 1: Configure a new provider with the new API key
provider "panos" {
hostname = "<hostname>"
api_key = ephemeral.panos_api_key.example.api_key
provider = panos.user1
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
34 changes: 34 additions & 0 deletions docs/ephemeral-resources/vm_auth_key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "panos_vm_auth_key Ephemeral Resource - panos"
subcategory: ""
description: |-
---

# panos_vm_auth_key (Ephemeral Resource)



## Example Usage

```terraform
# Generate the VM Auth Key on Panorama
# https://docs.paloaltonetworks.com/vm-series/11-0/vm-series-deployment/bootstrap-the-vm-series-firewall/generate-the-vm-auth-key-on-panorama
ephemeral "panos_vm_auth_key" "this" {
lifetime = 1
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `lifetime` (Number)

### Optional

- `expiration_date` (String)
- `vm_auth_key` (String, Sensitive)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22.7
toolchain go1.23.3

require (
github.com/PaloAltoNetworks/pango v0.10.3-0.20250214131722-6674231a613b
github.com/hashicorp/terraform-plugin-framework v1.13.0
github.com/hashicorp/terraform-plugin-framework-validators v0.16.0
github.com/hashicorp/terraform-plugin-go v0.25.0
Expand All @@ -21,7 +22,6 @@ require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/PaloAltoNetworks/pango v0.10.3-0.20250213110909-149fa41d9871 // indirect
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect
github.com/agext/levenshtein v1.2.2 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/PaloAltoNetworks/pango v0.10.3-0.20250213091804-03aebf526b1e h1:YZmUE+rSLnfAZ7QvHveU5kMvHW3nnJWwjbD/I4rb9J4=
github.com/PaloAltoNetworks/pango v0.10.3-0.20250213091804-03aebf526b1e/go.mod h1:tDFAikqi8qR9jGyOqzXn5JyWh4LoBG/aUSJHF3rmVd4=
github.com/PaloAltoNetworks/pango v0.10.3-0.20250213110909-149fa41d9871 h1:W3vix/+dbgCW+dmCvloszMEdPLGqn/tAcD7Mu4bdiUo=
github.com/PaloAltoNetworks/pango v0.10.3-0.20250213110909-149fa41d9871/go.mod h1:tDFAikqi8qR9jGyOqzXn5JyWh4LoBG/aUSJHF3rmVd4=
github.com/PaloAltoNetworks/pango v0.10.3-0.20250214124253-d85b000d6bcd h1:bt0ZfqWKkS1a/DhSouvbBOKFEthwlxEfXU97+pMGwjk=
github.com/PaloAltoNetworks/pango v0.10.3-0.20250214124253-d85b000d6bcd/go.mod h1:tDFAikqi8qR9jGyOqzXn5JyWh4LoBG/aUSJHF3rmVd4=
github.com/PaloAltoNetworks/pango v0.10.3-0.20250214131722-6674231a613b h1:7fBoHQiG5/ExkV/1LR/QcIsK536d1/rpQ+/tl+jcyjU=
github.com/PaloAltoNetworks/pango v0.10.3-0.20250214131722-6674231a613b/go.mod h1:tDFAikqi8qR9jGyOqzXn5JyWh4LoBG/aUSJHF3rmVd4=
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg=
github.com/ProtonMail/go-crypto v1.1.0-alpha.2/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
Expand Down
28 changes: 6 additions & 22 deletions internal/manager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ type TFConfigObject[E any] interface {

type SDKConfigService[C any, L ConfigLocation] interface {
Create(context.Context, L, C) (C, error)
CreateWithXpath(context.Context, string, C) error
Update(context.Context, L, C) (C, error)
ReadWithXpath(context.Context, string, string) (C, error)
Read(context.Context, L, string) (C, error)
Delete(context.Context, L, C) error
}

type ConfigLocation interface {
XpathWithComponents(version.Number, ...string) ([]string, error)
Xpath(version.Number) ([]string, error)
}

type ConfigObjectManager[C any, L ConfigLocation, S SDKConfigService[C, L]] struct {
Expand All @@ -42,31 +41,16 @@ func NewConfigObjectManager[C any, L ConfigLocation, S SDKConfigService[C, L]](c
}
}

func (o *ConfigObjectManager[C, L, S]) Create(ctx context.Context, location L, components []string, config C) (C, error) {
xpath, err := location.XpathWithComponents(o.client.Versioning(), components...)
if err != nil {
return *new(C), err
}

err = o.service.CreateWithXpath(ctx, util.AsXpath(xpath), config)
if err != nil {
return *new(C), err
}

return o.Read(ctx, location, components)
func (o *ConfigObjectManager[C, L, S]) Create(ctx context.Context, location L, config C) (C, error) {
return o.service.Create(ctx, location, config)
}

func (o *ConfigObjectManager[C, L, S]) Update(ctx context.Context, location L, config C) (C, error) {
return o.service.Update(ctx, location, config)
}

func (o *ConfigObjectManager[C, L, S]) Read(ctx context.Context, location L, components []string) (C, error) {
xpath, err := location.XpathWithComponents(o.client.Versioning(), components...)
if err != nil {
return *new(C), err
}

obj, err := o.service.ReadWithXpath(ctx, util.AsXpath(xpath), "get")
func (o *ConfigObjectManager[C, L, S]) Read(ctx context.Context, location L) (C, error) {
obj, err := o.service.Read(ctx, location, "get")
if err != nil && sdkerrors.IsObjectNotFound(err) {
return obj, ErrObjectNotFound
}
Expand Down
39 changes: 12 additions & 27 deletions internal/manager/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package manager

import (
"context"
"errors"
"fmt"
"log/slog"

Expand Down Expand Up @@ -34,15 +33,13 @@ type EntryObject interface {
}

type EntryLocation interface {
XpathWithComponents(version.Number, ...string) ([]string, error)
XpathWithEntryName(version.Number, string) ([]string, error)
}

type SDKEntryService[E EntryObject, L EntryLocation] interface {
CreateWithXpath(context.Context, string, E) error
ReadWithXpath(context.Context, string, string) (E, error)
Create(context.Context, L, E) (E, error)
List(context.Context, L, string, string, string) ([]E, error)
Read(context.Context, L, string, string) (E, error)
Update(context.Context, L, E, string) (E, error)
Delete(context.Context, L, ...string) error
}
Expand Down Expand Up @@ -85,13 +82,8 @@ func (o *EntryObjectManager[E, L, S]) ReadMany(ctx context.Context, location L,
return filtered, nil
}

func (o *EntryObjectManager[E, L, S]) Read(ctx context.Context, location L, components []string) (E, error) {
xpath, err := location.XpathWithComponents(o.client.Versioning(), components...)
if err != nil {
return *new(E), err
}

object, err := o.service.ReadWithXpath(ctx, util.AsXpath(xpath), "get")
func (o *EntryObjectManager[E, L, S]) Read(ctx context.Context, location L, name string) (E, error) {
object, err := o.service.Read(ctx, location, name, "get")
if err != nil {
if sdkerrors.IsObjectNotFound(err) {
return *new(E), ErrObjectNotFound
Expand All @@ -102,27 +94,20 @@ func (o *EntryObjectManager[E, L, S]) Read(ctx context.Context, location L, comp
return object, nil
}

func (o *EntryObjectManager[E, L, S]) Create(ctx context.Context, location L, components []string, entry E) (E, error) {
_, err := o.Read(ctx, location, components)
if err == nil {
return *new(E), &Error{err: ErrConflict, message: fmt.Sprintf("entry '%s' already exists", entry.EntryName())}
}

if err != nil && !errors.Is(err, ErrObjectNotFound) {
return *new(E), err
}

xpath, err := location.XpathWithComponents(o.client.Versioning(), components...)
if err != nil {
func (o *EntryObjectManager[E, T, S]) Create(ctx context.Context, location T, entry E) (E, error) {
existing, err := o.service.List(ctx, location, "get", "", "")
if err != nil && !sdkerrors.IsObjectNotFound(err) {
return *new(E), err
}

err = o.service.CreateWithXpath(ctx, util.AsXpath(xpath[:len(xpath)-1]), entry)
if err != nil {
return *new(E), err
for _, elt := range existing {
if elt.EntryName() == entry.EntryName() {
return *new(E), ErrConflict
}
}

return o.Read(ctx, location, components)
obj, err := o.service.Create(ctx, location, entry)
return obj, err
}

func (o *EntryObjectManager[E, L, S]) CreateMany(ctx context.Context, location L, entries []E) ([]E, error) {
Expand Down
54 changes: 12 additions & 42 deletions internal/manager/entry_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@ package manager

import (
"context"
"errors"
"fmt"

sdkerrors "github.com/PaloAltoNetworks/pango/errors"
"github.com/PaloAltoNetworks/pango/util"
)

type SDKImportableEntryService[E EntryObject, L EntryLocation, IL ImportLocation] interface {
Create(context.Context, L, []IL, E) (E, error)
CreateWithXpath(context.Context, string, E) error
Read(context.Context, L, string, string) (E, error)
ReadWithXpath(context.Context, string, string) (E, error)
List(context.Context, L, string, string, string) ([]E, error)
Update(context.Context, L, E, string) (E, error)
Delete(context.Context, L, []IL, ...string) error
ImportToLocations(context.Context, L, []IL, string) error
UnimportFromLocations(context.Context, L, []IL, []string) error
}

type ImportableEntryObjectManager[E EntryObject, L EntryLocation, IL ImportLocation, IS SDKImportableEntryService[E, L, IL]] struct {
Expand All @@ -41,44 +34,29 @@ func (o *ImportableEntryObjectManager[E, L, IL, IS]) ReadMany(ctx context.Contex
return nil, &Error{err: ErrInternal, message: "called ReadMany on an importable singular resource"}
}

func (o *ImportableEntryObjectManager[E, L, IL, IS]) Read(ctx context.Context, location L, components []string) (E, error) {
xpath, err := location.XpathWithComponents(o.client.Versioning(), components...)
func (o *ImportableEntryObjectManager[E, L, IL, IS]) Read(ctx context.Context, location L, name string) (E, error) {
object, err := o.service.Read(ctx, location, name, "get")
if err != nil {
return *new(E), err
}

object, err := o.service.ReadWithXpath(ctx, util.AsXpath(xpath), "get")
if err != nil {
if sdkerrors.IsObjectNotFound(err) {
return *new(E), ErrObjectNotFound
}
return *new(E), &Error{err: err}
return *new(E), ErrObjectNotFound
}

return object, nil
}

func (o *ImportableEntryObjectManager[E, L, IL, IS]) Create(ctx context.Context, location L, components []string, entry E) (E, error) {
_, err := o.Read(ctx, location, components)
if err == nil {
return *new(E), &Error{err: ErrConflict, message: fmt.Sprintf("entry '%s' already exists", entry.EntryName())}
}

if err != nil && !errors.Is(err, ErrObjectNotFound) {
return *new(E), err
}

xpath, err := location.XpathWithComponents(o.client.Versioning(), components...)
if err != nil {
func (o *ImportableEntryObjectManager[E, L, IL, IS]) Create(ctx context.Context, location L, importLocs []IL, entry E) (E, error) {
existing, err := o.service.List(ctx, location, "get", "", "")
if err != nil && !sdkerrors.IsObjectNotFound(err) {
return *new(E), err
}

err = o.service.CreateWithXpath(ctx, util.AsXpath(xpath[:len(xpath)-1]), entry)
if err != nil {
return *new(E), err
for _, elt := range existing {
if elt.EntryName() == entry.EntryName() {
return *new(E), ErrConflict
}
}

return o.Read(ctx, location, components)
obj, err := o.service.Create(ctx, location, importLocs, entry)
return obj, err
}

func (o *ImportableEntryObjectManager[E, L, IL, IS]) Update(ctx context.Context, location L, entry E, name string) (E, error) {
Expand All @@ -97,11 +75,3 @@ func (o *ImportableEntryObjectManager[E, L, IL, IS]) Delete(ctx context.Context,
}
return nil
}

func (o *ImportableEntryObjectManager[E, L, IL, IS]) ImportToLocations(ctx context.Context, location L, importLocs []IL, entry string) error {
return o.service.ImportToLocations(ctx, location, importLocs, entry)
}

func (o *ImportableEntryObjectManager[E, L, IL, IS]) UnimportFromLocations(ctx context.Context, location L, importLocs []IL, entry string) error {
return o.service.UnimportFromLocations(ctx, location, importLocs, []string{entry})
}
Loading

0 comments on commit dbf2e36

Please sign in to comment.