Skip to content

Commit 54493b2

Browse files
authored
Merge pull request #120 from OpenSemanticLab/login-mechanism
Rework of login mechanism to combat session timeout and stale session cookies Result of review: All comments resolved Unchanged: dotenv.load_dotenv() in calling script file because: Placing the load_dotenv() function call in WtSite would not produce the same behavior: load_dotenv() with no path does not strictly mean "use current working directory". It calls find_dotenv() internally, which usually searches from the caller file location and then walks up parent directories. If the call is inside an imported module, the lookup can start from that module’s directory, so it may load a different .env than the one in the process working directory. Note to users: For deterministic behavior, pass an explicit path to load_dotenv(...).
2 parents 473db3b + 48738fb commit 54493b2

20 files changed

Lines changed: 2028 additions & 161 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,6 @@ src/osw/model/*.json
6363
playground
6464

6565
.env
66+
67+
# Automatically added by osw.auth.CredentialManager.save_credentials_to_file:
68+
*/osw_files/*

examples/.env_example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
OSW_DOMAIN=wiki-dev.open-semantic-lab.org
2+
OSW_CRED_FILEPATH=/path/to/credentials/file
3+
OSW_DOWNLOAD_DIR=/path/to/download/directory

examples/controller_logic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing_extensions import override
44

5-
from osw.controller.entity import Entity, Hardware
5+
from osw.controller.entity import Entity
66
from osw.express import OswExpress
77

88
# Create/update the password file under examples/accounts.pwd.yaml
@@ -18,7 +18,7 @@
1818
osw_obj.fetch_schema(
1919
fetchSchemaParam=OswExpress.FetchSchemaParam(schema_title="Category:Hardware")
2020
)
21-
21+
from osw.model.entity import Hardware # noqa: E402
2222

2323
title = "Item:OSW7d7193567ea14e4e89b74de88983b718"
2424
# title = "Item:OSWe02213b6c4664d04834355dc8eb08b99"

examples/create_entity.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import osw.model.entity as model
44

55
my_entity = model.Item(
6-
label=[model.Label(text="MyItem")], statements=[model.Statement(predicate="IsA")]
6+
label=[model.Label(text="MyItem")],
7+
statements=[model.DataStatement(property="IsA", value="Category:Item")],
78
)
89
pprint(my_entity.dict())
910
print(my_entity.json())

examples/device_inventory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
model, "Corporation"
2727
): # only load if not already loaded. note: does not detect updated schemas yet
2828
DEPENDENCIES = {
29-
"MetaDeviceCategory": "Category:OSWd845b96813a344458f140e48c4d063fd",
29+
"DeviceType": "Category:OSWd845b96813a344458f140e48c4d063fd",
3030
"Device(SubclassWithMetaModel)": "Category:OSW5bf1542d9cf847db83cbc73d579ba9d6",
3131
"Corporation": "Category:OSW5f4a3751d23e482d80fb0b72dcd6bc31", #
3232
}
@@ -47,7 +47,7 @@
4747
)
4848

4949
# Create a new device type with the new manufacturer as manufacturer
50-
new_category = model.MetaDeviceCategory( # here used as a device type
50+
new_category = model.DeviceType( # here used as a device type
5151
uuid=uuid.uuid5(
5252
uuid_namespace, "MyNewDeviceCategory"
5353
), # use a stable id from the source dataset / file
@@ -70,7 +70,7 @@
7070
namespace="Category",
7171
# meta_category_title= (
7272
# "Category:OSWd845b96813a344458f140e48c4d063fd")
73-
# usage of MetaDeviceCategory not yet supported
73+
# usage of DeviceType not yet supported
7474
)
7575
)
7676

examples/generate_rdf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# load dependencies
2020
DEPENDENCIES = {
2121
"Tool": "Category:OSWe427aafafbac4262955b9f690a83405d",
22+
"Device": "Category:OSWf0fe562f422d49c6877490b3dfee2f3f",
2223
}
2324
osw_obj.install_dependencies(DEPENDENCIES, mode="append", policy="if-missing")
2425

examples/get_page_content.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
go to special pages -> Bot passwords ; follow the instructions)
55
"""
66

7+
import dotenv
8+
79
from osw.express import OswExpress
810
from osw.params import GetPageParam
911

12+
dotenv.load_dotenv()
13+
1014
osw = OswExpress(domain="demo.open-semantic-lab.org")
1115

1216
# the page title of the page to downlaod

examples/inter_osw_copy_page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
from pathlib import Path
55

6+
from opensemantic.v1 import OswBaseModel
67
from typing_extensions import List, Optional, Union
78

89
from osw.auth import CredentialManager
910
from osw.core import OSW
10-
from osw.model.static import OswBaseModel
1111
from osw.utils import util
1212
from osw.wtsite import SLOTS, WtPage, WtSite
1313

examples/offline_content_package.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import os
22
from pathlib import Path
33

4+
import dotenv
5+
46
from osw import wiki_tools
57
from osw.auth import CredentialManager
68
from osw.core import OSW
79
from osw.model.page_package import PagePackage, PagePackageBundle, PagePackageConfig
810
from osw.params import CreatePagePackageParam, PageDumpConfig
911
from osw.wtsite import WtSite
1012

13+
dotenv.load_dotenv()
14+
1115
# Create/update the password file under examples/accounts.pwd.yaml
1216
pwd_file_path = os.path.join(
1317
os.path.dirname(os.path.abspath(__file__)), "accounts.pwd.yaml"

0 commit comments

Comments
 (0)