Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
ec2fb9ed
Commit
ec2fb9ed
authored
Jul 07, 2024
by
Levin Zimmermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sync zurl to py upstream
parent
1ad088c8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
38 deletions
+38
-38
go/neo/client.go
go/neo/client.go
+18
-26
go/neo/client_test.go
go/neo/client_test.go
+20
-12
No files found.
go/neo/client.go
View file @
ec2fb9ed
...
...
@@ -484,7 +484,7 @@ func openClientByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (
// parseURL extracts information from a NEO URI and puts this information into
// a urlInfo.
func
parseURL
(
ctx
context
.
Context
,
u
*
url
.
URL
)
(
urlinfo
*
urlInfo
,
err
error
)
{
// neo(s)://
[credentials@]master1,master2,...,masterN/name
?options
// neo(s)://
name@master1,master2,...,masterN
?options
var
ssl
bool
switch
u
.
Scheme
{
...
...
@@ -493,20 +493,23 @@ func parseURL(ctx context.Context, u *url.URL) (urlinfo *urlInfo, err error) {
default
:
return
nil
,
fmt
.
Errorf
(
"invalid scheme"
)
}
cred
:=
u
.
User
.
String
()
// ca=ca.crt;cert=my.crt;key=my.key
cred
=
strings
.
ReplaceAll
(
cred
,
";"
,
"&"
)
// ; is no longer in default separators set https://github.com/golang/go/issues/25192
x
,
err
:=
xurl
.
ParseQuery
(
cred
)
name
:=
u
.
User
.
String
()
if
name
==
""
{
return
nil
,
fmt
.
Errorf
(
"cluster name not specified"
)
}
q
,
err
:=
xurl
.
ParseQuery
(
u
.
RawQuery
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"credentials: %s"
,
err
)
return
nil
,
err
}
// xpop pops k from credentials, defaulting to $NEO_<K> if envok.
// xpop pops k from query, defaulting to $NEO_<K> if envok.
xpop
:=
func
(
k
string
,
envok
bool
)
string
{
v
,
ok
:=
x
[
k
]
v
,
ok
:=
q
[
k
]
if
!
ok
&&
envok
{
v
=
os
.
Getenv
(
"NEO_"
+
strings
.
ToUpper
(
k
))
}
delete
(
x
,
k
)
delete
(
q
,
k
)
return
v
}
...
...
@@ -514,28 +517,17 @@ func parseURL(ctx context.Context, u *url.URL) (urlinfo *urlInfo, err error) {
netcfg
.
LoNode
=
xpop
(
"lonode"
,
false
)
if
!
ssl
{
if
len
(
x
)
!=
0
{
return
nil
,
fmt
.
Errorf
(
"credentials can be specified only with neos:// scheme"
)
}
//
if len(x) != 0 {
//
return nil, fmt.Errorf("credentials can be specified only with neos:// scheme")
//
}
}
else
{
netcfg
.
CA
=
xpop
(
"ca"
,
true
)
netcfg
.
Cert
=
xpop
(
"cert"
,
true
)
netcfg
.
Key
=
xpop
(
"key"
,
true
)
if
len
(
x
)
!=
0
{
return
nil
,
fmt
.
Errorf
(
"invalid credentials: %v"
,
x
)
}
}
name
:=
u
.
Path
name
=
strings
.
TrimPrefix
(
name
,
"/"
)
if
name
==
""
{
return
nil
,
fmt
.
Errorf
(
"cluster name not specified"
)
}
q
,
err
:=
xurl
.
ParseQuery
(
u
.
RawQuery
)
if
err
!=
nil
{
return
nil
,
err
// if len(x) != 0 {
// return nil, fmt.Errorf("invalid credentials: %v", x)
// }
}
// pop not yet used client options
...
...
go/neo/client_test.go
View file @
ec2fb9ed
...
...
@@ -175,7 +175,7 @@ func (n *NEOPySrv) clusterName() string {
}
func
(
n
*
NEOPySrv
)
URL
()
string
{
return
fmt
.
Sprintf
(
"%s%s
/%s"
,
n
.
opt
.
URLPrefix
(),
strings
.
Join
(
n
.
masterAddrSlice
,
","
),
n
.
clusterName
())
return
fmt
.
Sprintf
(
"%s%s
?%s"
,
n
.
opt
.
URLPrefix
(),
strings
.
Join
(
n
.
masterAddrSlice
,
","
),
n
.
opt
.
URLQuery
())
}
func
(
n
*
NEOPySrv
)
LogTail
()
(
string
,
error
)
{
...
...
@@ -361,7 +361,7 @@ func (n *NEOGoSrv) masterAddrSlice() []string {
}
func
(
n
*
NEOGoSrv
)
URL
()
string
{
return
fmt
.
Sprintf
(
"%s%s
/%s"
,
n
.
opt
.
URLPrefix
(),
strings
.
Join
(
n
.
masterAddrSlice
(),
","
),
n
.
opt
.
name
)
return
fmt
.
Sprintf
(
"%s%s
?%s"
,
n
.
opt
.
URLPrefix
(),
strings
.
Join
(
n
.
masterAddrSlice
(),
","
),
n
.
opt
.
URLQuery
()
)
}
...
...
@@ -391,22 +391,30 @@ func (opt NEOSrvOptions) Key() string {
}
// URLPrefix returns start of URL for a NEO server started with opt.
// e.g. neo://
or neos://ca=1;cert=2;key=3
@
// To be come complete returned URL has to be appended with host and
path
parts.
// e.g. neo://
test@ or neos://test
@
// To be come complete returned URL has to be appended with host and
query
parts.
func
(
opt
NEOSrvOptions
)
URLPrefix
()
string
{
zurl
:=
""
if
!
opt
.
SSL
{
zurl
=
"neo://"
}
else
{
zurl
=
"neos://"
zurl
+=
"ca="
+
url
.
QueryEscape
(
opt
.
CA
())
+
";"
zurl
+=
"cert="
+
url
.
QueryEscape
(
opt
.
Cert
())
+
";"
zurl
+=
"key="
+
url
.
QueryEscape
(
opt
.
Key
())
zurl
+=
"@"
}
zurl
+=
opt
.
name
zurl
+=
"@"
return
zurl
}
func
(
opt
NEOSrvOptions
)
URLQuery
()
string
{
query
:=
""
if
opt
.
SSL
{
query
+=
"ca="
+
url
.
QueryEscape
(
opt
.
CA
())
+
"&"
query
+=
"cert="
+
url
.
QueryEscape
(
opt
.
Cert
())
+
"&"
query
+=
"key="
+
url
.
QueryEscape
(
opt
.
Key
())
}
return
query
}
// ----------------
...
...
@@ -677,14 +685,14 @@ func TestWatch(t *testing.T) {
// scheme neo(s)://[credentials@]master1,master2,...,masterN/name?options)
func
TestParseURL
(
t
*
testing
.
T
)
{
// Most simple valid URI
testParseURL
(
t
,
"neo://
127.0.0.1/test
"
,
urlInfo
{})
testParseURL
(
t
,
"neo://
test@127.0.0.1
"
,
urlInfo
{})
// With 2 masters
testParseURL
(
t
,
"neo://
127.0.0.1,127.0.0.2/test
"
,
urlInfo
{
masterAddr
:
"127.0.0.1,127.0.0.2"
})
testParseURL
(
t
,
"neo://
test@127.0.0.1,127.0.0.2
"
,
urlInfo
{
masterAddr
:
"127.0.0.1,127.0.0.2"
})
// With ssl
u
:=
"neos://
ca=ca;cert=cert;key=key@127.0.0.1/test
"
u
:=
"neos://
test@127.0.0.1?ca=ca&cert=cert&key=key
"
testParseURL
(
t
,
u
,
urlInfo
{
netcfg
:
neonet
.
Config
{
CA
:
"ca"
,
Cert
:
"cert"
,
Key
:
"key"
}})
// With query parameters
u
=
"neo://
127.0.0.1/test?
compress=true&logfile=n.log&cache-size=256"
u
=
"neo://
test@127.0.0.1/
compress=true&logfile=n.log&cache-size=256"
testParseURL
(
t
,
u
,
urlInfo
{})
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment