Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
asapo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joao Alvim Oliveira Dias De Almeida
asapo
Commits
3b091040
Commit
3b091040
authored
3 years ago
by
Sergey Yakubov
Browse files
Options
Downloads
Patches
Plain Diff
fix getting list of hosts from LDAP
parent
eba39856
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
3d_party/ldap/record.ldif
+4
-0
4 additions, 0 deletions
3d_party/ldap/record.ldif
authorizer/src/asapo_authorizer/ldap_client/openldap_client.go
+26
-18
26 additions, 18 deletions
...rizer/src/asapo_authorizer/ldap_client/openldap_client.go
with
30 additions
and
18 deletions
3d_party/ldap/record.ldif
+
4
−
0
View file @
3b091040
...
...
@@ -11,11 +11,15 @@ objectClass :top
objectClass :nisNetgroup
cn:a3p00-hosts
description: Netgroup for nodes on PETRA III Beamline P00
nisNetgroupTriple: (blabla,-,)
nisNetgroupTriple: (localhost,-,)
nisNetgroupTriple: (blabla2,-,)
dn: cn=a3p07-hosts,ou=netgroup,ou=rgy,o=desy,c=de
objectClass :top
objectClass :nisNetgroup
cn:a3p07-hosts
description: Netgroup for nodes on PETRA III Beamline P07
nisNetgroupTriple: (blabla,-,)
nisNetgroupTriple: (localhost,-,)
nisNetgroupTriple: (blabla2,-,)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
authorizer/src/asapo_authorizer/ldap_client/openldap_client.go
+
26
−
18
View file @
3b091040
...
...
@@ -2,6 +2,7 @@ package ldap_client
import
(
"asapo_authorizer/common"
log
"asapo_common/logger"
"asapo_common/utils"
"net"
"strings"
...
...
@@ -11,10 +12,10 @@ import "github.com/go-ldap/ldap"
type
OpenLdapClient
struct
{
}
func
(
c
*
OpenLdapClient
)
GetAllowedIpsForBeamline
(
url
string
,
base
string
,
filter
string
)
([]
string
,
error
)
{
func
(
c
*
OpenLdapClient
)
GetAllowedIpsForBeamline
(
url
string
,
base
string
,
filter
string
)
([]
string
,
error
)
{
l
,
err
:=
ldap
.
DialURL
(
url
)
if
err
!=
nil
{
return
[]
string
{},
&
common
.
ServerError
{
utils
.
StatusServiceUnavailable
,
err
.
Error
()}
return
[]
string
{},
&
common
.
ServerError
{
utils
.
StatusServiceUnavailable
,
err
.
Error
()}
}
defer
l
.
Close
()
...
...
@@ -28,28 +29,35 @@ func (c *OpenLdapClient) GetAllowedIpsForBeamline(url string,base string,filter
sr
,
err
:=
l
.
Search
(
searchRequest
)
if
err
!=
nil
{
if
ldap
.
IsErrorWithCode
(
err
,
ldap
.
LDAPResultNoSuchObject
)
{
return
[]
string
{},
nil
if
ldap
.
IsErrorWithCode
(
err
,
ldap
.
LDAPResultNoSuchObject
)
{
return
[]
string
{},
nil
}
else
{
return
[]
string
{},
err
return
[]
string
{},
err
}
}
res
:=
make
([]
string
,
0
)
res
:=
make
([]
string
,
0
)
var
lasterr
error
=
nil
for
_
,
entry
:=
range
sr
.
Entries
{
host
:=
entry
.
GetAttributeValue
(
"nisNetgroupTriple"
)
host
=
strings
.
TrimPrefix
(
host
,
"("
)
host
=
strings
.
Split
(
host
,
","
)[
0
]
addrs
,
err
:=
net
.
LookupIP
(
host
)
if
err
!=
nil
{
return
[]
string
{},
err
}
for
_
,
addr
:=
range
addrs
{
if
ipv4
:=
addr
.
To4
();
ipv4
!=
nil
{
res
=
append
(
res
,
ipv4
.
String
())
hosts
:=
entry
.
GetAttributeValues
(
"nisNetgroupTriple"
)
for
_
,
host
:=
range
hosts
{
host
=
strings
.
TrimPrefix
(
host
,
"("
)
host
=
strings
.
Split
(
host
,
","
)[
0
]
addrs
,
err
:=
net
.
LookupIP
(
host
)
if
err
!=
nil
{
lasterr
=
err
log
.
Warning
(
"cannot lookup ip for "
+
host
)
continue
}
for
_
,
addr
:=
range
addrs
{
if
ipv4
:=
addr
.
To4
();
ipv4
!=
nil
{
res
=
append
(
res
,
ipv4
.
String
())
}
}
}
}
return
res
,
nil
if
len
(
res
)
==
0
{
return
res
,
lasterr
}
return
res
,
nil
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment