Skip to content

Commit 06dbd6a

Browse files
authored
feat: fix/complete cloud-ldaps support (#781)
* feat: fix/update cloud-ldaps support * add newline between responses * Add missing fields to CloudLdapKeystore struct
1 parent 811ebe8 commit 06dbd6a

File tree

5 files changed

+256
-23
lines changed

5 files changed

+256
-23
lines changed

examples/cloud_ldap/CreateCloudIdentityProviderLdap/CreateCloudIdentityProviderLdap.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func main() {
1212
// Define the path to the JSON configuration file
13-
configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json"
13+
configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/clientconfig.json"
1414

1515
// Initialize the Jamf Pro client with the HTTP client configuration
1616
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
@@ -22,14 +22,14 @@ func main() {
2222
request := &jamfpro.ResourceCloudLdap{
2323
CloudIdPCommon: &jamfpro.CloudIdPCommon{
2424
ProviderName: "GOOGLE",
25-
DisplayName: "test",
25+
DisplayName: "Google LDAP",
2626
},
2727
Server: &jamfpro.CloudLdapServer{
2828
Enabled: true,
2929
Keystore: &jamfpro.CloudLdapKeystore{
30-
Password: "thing",
31-
FileBytes: "WlhoaGJYQnNaU0J2WmlCaElHSmhjMlUyTkNCbGJtTnZaR1ZrSUhaaGJHbGtJSEF4TWk0Z2EyVjVjM1J2Y21VZ1ptbHNaUT09",
32-
FileName: "keystore.jks", // Added example filename
30+
Password: "supersecretpassword",
31+
FileBytes: "MIIJsQIBAzCCCXcGCSqGS...",
32+
FileName: "keystore.p12", // Added example filename
3333
},
3434
UseWildcards: true,
3535
ConnectionType: "LDAPS",
@@ -46,25 +46,25 @@ func main() {
4646
SearchScope: "ALL_SUBTREES",
4747
ObjectClasses: "inetOrgPerson",
4848
SearchBase: "ou=Users",
49-
AdditionalSearchBase: "thing",
50-
UserID: "mail",
51-
Username: "uid",
49+
AdditionalSearchBase: "",
50+
UserID: "uid",
51+
Username: "mail",
5252
RealName: "displayName",
5353
EmailAddress: "mail",
5454
Department: "departmentNumber",
55-
Building: "building",
56-
Room: "room",
57-
Phone: "phone",
58-
Position: "position",
55+
Building: "",
56+
Room: "",
57+
Phone: "",
58+
Position: "title",
5959
UserUuid: "uid",
6060
},
6161
GroupMappings: jamfpro.CloudIdentityProviderDefaultMappingsSubsetGroupMappings{
6262
ObjectClassLimitation: "ANY_OBJECT_CLASSES",
6363
SearchScope: "ALL_SUBTREES",
6464
ObjectClasses: "groupOfNames",
6565
SearchBase: "ou=Groups",
66-
GroupID: "cn=",
67-
GroupName: "cn=",
66+
GroupID: "cn",
67+
GroupName: "cn",
6868
GroupUuid: "gidNumber",
6969
},
7070
MembershipMappings: jamfpro.CloudIdentityProviderDefaultMappingsSubsetMembershipMappings{
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 with the HTTP client configuration
15+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
16+
if err != nil {
17+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
18+
}
19+
20+
// Define the ID of the Cloud LDAP configuration you want to delete
21+
ldapID := "1022" // Replace with your actual LDAP configuration ID
22+
23+
// Delete the Cloud LDAP configuration
24+
err = client.DeleteCloudIdentityProviderLdapByID(ldapID)
25+
if err != nil {
26+
log.Fatalf("Error deleting cloud LDAP configuration: %v", err)
27+
}
28+
29+
fmt.Printf("Successfully deleted Cloud LDAP configuration with ID: %s\n", ldapID)
30+
}
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+
"encoding/json"
5+
"fmt"
6+
"log"
7+
8+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
9+
)
10+
11+
func main() {
12+
// Define the path to the JSON configuration file
13+
configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/clientconfig.json"
14+
15+
// Initialize the Jamf Pro client with the HTTP client configuration
16+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
17+
if err != nil {
18+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
19+
}
20+
21+
// Define the ID of the Cloud LDAP configuration you want to retrieve
22+
cloudLdapID := "1019" // Replace with your actual Cloud LDAP ID
23+
24+
// Get the Cloud LDAP configuration by ID
25+
cloudLdap, err := client.GetCloudIdentityProviderLdapByID(cloudLdapID)
26+
if err != nil {
27+
log.Fatalf("Error retrieving cloud LDAP configuration: %v", err)
28+
}
29+
30+
// Pretty print the response in JSON
31+
responseJSON, err := json.MarshalIndent(cloudLdap, "", " ") // Indent with 4 spaces
32+
if err != nil {
33+
log.Fatalf("Error marshaling response data: %v", err)
34+
}
35+
fmt.Printf("Cloud LDAP Configuration (ID: %s):\n%s\n", cloudLdapID, string(responseJSON))
36+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"log"
7+
8+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
9+
)
10+
11+
func main() {
12+
// Define the path to the JSON configuration file
13+
configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/clientconfig.json"
14+
15+
// Initialize the Jamf Pro client with the HTTP client configuration
16+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
17+
if err != nil {
18+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
19+
}
20+
21+
// Define the ID of the Cloud LDAP configuration you want to update
22+
ldapID := "1022" // Replace with your actual LDAP configuration ID
23+
24+
// Create the update request body
25+
request := &jamfpro.ResourceCloudLdap{
26+
CloudIdPCommon: &jamfpro.CloudIdPCommon{
27+
ID: ldapID,
28+
ProviderName: "GOOGLE",
29+
DisplayName: "Google LDAP Updated", // Example of updated display name
30+
},
31+
Server: &jamfpro.CloudLdapServer{
32+
Enabled: true,
33+
Keystore: &jamfpro.CloudLdapKeystore{
34+
Password: "supersecretpassword",
35+
FileBytes: "MIIJsQIBAzCCCXcGCSqGS...",
36+
FileName: "keystore.p12",
37+
},
38+
UseWildcards: true,
39+
ConnectionType: "LDAPS",
40+
ServerUrl: "ldap.google.com",
41+
DomainName: "jamf.com",
42+
Port: 636,
43+
ConnectionTimeout: 15,
44+
SearchTimeout: 60,
45+
MembershipCalculationOptimizationEnabled: true,
46+
},
47+
Mappings: &jamfpro.CloudLdapMappings{
48+
UserMappings: jamfpro.CloudIdentityProviderDefaultMappingsSubsetUserMappings{
49+
ObjectClassLimitation: "ANY_OBJECT_CLASSES",
50+
SearchScope: "ALL_SUBTREES",
51+
ObjectClasses: "inetOrgPerson",
52+
SearchBase: "ou=Users",
53+
AdditionalSearchBase: "",
54+
UserID: "uid",
55+
Username: "mail",
56+
RealName: "displayName",
57+
EmailAddress: "mail",
58+
Department: "departmentNumber",
59+
Building: "",
60+
Room: "",
61+
Phone: "",
62+
Position: "title",
63+
UserUuid: "uid",
64+
},
65+
GroupMappings: jamfpro.CloudIdentityProviderDefaultMappingsSubsetGroupMappings{
66+
ObjectClassLimitation: "ANY_OBJECT_CLASSES",
67+
SearchScope: "ALL_SUBTREES",
68+
ObjectClasses: "groupOfNames",
69+
SearchBase: "ou=Groups",
70+
GroupID: "cn",
71+
GroupName: "cn",
72+
GroupUuid: "gidNumber",
73+
},
74+
MembershipMappings: jamfpro.CloudIdentityProviderDefaultMappingsSubsetMembershipMappings{
75+
GroupMembershipMapping: "memberOf",
76+
},
77+
},
78+
}
79+
80+
// Update the Cloud LDAP configuration
81+
resp, err := client.UpdateCloudIdentityProviderLdap(ldapID, request)
82+
if err != nil {
83+
log.Fatalf("Error updating cloud LDAP configuration: %v", err)
84+
}
85+
86+
// Pretty print the response
87+
responseJSON, err := json.MarshalIndent(resp, "", " ")
88+
if err != nil {
89+
log.Fatalf("Error marshaling response data: %v", err)
90+
}
91+
92+
fmt.Printf("Successfully updated Cloud LDAP configuration with ID %s:\n%s\n", ldapID, string(responseJSON))
93+
94+
// Optionally fetch and display the updated configuration
95+
updatedConfig, err := client.GetCloudIdentityProviderLdapByID(ldapID)
96+
if err != nil {
97+
log.Fatalf("Error fetching updated configuration: %v", err)
98+
}
99+
100+
// Pretty print the updated configuration
101+
updatedJSON, err := json.MarshalIndent(updatedConfig, "", " ")
102+
if err != nil {
103+
log.Fatalf("Error marshaling updated configuration data: %v", err)
104+
}
105+
106+
fmt.Printf("\nFull Updated Configuration:\n%s\n", string(updatedJSON))
107+
}

sdk/jamfpro/jamfproapi_cloud_ldap.go

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@
55

66
package jamfpro
77

8-
import "fmt"
8+
import (
9+
"fmt"
10+
)
911

1012
// TODO - Figure out if we need this.
1113

1214
const uriCloudLdaps = "/api/v2/cloud-ldaps"
1315

1416
// Responses
1517

18+
type ResponseCloudIdentityProviderLdapCreated struct {
19+
ID string `json:"id"`
20+
Href string `json:"href"`
21+
}
22+
1623
type ResponseCloudIdentityProviderDefaultMappings struct {
1724
CloudIdentityProviderDefaultMappingsSubsetUserMappings CloudIdentityProviderDefaultMappingsSubsetUserMappings `json:"userMappings"`
1825
CloudIdentityProviderDefaultMappingsSubsetGroupMappings CloudIdentityProviderDefaultMappingsSubsetGroupMappings `json:"groupMappings"`
@@ -50,7 +57,7 @@ type CloudIdentityProviderDefaultMappingsSubsetGroupMappings struct {
5057
}
5158

5259
type CloudIdentityProviderDefaultMappingsSubsetMembershipMappings struct {
53-
GroupMembershipMapping string `json:"memberOf"`
60+
GroupMembershipMapping string `json:"groupMembershipMapping"`
5461
}
5562

5663
type ResourceCloudLdap struct {
@@ -60,6 +67,7 @@ type ResourceCloudLdap struct {
6067
}
6168

6269
type CloudIdPCommon struct {
70+
ID string `json:"id,omitempty"`
6371
ProviderName string `json:"providerName"` // GOOGLE or AZURE
6472
DisplayName string `json:"displayName"`
6573
}
@@ -78,9 +86,12 @@ type CloudLdapServer struct {
7886
}
7987

8088
type CloudLdapKeystore struct {
81-
Password string `json:"password"`
82-
FileBytes string `json:"fileBytes"`
83-
FileName string `json:"fileName"`
89+
Type string `json:"type,omitempty"`
90+
ExpirationDate string `json:"expirationDate,omitempty"`
91+
Subject string `json:"subject,omitempty"`
92+
FileName string `json:"fileName,omitempty"`
93+
Password string `json:"password,omitempty"`
94+
FileBytes string `json:"fileBytes,omitempty"`
8495
}
8596

8697
type CloudLdapMappings struct {
@@ -109,12 +120,11 @@ func (c *Client) GetDefaultCloudIdentityProviderDefaultMappings(providerName str
109120
}
110121

111122
// CreateCloudIdentityProviderLdap creates a new Cloud Identity Provider configuration
112-
func (c *Client) CreateCloudIdentityProviderLdap(config *ResourceCloudLdap) (*ResponseCloudIdentityProviderDefaultMappings, error) {
123+
func (c *Client) CreateCloudIdentityProviderLdap(config *ResourceCloudLdap) (*ResponseCloudIdentityProviderLdapCreated, error) {
113124
endpoint := uriCloudLdaps
114125

115-
// Send the request
116-
var out ResponseCloudIdentityProviderDefaultMappings
117-
resp, err := c.HTTP.DoRequest("POST", endpoint, config, &out)
126+
var response ResponseCloudIdentityProviderLdapCreated
127+
resp, err := c.HTTP.DoRequest("POST", endpoint, config, &response)
118128
if err != nil {
119129
return nil, fmt.Errorf(errMsgFailedCreate, "cloud identity provider", err)
120130
}
@@ -123,5 +133,55 @@ func (c *Client) CreateCloudIdentityProviderLdap(config *ResourceCloudLdap) (*Re
123133
defer resp.Body.Close()
124134
}
125135

136+
return &response, nil
137+
}
138+
139+
// GetCloudIdentityProviderLdapByID retrieves a specific Cloud Identity Provider LDAP configuration by ID
140+
func (c *Client) GetCloudIdentityProviderLdapByID(id string) (*ResourceCloudLdap, error) {
141+
endpoint := fmt.Sprintf("%s/%s", uriCloudLdaps, id)
142+
143+
var out ResourceCloudLdap
144+
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &out)
145+
if err != nil {
146+
return nil, fmt.Errorf(errMsgFailedGet, "cloud identity provider LDAP", err)
147+
}
148+
149+
if resp != nil && resp.Body != nil {
150+
defer resp.Body.Close()
151+
}
152+
126153
return &out, nil
127154
}
155+
156+
// UpdateCloudIdentityProviderLdap updates an existing Cloud Identity Provider LDAP configuration
157+
func (c *Client) UpdateCloudIdentityProviderLdap(id string, config *ResourceCloudLdap) (*ResourceCloudLdap, error) {
158+
endpoint := fmt.Sprintf("%s/%s", uriCloudLdaps, id)
159+
160+
var out ResourceCloudLdap
161+
resp, err := c.HTTP.DoRequest("PUT", endpoint, config, &out)
162+
if err != nil {
163+
return nil, fmt.Errorf(errMsgFailedUpdate, "cloud identity provider LDAP", err)
164+
}
165+
166+
if resp != nil && resp.Body != nil {
167+
defer resp.Body.Close()
168+
}
169+
170+
return &out, nil
171+
}
172+
173+
// DeleteCloudIdentityProviderLdapByID deletes a Cloud Identity Provider LDAP configuration by ID
174+
func (c *Client) DeleteCloudIdentityProviderLdapByID(id string) error {
175+
endpoint := fmt.Sprintf("%s/%s", uriCloudLdaps, id)
176+
177+
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
178+
if err != nil {
179+
return fmt.Errorf(errMsgFailedDelete, "cloud identity provider LDAP", err)
180+
}
181+
182+
if resp != nil && resp.Body != nil {
183+
defer resp.Body.Close()
184+
}
185+
186+
return nil
187+
}

0 commit comments

Comments
 (0)