Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
clients
python
DuniterPy
Commits
e0733485
Commit
e0733485
authored
6 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
issue
#56
WIP - Support Elasticsearch/Duniter4j nodes ES_CORE_API with example
parent
e045755a
No related branches found
No related tags found
No related merge requests found
Pipeline
#2683
passed
6 years ago
Stage: github-sync
Stage: build
Stage: test
Stage: release
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
duniterpy/api/client.py
+3
-0
3 additions, 0 deletions
duniterpy/api/client.py
duniterpy/api/endpoint.py
+49
-4
49 additions, 4 deletions
duniterpy/api/endpoint.py
examples/request_data_elasticsearch.py
+42
-0
42 additions, 0 deletions
examples/request_data_elasticsearch.py
with
94 additions
and
4 deletions
duniterpy/api/client.py
+
3
−
0
View file @
e0733485
...
@@ -203,6 +203,9 @@ class Client:
...
@@ -203,6 +203,9 @@ class Client:
else
:
else
:
self
.
endpoint
=
_endpoint
self
.
endpoint
=
_endpoint
if
isinstance
(
self
.
endpoint
,
endpoint
.
UnknownEndpoint
):
raise
NotImplementedError
(
"
{0} endpoint in not supported
"
.
format
(
self
.
endpoint
.
api
))
# if no user session...
# if no user session...
if
session
is
None
:
if
session
is
None
:
# open a session
# open a session
...
...
This diff is collapsed.
Click to expand it.
duniterpy/api/endpoint.py
+
49
−
4
View file @
e0733485
...
@@ -319,11 +319,56 @@ class WS2PEndpoint(Endpoint):
...
@@ -319,11 +319,56 @@ class WS2PEndpoint(Endpoint):
return
hash
((
self
.
ws2pid
,
self
.
server
,
self
.
port
,
self
.
path
))
return
hash
((
self
.
ws2pid
,
self
.
server
,
self
.
port
,
self
.
path
))
class
ESCoreEndpoint
(
Endpoint
):
API
=
"
ES_CORE_API
"
re_inline
=
re
.
compile
(
'
^ES_CORE_API ((?:{host_regex})|(?:{ipv4_regex})) ([0-9]+)$
'
.
format
(
host_regex
=
HOST_REGEX
,
ipv4_regex
=
IPV4_REGEX
))
def
__init__
(
self
,
server
,
port
):
self
.
server
=
server
self
.
port
=
port
@classmethod
def
from_inline
(
cls
,
inline
):
m
=
ESCoreEndpoint
.
re_inline
.
match
(
inline
)
if
m
is
None
:
raise
MalformedDocumentError
(
ESCoreEndpoint
.
API
)
server
=
m
.
group
(
1
)
port
=
int
(
m
.
group
(
2
))
return
cls
(
server
,
port
)
def
inline
(
self
):
inlined
=
[
str
(
info
)
for
info
in
(
self
.
server
,
self
.
port
)
if
info
]
return
ESCoreEndpoint
.
API
+
"
"
+
"
"
.
join
(
inlined
)
def
conn_handler
(
self
,
session
:
aiohttp
.
ClientSession
,
proxy
:
str
=
None
)
->
ConnectionHandler
:
"""
Return connection handler instance for the endpoint
:param aiohttp.ClientSession session: AIOHTTP client session instance
:param str proxy: Proxy url
:rtype: ConnectionHandler
"""
return
ConnectionHandler
(
"
https
"
,
"
wss
"
,
self
.
server
,
self
.
port
,
""
,
proxy
,
session
)
def
__str__
(
self
):
return
self
.
inline
()
def
__eq__
(
self
,
other
):
if
isinstance
(
other
,
ESCoreEndpoint
):
return
self
.
server
==
other
.
server
and
self
.
port
==
other
.
port
else
:
return
False
def
__hash__
(
self
):
return
hash
((
self
.
server
,
self
.
port
))
class
ESUserEndpoint
(
Endpoint
):
class
ESUserEndpoint
(
Endpoint
):
API
=
"
ES_USER_API
"
API
=
"
ES_USER_API
"
re_inline
=
re
.
compile
(
re_inline
=
re
.
compile
(
'
^ES_USER_API ((?:{host_regex})|(?:{ipv4_regex})) ([0-9]+)$
'
.
format
(
ws2pid_regex
=
WS2PID_REGEX
,
'
^ES_USER_API ((?:{host_regex})|(?:{ipv4_regex})) ([0-9]+)$
'
.
format
(
host_regex
=
HOST_REGEX
,
host_regex
=
HOST_REGEX
,
ipv4_regex
=
IPV4_REGEX
))
ipv4_regex
=
IPV4_REGEX
))
def
__init__
(
self
,
server
,
port
):
def
__init__
(
self
,
server
,
port
):
...
@@ -369,8 +414,7 @@ class ESUserEndpoint(Endpoint):
...
@@ -369,8 +414,7 @@ class ESUserEndpoint(Endpoint):
class
ESSubscribtionEndpoint
(
Endpoint
):
class
ESSubscribtionEndpoint
(
Endpoint
):
API
=
"
ES_SUBSCRIPTION_API
"
API
=
"
ES_SUBSCRIPTION_API
"
re_inline
=
re
.
compile
(
re_inline
=
re
.
compile
(
'
^ES_SUBSCRIPTION_API ((?:{host_regex})|(?:{ipv4_regex})) ([0-9]+)$
'
.
format
(
ws2pid_regex
=
WS2PID_REGEX
,
'
^ES_SUBSCRIPTION_API ((?:{host_regex})|(?:{ipv4_regex})) ([0-9]+)$
'
.
format
(
host_regex
=
HOST_REGEX
,
host_regex
=
HOST_REGEX
,
ipv4_regex
=
IPV4_REGEX
))
ipv4_regex
=
IPV4_REGEX
))
def
__init__
(
self
,
server
,
port
):
def
__init__
(
self
,
server
,
port
):
...
@@ -417,6 +461,7 @@ MANAGED_API = {
...
@@ -417,6 +461,7 @@ MANAGED_API = {
BMAEndpoint
.
API
:
BMAEndpoint
,
BMAEndpoint
.
API
:
BMAEndpoint
,
SecuredBMAEndpoint
.
API
:
SecuredBMAEndpoint
,
SecuredBMAEndpoint
.
API
:
SecuredBMAEndpoint
,
WS2PEndpoint
.
API
:
WS2PEndpoint
,
WS2PEndpoint
.
API
:
WS2PEndpoint
,
ESCoreEndpoint
.
API
:
ESCoreEndpoint
,
ESUserEndpoint
.
API
:
ESUserEndpoint
,
ESUserEndpoint
.
API
:
ESUserEndpoint
,
ESSubscribtionEndpoint
.
API
:
ESSubscribtionEndpoint
ESSubscribtionEndpoint
.
API
:
ESSubscribtionEndpoint
}
}
...
...
This diff is collapsed.
Click to expand it.
examples/request_data_elasticsearch.py
0 → 100644
+
42
−
0
View file @
e0733485
import
asyncio
from
duniterpy.api.client
import
Client
# Duniter4j ES API documentation: https://git.duniter.org/clients/java/duniter4j/blob/master/src/site/markdown/ES_API.md
# Duniter4j project: https://git.duniter.org/clients/java/duniter4j/
# CONFIG #######################################
# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT]
# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT]
# Here we use the secure BASIC_MERKLED_API (BMAS)
ES_CORE_ENDPOINT
=
"
ES_CORE_API g1-test.data.duniter.fr 443
"
################################################
async
def
main
():
"""
Main code (synchronous requests)
"""
# Create Client from endpoint string in Duniter format
client
=
Client
(
ES_CORE_ENDPOINT
)
# Get the current node (direct REST GET request)
print
(
"
\n
GET g1-test/block/current/_source:
"
)
response
=
await
client
.
get
(
'
g1-test/block/current/_source
'
)
print
(
response
)
# Get the node number 2 with only selected fields (direct REST GET request)
print
(
"
\n
GET g1-test/block/2/_source:
"
)
response
=
await
client
.
get
(
'
g1-test/block/2/_source
'
,
{
'
_source
'
:
'
number,hash,dividend,membersCount
'
})
print
(
response
)
# Close client aiohttp session
await
client
.
close
()
# Latest duniter-python-api is asynchronous and you have to use asyncio, an asyncio loop and a "as" on the data.
# ( https://docs.python.org/3/library/asyncio.html )
asyncio
.
get_event_loop
().
run_until_complete
(
main
())
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