Skip to content

Commit d235f87

Browse files
committed
feat(specs): Add spec, tests and example for certificate import
1 parent 61372dd commit d235f87

File tree

10 files changed

+1431
-3
lines changed

10 files changed

+1431
-3
lines changed

assets/pango/client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ func (c *Client) Communicate(ctx context.Context, cmd util.PangoCommand, strip b
971971
}
972972

973973
// ImportFile imports the given file into PAN-OS.
974-
func (c *Client) ImportFile(ctx context.Context, cmd *xmlapi.Import, content, filename, fp string, strip bool, ans any) ([]byte, *http.Response, error) {
974+
func (c *Client) ImportFile(ctx context.Context, cmd *xmlapi.Import, content []byte, filename, fp string, strip bool, ans any) ([]byte, *http.Response, error) {
975975
if cmd == nil {
976976
return nil, nil, fmt.Errorf("cmd is nil")
977977
}
@@ -1002,7 +1002,7 @@ func (c *Client) ImportFile(ctx context.Context, cmd *xmlapi.Import, content, fi
10021002
return nil, nil, err
10031003
}
10041004

1005-
if _, err = io.Copy(w2, strings.NewReader(content)); err != nil {
1005+
if _, err = io.Copy(w2, bytes.NewReader(content)); err != nil {
10061006
return nil, nil, err
10071007
}
10081008

@@ -1038,6 +1038,8 @@ func (c *Client) ExportFile(ctx context.Context, cmd *xmlapi.Export, ans any) (s
10381038
return "", nil, nil, err
10391039
}
10401040

1041+
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
1042+
10411043
b, resp, err := c.sendRequest(ctx, req, false, ans)
10421044
if err != nil {
10431045
return "", b, resp, err

assets/pango/util/pangoclient.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type PangoClient interface {
3434

3535
// Specialized communication functions around specific XPI API commands.
3636
MultiConfig(context.Context, *xmlapi.MultiConfig, bool, url.Values) ([]byte, *http.Response, *xmlapi.MultiConfigResponse, error)
37-
ImportFile(context.Context, *xmlapi.Import, string, string, string, bool, any) ([]byte, *http.Response, error)
37+
ImportFile(context.Context, *xmlapi.Import, []byte, string, string, bool, any) ([]byte, *http.Response, error)
3838
ExportFile(context.Context, *xmlapi.Export, any) (string, []byte, *http.Response, error)
3939

4040
// Operational functions in use by one or more resources / data sources / namespaces.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
resource "panos_certificate_import" "example1" {
2+
location = { template = { name = panos_template.example.name } }
3+
4+
local = {
5+
pem = {
6+
certificate = file("cert.pem") # PEM-encoded certificate
7+
private_key = file("cert.key") # PEM-encoded private key
8+
passphrase = "example-passphrase" # passphrase used to decrypt private key
9+
}
10+
}
11+
}
12+
13+
resource "panos_template" "example2" {
14+
location = { panorama = {} }
15+
16+
name = "example-template"
17+
18+
local = {
19+
pcks12 = {
20+
certificate = base64encode(file("cert.pkcs12"))
21+
passphrase = "example-passphrase"
22+
}
23+
}
24+
}

assets/terraform/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/hashicorp/terraform-plugin-testing v1.12.0
1414
github.com/onsi/ginkgo/v2 v2.22.2
1515
github.com/onsi/gomega v1.36.2
16+
software.sslmate.com/src/go-pkcs12 v0.5.0
1617
)
1718

1819
require (

assets/terraform/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,5 @@ gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
253253
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
254254
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
255255
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
256+
software.sslmate.com/src/go-pkcs12 v0.5.0 h1:EC6R394xgENTpZ4RltKydeDUjtlM5drOYIG9c6TVj2M=
257+
software.sslmate.com/src/go-pkcs12 v0.5.0/go.mod h1:Qiz0EyvDRJjjxGyUQa2cCNZn/wMyzrRJ/qcDXOQazLI=

0 commit comments

Comments
 (0)