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
8c974485
Commit
8c974485
authored
Dec 09, 2020
by
Kirill Smelkov
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X Adjust NEO/go to neo:// URL change + py fixups
parent
b9a42957
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
94 additions
and
51 deletions
+94
-51
go/neo/client.go
go/neo/client.go
+57
-32
go/neo/client_test.go
go/neo/client_test.go
+10
-12
go/neo/util.go
go/neo/util.go
+21
-0
neo/client/zodburi.py
neo/client/zodburi.py
+3
-5
neo/tests/client/testZODBURI.py
neo/tests/client/testZODBURI.py
+1
-1
setup.py
setup.py
+2
-1
No files found.
go/neo/client.go
View file @
8c974485
...
...
@@ -25,6 +25,8 @@ import (
"fmt"
"math/rand"
"net/url"
"os"
"strings"
"sync"
"time"
...
...
@@ -608,48 +610,66 @@ func (c *Client) Watch(ctx context.Context) (zodb.Tid, []zodb.Oid, error) {
func
openClientByURL
(
ctx
context
.
Context
,
u
*
url
.
URL
,
opt
*
zodb
.
DriverOptions
)
(
_
zodb
.
IStorageDriver
,
_
zodb
.
Tid
,
err
error
)
{
// neo
://name@master1,master2,...,masterN
?options
// neo
(s)://[credentials@]master1,master2,...,masterN/name
?options
defer
xerr
.
Contextf
(
&
err
,
"neo: open %s"
,
u
)
if
u
.
User
==
nil
{
return
nil
,
zodb
.
InvalidTid
,
fmt
.
Errorf
(
"cluster name not specified"
)
var
ssl
bool
var
ca
,
cert
,
key
string
switch
u
.
Scheme
{
case
"neo"
:
ssl
=
false
case
"neos"
:
ssl
=
true
default
:
return
nil
,
zodb
.
InvalidTid
,
fmt
.
Errorf
(
"invalid scheme"
)
}
qv
,
err
:=
url
.
ParseQuery
(
u
.
RawQuery
)
if
err
!=
nil
{
return
nil
,
zodb
.
InvalidTid
,
err
}
q
:=
map
[
string
]
string
{}
for
k
,
vv
:=
range
qv
{
if
len
(
vv
)
==
0
{
return
nil
,
zodb
.
InvalidTid
,
fmt
.
Errorf
(
"parameter %q without value"
,
k
)
cred
:=
u
.
User
.
String
()
if
!
ssl
{
if
cred
!=
""
{
return
nil
,
zodb
.
InvalidTid
,
fmt
.
Errorf
(
"credentials can be specified only with neos:// scheme"
)
}
if
len
(
vv
)
!=
1
{
return
nil
,
zodb
.
InvalidTid
,
fmt
.
Errorf
(
"duplicate parameter %q "
,
k
)
}
else
{
x
,
err
:=
parseQuery
(
cred
)
if
err
!=
nil
{
return
nil
,
zodb
.
InvalidTid
,
fmt
.
Errorf
(
"credentials: %s"
,
err
)
}
q
[
k
]
=
vv
[
0
]
}
qpop
:=
func
(
k
string
)
string
{
v
:=
q
[
k
]
delete
(
q
,
k
)
return
v
}
// xpop pops k from credentials, defaultin to NEO_<K>
xpop
:=
func
(
k
string
)
string
{
v
,
ok
:=
x
[
k
]
if
!
ok
{
v
=
os
.
Getenv
(
"NEO_"
+
strings
.
ToUpper
(
k
))
}
delete
(
x
,
k
)
return
v
}
ssl
:=
false
ca
:=
qpop
(
"ca"
)
cert
:=
qpop
(
"cert"
)
key
:=
qpop
(
"key"
)
ca
=
xpop
(
"ca"
)
cert
=
xpop
(
"cert"
)
key
=
xpop
(
"key"
)
if
len
(
q
)
!=
0
{
return
nil
,
zodb
.
InvalidTid
,
fmt
.
Errorf
(
"invalid query: %v"
,
q
)
}
if
len
(
x
)
!=
0
{
return
nil
,
zodb
.
InvalidTid
,
fmt
.
Errorf
(
"invalid credentials: %v"
,
x
)
}
if
ca
!=
""
||
cert
!=
""
||
key
!=
""
{
if
!
(
ca
!=
""
&&
cert
!=
""
&&
key
!=
""
)
{
return
nil
,
zodb
.
InvalidTid
,
fmt
.
Errorf
(
"incomplete ca/cert/key provided"
)
}
ssl
=
true
}
name
:=
u
.
Path
if
strings
.
HasPrefix
(
name
,
"/"
)
{
name
=
name
[
1
:
]
}
if
name
==
""
{
return
nil
,
zodb
.
InvalidTid
,
fmt
.
Errorf
(
"cluster name not specified"
)
}
q
,
err
:=
parseQuery
(
u
.
RawQuery
)
if
err
!=
nil
{
return
nil
,
zodb
.
InvalidTid
,
err
}
if
len
(
q
)
!=
0
{
return
nil
,
zodb
.
InvalidTid
,
fmt
.
Errorf
(
"invalid query: %v"
,
q
)
}
...
...
@@ -666,7 +686,7 @@ func openClientByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (
net
=
xnet
.
NetTLS
(
net
,
tlsCfg
)
}
c
:=
NewClient
(
u
.
User
.
Username
()
,
u
.
Host
,
net
)
c
:=
NewClient
(
name
,
u
.
Host
,
net
)
c
.
watchq
=
opt
.
Watchq
defer
func
()
{
if
err
!=
nil
{
...
...
@@ -712,10 +732,15 @@ func openClientByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (
}
func
(
c
*
Client
)
URL
()
string
{
// XXX neos:// depending whether it was tls
// XXX options if such were given to open are discarded
// (but we need to be able to construct URL if Client was created via NewClient directly)
return
fmt
.
Sprintf
(
"neo://%s@%s"
,
c
.
node
.
ClusterName
,
c
.
node
.
MasterAddr
)
zurl
:=
"neo"
if
strings
.
Contains
(
c
.
node
.
Net
.
Network
(),
"+tls"
)
{
zurl
+=
"s"
}
zurl
+=
fmt
.
Sprintf
(
"://%s/%s"
,
c
.
node
.
MasterAddr
,
c
.
node
.
ClusterName
)
return
zurl
}
func
init
()
{
...
...
go/neo/client_test.go
View file @
8c974485
...
...
@@ -26,7 +26,6 @@ import (
"net/url"
"os"
"os/exec"
"strings"
"testing"
"time"
...
...
@@ -175,19 +174,18 @@ func (n *NEOPySrv) MasterAddr() string {
}
func
(
n
*
NEOPySrv
)
ZUrl
()
string
{
zurl
:=
fmt
.
Sprintf
(
"neo://%s@%s"
,
n
.
ClusterName
(),
n
.
MasterAddr
())
argv
:=
[]
string
{}
if
n
.
opt
.
SSL
{
argv
=
append
(
argv
,
"ca="
+
url
.
QueryEscape
(
n
.
CA
))
argv
=
append
(
argv
,
"cert="
+
url
.
QueryEscape
(
n
.
Cert
))
argv
=
append
(
argv
,
"key="
+
url
.
QueryEscape
(
n
.
Key
))
}
if
len
(
argv
)
!=
0
{
zurl
+=
"?"
zurl
+=
strings
.
Join
(
argv
,
"&"
)
zurl
:=
""
if
!
n
.
opt
.
SSL
{
zurl
=
"neo://"
}
else
{
zurl
=
"neos://"
zurl
+=
"ca="
+
url
.
QueryEscape
(
n
.
CA
)
+
";"
zurl
+=
"cert="
+
url
.
QueryEscape
(
n
.
Cert
)
+
";"
zurl
+=
"key="
+
url
.
QueryEscape
(
n
.
Key
)
zurl
+=
"@"
}
zurl
+=
fmt
.
Sprintf
(
"%s/%s"
,
n
.
MasterAddr
(),
n
.
ClusterName
())
return
zurl
}
...
...
go/neo/util.go
View file @
8c974485
...
...
@@ -26,6 +26,7 @@ import (
"fmt"
"io"
"io/ioutil"
"net/url"
"lab.nexedi.com/kirr/go123/xerr"
...
...
@@ -148,3 +149,23 @@ func tlsForSSL(ca, cert, key string) (_ *tls.Config, err error) {
return
tlsCfg
,
nil
}
// parseQuery parses query string into regular map.
// see also url.ParseQuery
func
parseQuery
(
query
string
)
(
map
[
string
]
string
,
error
)
{
qv
,
err
:=
url
.
ParseQuery
(
query
)
if
err
!=
nil
{
return
nil
,
err
}
q
:=
map
[
string
]
string
{}
for
k
,
vv
:=
range
qv
{
if
len
(
vv
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"parameter %q without value"
,
k
)
}
if
len
(
vv
)
!=
1
{
return
nil
,
fmt
.
Errorf
(
"duplicate parameter %q "
,
k
)
}
q
[
k
]
=
vv
[
0
]
}
return
q
,
nil
}
neo/client/zodburi.py
View file @
8c974485
...
...
@@ -82,11 +82,9 @@ def _resolve_uri(uri):
# parse credentials
if
cred
:
if
scheme
!=
"neos"
:
raise
ValueError
(
"invalid uri: %s : credentials can be provided only with neos:// scheme"
%
uri
)
# ca:ca.crt;cert:my.crt;key:my.key
credv
=
cred
.
split
(
';'
)
for
arg
in
credv
:
k
,
v
=
arg
.
split
(
':'
,
1
)
raise
ValueError
(
"invalid uri: %s : credentials can be specified only with neos:// scheme"
%
uri
)
# ca=ca.crt;cert=my.crt;key=my.key
for
k
,
v
in
OrderedDict
(
parse_qsl
(
cred
)).
items
():
if
k
not
in
_credopts
:
raise
ValueError
(
"invalid uri: %s : unexpected credential %s"
%
(
uri
,
k
))
neokw
[
k
]
=
v
...
...
neo/tests/client/testZODBURI.py
View file @
8c974485
...
...
@@ -42,7 +42,7 @@ testv = [
"""
,
{}),
(
"neos://ca
:qqq;cert:rrr;key:
sss@[2001:67c:1254:2a::1]:1234,master2:port2/db4?read_only=false"
(
"neos://ca
=qqq;cert=rrr;key=
sss@[2001:67c:1254:2a::1]:1234,master2:port2/db4?read_only=false"
"&compress=true&logfile=xxx&alpha=111&dynamic_master_list=zzz"
"&beta=222"
,
"""
\
...
...
setup.py
View file @
8c974485
...
...
@@ -104,7 +104,8 @@ setup(
'stat_zodb=neo.tests.stat_zodb:main'
,
],
'zodburi.resolvers'
:
[
'neo = neo.client.zodburi:resolve_uri [client]'
,
'neo = neo.client.zodburi:resolve_uri [client]'
,
'neos = neo.client.zodburi:resolve_uri [client]'
,
],
},
install_requires
=
[
...
...
Levin Zimmermann
@levin.zimmermann
mentioned in commit
573514c6
·
May 17, 2023
mentioned in commit
573514c6
mentioned in commit 573514c6e8ecf0f1c28a821f9db037850a711472
Toggle commit list
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