-
Notifications
You must be signed in to change notification settings - Fork 8
/
UpdateLDAPServerByName.go
123 lines (113 loc) · 4.42 KB
/
UpdateLDAPServerByName.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"encoding/xml"
"fmt"
"log"
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/http_client"
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
)
func main() {
// Define the path to the JSON configuration file
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
// Load the client OAuth credentials from the configuration file
authConfig, err := jamfpro.LoadAuthConfig(configFilePath)
if err != nil {
log.Fatalf("Failed to load client OAuth configuration: %v", err)
}
// Instantiate the default logger and set the desired log level
logLevel := http_client.LogLevelWarning // LogLevelNone // LogLevelWarning // LogLevelInfo // LogLevelDebug
// Configuration for the jamfpro
config := http_client.Config{
InstanceName: authConfig.InstanceName,
Auth: http_client.AuthConfig{
ClientID: authConfig.ClientID,
ClientSecret: authConfig.ClientSecret,
},
LogLevel: logLevel,
}
// Create a new jamfpro client instance
client, err := jamfpro.NewClient(config)
if err != nil {
log.Fatalf("Failed to create Jamf Pro client: %v", err)
}
// Define updated LDAP server details (adjust as needed)
updatedLDAPServer := &jamfpro.ResourceLDAPServers{
Connection: jamfpro.LDAPServerSubsetConnection{
Name: "Company Active Directory",
Hostname: "company.ad.com",
ServerType: "Active Directory",
Port: 389,
UseSSL: true,
AuthenticationType: "simple",
Account: jamfpro.LDAPServerSubsetConnectionAccount{
DistinguishedUsername: "CN=Administrator,CN=Users,DC=Company,DC=com",
Password: "password",
},
OpenCloseTimeout: 15,
SearchTimeout: 60,
ReferralResponse: "ignore",
UseWildcards: true,
// Additional fields if necessary...
},
MappingsForUsers: jamfpro.LDAPServerContainerMapping{
UserMappings: jamfpro.LDAPServerSubsetMappingUsers{
MapObjectClassToAnyOrAll: "all",
ObjectClasses: "organizationalPerson, user",
SearchBase: "DC=Company,DC=com",
SearchScope: "All Subtrees",
MapUserID: "uSNCreated",
MapUsername: "sAMAccountName",
MapRealName: "displayName",
MapEmailAddress: "mail",
AppendToEmailResults: "company.com",
MapDepartment: "department",
MapBuilding: "streetAddress",
MapRoom: "room",
MapTelephone: "telephoneNumber",
MapPosition: "title",
MapUserUUID: "objectGUID",
// Additional fields if necessary...
},
UserGroupMappings: jamfpro.LDAPServerSubsetMappingUserGroups{
MapObjectClassToAnyOrAll: "all",
ObjectClasses: "top, group",
SearchBase: "DC=Company,DC=com",
SearchScope: "All Subtrees",
MapGroupID: "uSNCreated",
MapGroupName: "name",
MapGroupUUID: "objectGUID",
// Additional fields if necessary...
},
UserGroupMembershipMappings: jamfpro.LDAPServerSubsetMappingUserGroupMemberships{
UserGroupMembershipStoredIn: "user object",
MapGroupMembershipToUserField: "memberOf",
AppendToUsername: "company.com",
UseDN: true,
RecursiveLookups: true,
MapUserMembershipToGroupField: true,
MapUserMembershipUseDN: true,
MapObjectClassToAnyOrAll: "all",
ObjectClasses: "group",
SearchBase: "DC=Company,DC=com",
SearchScope: "All Subtrees",
Username: "sAMAccountName",
GroupID: "uSNCreated",
UserGroupMembershipUseLDAPCompare: true,
// Additional fields if necessary...
},
// Additional fields if necessary...
},
}
// Update LDAP server by Name
LDAPServerName := "Company Active Directory" // Replace with actual LDAP server Name
updatedServer, err := client.UpdateLDAPServerByName(LDAPServerName, updatedLDAPServer)
if err != nil {
log.Fatalf("Error updating LDAP server by ID: %v", err)
}
// Print updated LDAP server details
serverXML, err := xml.MarshalIndent(updatedServer, "", " ")
if err != nil {
log.Fatalf("Error marshaling updated LDAP server data: %v", err)
}
fmt.Println("Updated LDAP Server:", string(serverXML))
}