Skip to content

Commit

Permalink
feat: Add methods for node custom certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
alperencelik committed Feb 19, 2024
1 parent 7d43d0f commit b3539e7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,16 @@ func (n *Node) FirewallRulesUpdate(ctx context.Context, rule *FirewallRule) erro
func (n *Node) FirewallRulesDelete(ctx context.Context, rulePos int) error {
return n.client.Delete(ctx, fmt.Sprintf("/nodes/%s/firewall/rules/%d", n.Name, rulePos), nil)
}

func (n *Node) UploadCustomCertificate(ctx context.Context, cert *CustomCertificate) error {
return n.client.Post(ctx, fmt.Sprintf("/nodes/%s/certificates/custom", n.Name), cert, nil)

Check warning on line 245 in nodes.go

View check run for this annotation

Codecov / codecov/patch

nodes.go#L244-L245

Added lines #L244 - L245 were not covered by tests
}

func (n *Node) DeleteCustomCertificate(ctx context.Context) error {
return n.client.Delete(ctx, fmt.Sprintf("/nodes/%s/certificates/custom", n.Name), nil)

Check warning on line 249 in nodes.go

View check run for this annotation

Codecov / codecov/patch

nodes.go#L248-L249

Added lines #L248 - L249 were not covered by tests
}

func (n *Node) GetCustomCertificates(ctx context.Context) (certs *NodeCertificates, err error) {
err = n.client.Get(ctx, fmt.Sprintf("/nodes/%s/certificates/info", n.Name), &certs)
return

Check warning on line 254 in nodes.go

View check run for this annotation

Codecov / codecov/patch

nodes.go#L252-L254

Added lines #L252 - L254 were not covered by tests
}
22 changes: 22 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1159,3 +1159,25 @@ type StorageContent struct {
Verification string `json:"verification,omitempty"`
VMID uint64 `json:"vmid,omitempty"`
}

type NodeCertificates []*NodeCertificate

type NodeCertificate struct {
Filename string `json:"filename,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
Issuer string `json:"issuer,omitempty"`
NotAfter string `json:"not-after,omitempty"`
NotBefore string `json:"not-before,omitempty"`
Pem string `json:"pem,omitempty"`
PublicKeyBits int `json:"public-key-bits,omitempty"`
PublicKeyType string `json:"public-key-type,omitempty"`
San []string `json:"san,omitempty"`
Subject string `json:"subject,omitempty"`
}

type CustomCertificate struct {
Certificates string `json:"certificates,omitempty"` // PEM encoded certificate (chain)
Force bool `json:"force,omitempty"` // overwrite existing certificate
Key string `json:"key,omitempty"` // PEM encoded private key
Restart bool `json:"restart,omitempty"` // restart pveproxy
}

0 comments on commit b3539e7

Please sign in to comment.