Skip to content

Commit

Permalink
env vars for admin username, fix for decoding string
Browse files Browse the repository at this point in the history
  • Loading branch information
jarno-knaw committed Sep 17, 2024
1 parent 8d7f0ff commit 048f39d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v2.15-1.2.1]

### Added
- Environment vars for sparql endpoint and db admin username.

### Fixed
- String decode error for 'file' type vocabularies.

## [v2.15-1.2.0]

### Added
Expand All @@ -32,3 +40,4 @@ Initial version
[v2.15-1.0.0]: https://github.com/knaw-huc/sd-skosmos/releases/tag/v2.15-1.0-RC4
[v2.15-1.1.0]: https://github.com/knaw-huc/sd-skosmos/releases/tag/v2.15-1.1.0
[v2.15-1.2.0]: https://github.com/knaw-huc/sd-skosmos/releases/tag/v2.15-1.2.0
[v2.15-1.2.1]: https://github.com/knaw-huc/sd-skosmos/releases/tag/v2.15-1.2.1
4 changes: 2 additions & 2 deletions config-docker-compose.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
# SPARQL endpoint
# a local Fuseki server is usually on localhost:3030
# skosmos:sparqlEndpoint <http://host.docker.internal:7200/repositories/test-skosmos> ;
skosmos:sparqlEndpoint <http://host.docker.internal:7200/repositories/skosmos> ;
# skosmos:sparqlEndpoint <${SPARQL_ENDPOINT}> ;
# skosmos:sparqlEndpoint <http://host.docker.internal:7200/repositories/skosmos> ;
skosmos:sparqlEndpoint <${SPARQL_ENDPOINT}> ;
# use the dev.finto.fi endpoint where the example vocabularies reside
# skosmos:sparqlEndpoint <http://api.dev.finto.fi/sparql> ;
# sparql-query extension, or "Generic" for plain SPARQL 1.1
Expand Down
9 changes: 5 additions & 4 deletions src/graphdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from SPARQLWrapper import SPARQLWrapper, JSON, POST, DIGEST

admin_password = os.environ.get("ADMIN_PASSWORD", '')
admin_username = os.environ.get("ADMIN_USERNAME", 'admin')
endpoint = os.environ.get("SPARQL_ENDPOINT", '')


Expand All @@ -29,7 +30,7 @@ def setup_graphdb() -> None:
f"{endpoint}",
headers=headers,
data=fp,
auth=('admin', admin_password),
auth=(admin_username, admin_password),
timeout=60
)
print(f"CREATED GRAPHDB[{endpoint}] DB[skosmos.tdb]")
Expand Down Expand Up @@ -72,7 +73,7 @@ def set_timestamp(graph_name: str, timestamp: int) -> None:
"""
sparql = SPARQLWrapper(f"{endpoint}/statements")
sparql.setHTTPAuth(DIGEST)
sparql.setCredentials("admin", admin_password)
sparql.setCredentials(admin_username, admin_password)
sparql.setMethod(POST)
q = """INSERT DATA {{
<{graph}> <http://purl.org/dc/terms/modified> {timestamp} .
Expand All @@ -92,7 +93,7 @@ def update_timestamp(graph_name: str, timestamp: int) -> None:
"""
sparql = SPARQLWrapper(f"{endpoint}/statements")
sparql.setHTTPAuth(DIGEST)
sparql.setCredentials("admin", admin_password)
sparql.setCredentials(admin_username, admin_password)
sparql.setMethod(POST)
q = """
DELETE {{
Expand Down Expand Up @@ -139,7 +140,7 @@ def add_vocabulary(graph: TextIO, graph_name: str, extension: str) -> None:
f"{endpoint}/statements",
data=graph.read(),
headers=headers,
auth=('admin', admin_password),
auth=(admin_username, admin_password),
params={'context': f"<{graph_name}>"},
timeout=60,
)
Expand Down
2 changes: 1 addition & 1 deletion src/vocabularies.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_graph(fp: IO) -> str:
for line in fp:
try:
line = line.decode('utf-8')
except UnicodeDecodeError:
except (UnicodeDecodeError, AttributeError):
# Already decoded
pass
if re.search("sparqlGraph", line):
Expand Down

0 comments on commit 048f39d

Please sign in to comment.