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
816ad564
Commit
816ad564
authored
Jul 07, 2024
by
Levin Zimmermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Y client: Fix URI scheme to move credentials out of query"
This reverts commit
b9a42957
.
parent
56f0bded
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
54 deletions
+24
-54
neo/client/zodburi.py
neo/client/zodburi.py
+9
-33
neo/tests/client/testZODBURI.py
neo/tests/client/testZODBURI.py
+15
-21
No files found.
neo/client/zodburi.py
View file @
816ad564
#
# Copyright (C) 2017-20
20
Nexedi SA
# Copyright (C) 2017-20
19
Nexedi SA
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
...
...
@@ -17,7 +17,7 @@
URI format:
neo
(s)://[credentials@]master1,master2,...,masterN/name
?options
neo
://name@master1,master2,...,masterN
?options
"""
import
ZODB.config
...
...
@@ -27,9 +27,6 @@ from cStringIO import StringIO
from
collections
import
OrderedDict
from
urlparse
import
urlsplit
,
parse_qsl
# _credopts defines which options correspond to credentials
_credopts
=
{
'ca'
,
'cert'
,
'key'
}
# neo_zconf_options returns set of zconfig options supported by NEO storage
def
neo_zconf_options
():
neo_schema
=
"""<schema>
...
...
@@ -44,8 +41,6 @@ def neo_zconf_options():
options
=
{
k
for
k
,
_
in
neo_storage_zconf
}
assert
'master_nodes'
in
options
assert
'name'
in
options
for
opt
in
_credopts
:
assert
opt
in
options
,
opt
return
options
...
...
@@ -57,46 +52,27 @@ def canonical_opt_name(name):
def
_resolve_uri
(
uri
):
scheme
,
netloc
,
path
,
query
,
frag
=
urlsplit
(
uri
)
if
scheme
not
in
(
"neo"
,
"neos"
):
raise
ValueError
(
"invalid uri: %s : expected neo:// or neos:// scheme"
%
uri
)
if
scheme
!=
"neo"
:
raise
ValueError
(
"invalid uri: %s : expected neo:// scheme"
%
uri
)
if
path
!=
""
:
raise
ValueError
(
"invalid uri: %s : non-empty path"
%
uri
)
if
frag
!=
""
:
raise
ValueError
(
"invalid uri: %s : non-empty fragment"
%
uri
)
# name is given as path
if
path
.
startswith
(
"/"
):
path
=
path
[
1
:]
name
=
path
if
name
==
''
:
raise
ValueError
(
"invalid uri: %s : cluster name not specified"
%
uri
)
# extract master list and credentials from netloc
cred
,
masterloc
=
''
,
netloc
if
'@'
in
netloc
:
cred
,
masterloc
=
netloc
.
split
(
'@'
,
1
)
# extract master list and name from netloc
name
,
masterloc
=
netloc
.
split
(
'@'
,
1
)
master_list
=
masterloc
.
split
(
','
)
neokw
=
OrderedDict
()
neokw
[
'master_nodes'
]
=
' '
.
join
(
master_list
)
neokw
[
'name'
]
=
name
# parse credentials
if
cred
:
if
scheme
!=
"neos"
:
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
# get options from query: only those that are defined by NEO schema go to
# storage - rest are returned as database options
dbkw
=
{}
neo_options
=
neo_zconf_options
()
for
k
,
v
in
OrderedDict
(
parse_qsl
(
query
)).
items
():
if
k
in
_credopts
:
raise
ValueError
(
"invalid uri: %s : option %s must be in credentials"
%
(
uri
,
k
))
elif
k
in
neo_options
:
if
k
in
neo_options
:
neokw
[
k
]
=
v
else
:
# it might be option for storage, but not in canonical form e.g.
...
...
neo/tests/client/testZODBURI.py
View file @
816ad564
#
# Copyright (C) 2017-20
20
Nexedi SA
# Copyright (C) 2017-20
19
Nexedi SA
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
...
...
@@ -20,21 +20,21 @@ from neo.client.zodburi import _resolve_uri
testv
=
[
# [] of (uri, zconf_ok, dbkw_ok)
(
"neo://
master/dbname
"
,
(
"neo://
dbname@master
"
,
"""
\
master_nodes
\
t
master
name
\
t
dbname
"""
,
{}),
(
"neo://
master1:port1,master2:port2,master3:port3/db2
"
,
(
"neo://
db2@master1:port1,master2:port2,master3:port3
"
,
"""
\
master_nodes
\
t
master1:port1 master2:port2 master3:port3
name
\
t
db2
"""
,
{}),
(
"neo://
master1,master2:port2/db3
?read_only=true"
,
(
"neo://
db3@master1,master2:port2
?read_only=true"
,
"""
\
master_nodes
\
t
master1 master2:port2
name
\
t
db3
...
...
@@ -42,19 +42,19 @@ testv = [
"""
,
{}),
(
"neo
s://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"
,
(
"neo
://db4@[2001:67c:1254:2a::1]:1234,master2:port2
?read_only=false"
"&compress=true&logfile=xxx&alpha=111&dynamic_master_list=zzz
&ca=qqq
"
"&
cert=rrr&key=sss&
beta=222"
,
"""
\
master_nodes
\
t
[2001:67c:1254:2a::1]:1234 master2:port2
name
\
t
db4
ca
\
t
qqq
cert
\
t
rrr
key
\
t
sss
read-only
\
t
false
compress
\
t
true
logfile
\
t
xxx
dynamic_master_list
\
t
zzz
ca
\
t
qqq
cert
\
t
rrr
key
\
t
sss
"""
,
{
"alpha"
:
"111"
,
"beta"
:
"222"
}),
]
...
...
@@ -64,20 +64,14 @@ testv = [
class
ZODBURITests
(
unittest
.
TestCase
):
def
test_zodburi
(
self
):
# invalid schema / fragment
self
.
assertRaises
(
ValueError
,
_resolve_uri
,
"http://master/db"
)
self
.
assertRaises
(
ValueError
,
_resolve_uri
,
"neo://master/db#frag"
)
# invalid schema / path / fragment
self
.
assertRaises
(
ValueError
,
_resolve_uri
,
"http://db@master"
)
self
.
assertRaises
(
ValueError
,
_resolve_uri
,
"neo://db@master/path"
)
self
.
assertRaises
(
ValueError
,
_resolve_uri
,
"neo://db@master#frag"
)
#
master/db
not fully specified
#
db @ master
not fully specified
self
.
assertRaises
(
ValueError
,
_resolve_uri
,
"neo://master"
)
# option that corresponds to credential provided in query
self
.
assertRaises
(
ValueError
,
_resolve_uri
,
"neos://master/db?ca=123"
)
# credentials with neo:// instead of neos://
self
.
assertRaises
(
ValueError
,
_resolve_uri
,
"neo://key:zzz@master/db"
)
# verify zodburi resolver produces expected zconfig
for
uri
,
zconf_ok
,
dbkw_ok
in
testv
:
zconf_ok
=
"%import neo.client
\
n
<NEOStorage>
\
n
"
+
zconf_ok
+
\
...
...
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