Skip to content

Commit 811ebe8

Browse files
authored
feat: add SSO certificate support (#779)
* feat: add SSO certificate support * fix: correct filename in comment for SSO certificate API
1 parent 9bff47e commit 811ebe8

File tree

4 files changed

+180
-5
lines changed

4 files changed

+180
-5
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
8+
)
9+
10+
func main() {
11+
// Define the path to the JSON configuration file
12+
configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/clientconfig.json"
13+
14+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
15+
if err != nil {
16+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
17+
}
18+
19+
// Create new SSO certificate
20+
newCert, err := client.CreateSSOCertificate()
21+
if err != nil {
22+
log.Fatalf("Error generating new SSO certificate: %v", err)
23+
}
24+
25+
fmt.Println("New SSO certificate generated successfully!")
26+
fmt.Printf("Certificate Type: %s\n", newCert.Keystore.Type)
27+
fmt.Printf("Setup Type: %s\n", newCert.Keystore.KeystoreSetupType)
28+
29+
// Print validation status for each key
30+
for _, key := range newCert.Keystore.Keys {
31+
fmt.Printf("Key ID: %s, Valid: %v\n", key.ID, key.Valid)
32+
}
33+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
8+
)
9+
10+
func main() {
11+
// Define the path to the JSON configuration file
12+
configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/clientconfig.json"
13+
14+
// Initialize the Jamf Pro client
15+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
16+
if err != nil {
17+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
18+
}
19+
20+
// Delete the SSO certificate
21+
err = client.DeleteSSOCertificate()
22+
if err != nil {
23+
log.Fatalf("Error deleting SSO certificate: %v", err)
24+
}
25+
26+
fmt.Println("SSO certificate successfully deleted")
27+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
8+
)
9+
10+
func main() {
11+
// Define the path to the JSON configuration file
12+
configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/clientconfig.json"
13+
14+
// Initialize the Jamf Pro client
15+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
16+
if err != nil {
17+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
18+
}
19+
20+
// Get SSO certificate information
21+
certInfo, err := client.GetSSOCertificate()
22+
if err != nil {
23+
log.Fatalf("Error fetching SSO certificate information: %v", err)
24+
}
25+
26+
// Print certificate details
27+
fmt.Printf("Certificate Type: %s\n", certInfo.Keystore.Type)
28+
fmt.Printf("Keystore Filename: %s\n", certInfo.Keystore.KeystoreFileName)
29+
fmt.Printf("Setup Type: %s\n", certInfo.Keystore.KeystoreSetupType)
30+
31+
if certInfo.KeystoreDetails != nil {
32+
fmt.Printf("Issuer: %s\n", certInfo.KeystoreDetails.Issuer)
33+
fmt.Printf("Subject: %s\n", certInfo.KeystoreDetails.Subject)
34+
fmt.Printf("Expiration: %s\n", certInfo.KeystoreDetails.Expiration)
35+
}
36+
}
Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,87 @@
11
// jamfproapi_sso_certificate.go
2-
// Jamf Pro Api - SSO Certificate
3-
// api reference: https://developer.jamf.com/jamf-pro/reference/get_v2-sso-cert
4-
// Jamf Pro API requires the structs to support a JSON data structure.
5-
62
package jamfpro
73

8-
// TODO - Awaiting some investigation around what this endpoint actually returns (json or cert or ???)
4+
import (
5+
"fmt"
6+
)
7+
8+
const (
9+
uriSSOCert = "/api/v2/sso/cert"
10+
)
11+
12+
// Resource structures
13+
type ResourceSSOCertKeystore struct {
14+
Key string `json:"key,omitempty"`
15+
Keys []ResourceCertKey `json:"keys,omitempty"`
16+
Type string `json:"type,omitempty"`
17+
KeystoreFileName string `json:"keystoreFileName,omitempty"`
18+
KeystoreSetupType string `json:"keystoreSetupType,omitempty"`
19+
}
20+
21+
type ResourceCertKey struct {
22+
ID string `json:"id,omitempty"`
23+
Valid bool `json:"valid"`
24+
}
25+
26+
type ResourceSSOKeystoreDetails struct {
27+
Keys []string `json:"keys,omitempty"`
28+
Issuer string `json:"issuer,omitempty"`
29+
Subject string `json:"subject,omitempty"`
30+
Expiration string `json:"expiration,omitempty"`
31+
SerialNumber int `json:"serialNumber,omitempty"`
32+
}
33+
34+
type ResourceSSOKeystoreResponse struct {
35+
Keystore ResourceSSOCertKeystore `json:"keystore,omitempty"`
36+
KeystoreDetails *ResourceSSOKeystoreDetails `json:"keystoreDetails,omitempty"`
37+
}
38+
39+
// GetSSOCertificate gets the certificate currently configured for use with SSO
40+
func (c *Client) GetSSOCertificate() (*ResourceSSOKeystoreResponse, error) {
41+
endpoint := uriSSOCert
42+
43+
var certResponse ResourceSSOKeystoreResponse
44+
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &certResponse)
45+
if err != nil {
46+
return nil, fmt.Errorf(errMsgFailedGet, "sso certificate", err)
47+
}
48+
49+
if resp != nil && resp.Body != nil {
50+
defer resp.Body.Close()
51+
}
52+
53+
return &certResponse, nil
54+
}
55+
56+
// CreateSSOCertificate generates a new certificate for signing SSO requests
57+
func (c *Client) CreateSSOCertificate() (*ResourceSSOKeystoreResponse, error) {
58+
endpoint := uriSSOCert
59+
60+
var certResponse ResourceSSOKeystoreResponse
61+
resp, err := c.HTTP.DoRequest("POST", endpoint, nil, &certResponse)
62+
if err != nil {
63+
return nil, fmt.Errorf(errMsgFailedCreate, "sso certificate", err)
64+
}
65+
66+
if resp != nil && resp.Body != nil {
67+
defer resp.Body.Close()
68+
}
69+
70+
return &certResponse, nil
71+
}
72+
73+
// DeleteSSOCertificate deletes the currently configured certificate used by SSO
74+
func (c *Client) DeleteSSOCertificate() error {
75+
endpoint := uriSSOCert
76+
77+
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
78+
if err != nil {
79+
return fmt.Errorf(errMsgFailedDelete, "sso certificate", err)
80+
}
81+
82+
if resp != nil && resp.Body != nil {
83+
defer resp.Body.Close()
84+
}
85+
86+
return nil
87+
}

0 commit comments

Comments
 (0)