Skip to content
Snippets Groups Projects
Unverified Commit 6f644e0c authored by Martin Weise's avatar Martin Weise
Browse files

Added Python stubs, added rest template

parent af35f0ba
Branches
Tags
2 merge requests!163Relase 1.3.0,!155Added readme to authentication service and added eureka service
import requests
auth = requests.post("http://localhost/api/auth/realms/dbrepo/protocol/openid-connect/token", data={
"username": "foo",
"password": "bar",
"grant_type": "password",
"client_id": "dbrepo-client",
"scope": "openid",
"client_secret": "MUwRc7yfXSJwX8AdRMWaQC3Nep1VjwgG"
})
print(auth.json()["access_token"])
import requests
auth = requests.post("http://localhost/api/auth/realms/dbrepo/protocol/openid-connect/token", data={
"grant_type": "refresh_token",
"client_id": "dbrepo-client",
"client_secret": "MUwRc7yfXSJwX8AdRMWaQC3Nep1VjwgG",
"refresh_token": "THE_REFRESH_TOKEN"
})
print(auth.json()["access_token"])
#!/bin/env python3
import os
import pika
from dotenv import load_dotenv
load_dotenv()
if __name__ == "__main__":
token = os.getenv("TOKEN")
credentials = pika.credentials.PlainCredentials("", token)
credentials = pika.credentials.PlainCredentials("", "THE_ACCESS_TOKEN")
parameters = pika.ConnectionParameters('localhost', 5672, '/', credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue='test', durable=True)
......
import pika
credentials = pika.credentials.PlainCredentials("foo", "bar")
parameters = pika.ConnectionParameters('localhost', 5672, '/', credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue='test', durable=True)
channel.basic_publish(exchange='',
routing_key='test',
body=b'Hello World!')
print(" [x] Sent 'Hello World!'")
connection.close()
pika==1.3.1
python-dotenv==1.0.0
requests==2.28.2
\ No newline at end of file
......@@ -20,6 +20,10 @@ spring:
time_zone: UTC
application:
name: metadata-service
rabbitmq:
host: localhost
username: fda
password: fda
cloud:
loadbalancer.ribbon.enabled: false
management.endpoints.web.exposure.include: health,info,prometheus
......
package at.tuwien.config;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.support.BasicAuthenticationInterceptor;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriBuilderFactory;
@Getter
@Configuration
public class GatewayConfig {
@Value("${fda.gateway.endpoint}")
private String gatewayEndpoint;
@Value("${spring.rabbitmq.username}")
private String brokerUsername;
@Value("${spring.rabbitmq.password}")
private String brokerPassword;
@Bean("brokerRestTemplate")
public RestTemplate brokerRestTemplate() {
final RestTemplate restTemplate = new RestTemplate();
restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(gatewayEndpoint));
restTemplate.getInterceptors()
.add(new BasicAuthenticationInterceptor(brokerUsername, brokerPassword));
return restTemplate;
}
}
......@@ -28,7 +28,8 @@ HEALTHCHECK --interval=10s --timeout=5s --retries=12 CMD service_ready
EXPOSE $PORT_APP
COPY ./us-yml/ ./us-yml/
COPY ./us-yml ./us-yml
COPY ./ontologies ./ontologies
COPY ./*.py ./
ENTRYPOINT [ "python", "-u", "./pywsgi.py" ]
......@@ -8,15 +8,13 @@ Created on Thu Dec 2 23:31:39 2021
import rdflib
import requests as rq
rdf = rq.get('http://www.ontology-of-units-of-measure.org/resource/om-2', headers={'Accept': 'application/rdf+xml'})
rdf.raise_for_status()
g = rdflib.Graph()
g.namespace_manager.bind('om', 'http://www.ontology-of-units-of-measure.org/resource/om-2/')
g.parse(data=rdf.text, format='xml')
# ontology of measure
u = rdflib.Graph()
u.namespace_manager.bind('om', 'http://www.ontology-of-units-of-measure.org/resource/om-2/')
u.namespace_manager.bind('schema', 'http://schema.org/')
u.parse('ontologies/om-2.rdf', format='xml')
om = rdflib.Namespace('http://www.ontology-of-units-of-measure.org/resource/om-2/')
rdf_schema = rdflib.Namespace('http://www.w3.org/2000/01/rdf-schema#')
# rdf = rq.get('http://qudt.org/2.1/vocab/unit', headers={'Accept': 'text/turtle'})
......@@ -33,9 +31,9 @@ def validator(value):
# input str
tmp = str(om) + value
t_uri = rdflib.term.URIRef(tmp)
if next(g.triples((t_uri, None, om.Unit)), _exhausted) is _exhausted and next(
g.triples((t_uri, None, om.PrefixedUnit)), _exhausted) is _exhausted and next(
g.triples((t_uri, None, None)), _exhausted) is _exhausted:
if next(u.triples((t_uri, None, om.Unit)), _exhausted) is _exhausted and next(
u.triples((t_uri, None, om.PrefixedUnit)), _exhausted) is _exhausted and next(
u.triples((t_uri, None, None)), _exhausted) is _exhausted:
return False
else:
return True
......
......@@ -28,6 +28,7 @@ COPY ./api ./api
COPY ./components ./components
COPY ./lang ./lang
COPY ./layouts ./layouts
COPY ./locales ./locales
COPY ./pages ./pages
COPY ./plugins ./plugins
COPY ./server-middleware ./server-middleware
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment