Skip to content

Commit eb5813a

Browse files
Merge pull request #3 from CSWorldTelugu/dev
Reorganize codebase for Python package, update docs, add tests
2 parents bd85aa4 + 3c72952 commit eb5813a

File tree

19 files changed

+944
-91
lines changed

19 files changed

+944
-91
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ dmypy.json
152152
# Cython debug symbols
153153
cython_debug/
154154

155+
.env
156+
155157
# PyCharm
156158
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157159
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore

CONTRIBUTING.md

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
# Contributing to Python FM DAPI Weaver
22

33

4-
Thank you for your interest in contributing to **Python FM DAPI Weaver**!This guide outlines the steps to get started and the standards we follow.
5-
4+
Thank you for your interest in contributing to **Python FM DAPI Weaver**! This guide outlines the steps to get started and the standards we follow.
65

76

87

98
## Ways to Contribute?
109

1110
You can help improve the project in the following ways:
1211

13-
14-
15-
- Identifying and reporting bugs
16-
- Proposing new features or enhancements
17-
- Improving or expanding documentation
18-
- Fixing existing issues
19-
- Developing new features or API endpoints
12+
- **Bug Reports**: Identify and report any bugs you find.
13+
- **Feature Proposals**: Suggest new features or improvements to existing ones.
14+
- **Documentation**: Improve or expand documentation to make it easier for users and developers.
15+
- **Fixing Issues**: Address open issues and contribute fixes.
16+
2017

2118

2219

@@ -30,37 +27,93 @@ You can help improve the project in the following ways:
3027

3128

3229

33-
## How to Contribute:
30+
## A Quick Start Guide:
31+
3432

33+
### 1. Fork the Repository
3534

3635

37-
1. **Fork the Project:** Create a personal copy of the repository by forking it on GitHub.
3836

37+
Click the **Fork** button at the top-right corner of this repository to create your own copy.
3938

4039

41-
2. **Clone Your Fork:** Pull the repository onto your local computer using Git.
4240

41+
### 2. Clone Your Fork
4342

4443

45-
3. **Create a Feature Branch:** Work on a new branch dedicated to the feature or fix you're adding.
4644

45+
Clone the repository to your local machine:
4746

4847

49-
4. **Make Necessary Changes:** Implement your changes and thoroughly test to ensure everything works.
5048

49+
```
50+
git clone https://github.com/your-username/python-fm-dapi-weaver.git
51+
cd python-fm-dapi-weaver
5152
53+
```
5254

53-
5. **Commit the Changes:** Commit your work with a concise, clear message about what was modified.
55+
### 3. Install Dependencies
5456

5557

5658

57-
6. **Push to Your Fork on GitHub:** Push the branch to your GitHub account.
59+
It's recommended to use a virtual environment:
5860

5961

6062

61-
7. **Open a Pull Request:** Submit your pull request to the project repository for review and merging.
63+
```
64+
python -m venv venv
65+
source venv/bin/activate  # On Windows use `venv\Scripts\activate`
66+
pip install -r requirements.txt
6267
6368
69+
```
70+
71+
### 4. Run the Server
72+
73+
74+
you can run the server using below command:
75+
76+
77+
78+
```
79+
python -m python_fm_dapi_weaver.main
80+
81+
```
82+
83+
### 5. Test the API
84+
85+
86+
87+
Once the server is running, you can test the API using tools like [Postman](https://www.postman.com/). The server should be accessible at `http://127.0.0.1:8000`.
88+
89+
90+
### 6. Make Changes
91+
92+
Feel free to make changes or add new features! You can modify the code in the `python_fm_dapi_weaver` directory and test locally to ensure your changes work as expected.
93+
94+
95+
For example, to add a new feature, you might:
96+
- Create a new module or file in the `python_fm_dapi_weaver` folder.
97+
- Modify existing files if you're improving or fixing existing functionality.
98+
- Ensure your changes align with the overall structure and coding style of the project.
99+
100+
101+
102+
### 7. **Commit the Changes:**
103+
Commit your work with a concise, clear message about what was modified.
104+
105+
106+
107+
### 8. **Push to Your Fork on GitHub:**
108+
Push the branch/changes to your GitHub Repository.
109+
110+
111+
112+
### 9. **Submitting changes:**
113+
114+
Please open a Pull Request with a list of what you've done.Make sure, if possible, keep all of your commits are atomic (one feature per commit).
115+
116+
64117
## Code of Conduct and Licensing
65118

66119
By participating in this project, you agree to abide by our [Code of Conduct](CODE_OF_CONDUCT.md) and are licensed under the project's [License](./LICENSE).
@@ -79,5 +132,5 @@ If you have any questions, feel free to reach out. We encourage everyone to cont
79132

80133

81134

82-
Happy coding!
135+
Happy coding!!
83136

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ requests = "*"
1111
[dev-packages]
1212

1313
[requires]
14-
python_version = "3.13"
14+
python_version = "3.10"

Pipfile.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

python_fm_dapi_weaver/__init__.py

Whitespace-only changes.

python_fm_dapi_weaver/controllers/__init__.py

Whitespace-only changes.
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22
from starlette.responses import JSONResponse
33
import requests
44

5+
# Validates the 'Authorization' header and extracts the Basic Auth token
56
async def validate_token(req: Request):
6-
print("reaching here---validateToken")
77
auth_header = req.headers.get("Authorization")
88

9+
910
if not auth_header:
1011
raise HTTPException(status_code=401, detail="Authorization header is missing")
1112

1213
auth_header_parts = auth_header.split(" ")
1314

1415
if len(auth_header_parts) != 2 or auth_header_parts[0].lower() != "basic":
1516
raise HTTPException(status_code=400, detail="Invalid Authorization header format")
17+
# Save token to request.state for future use
18+
req.state.basicAuthToken = auth_header_parts[1]
19+
1620

17-
req.basicAuthToken = auth_header_parts[1]
18-
19-
21+
# Validates the session
2022
async def validate_session(req: Request):
21-
basic_auth_token = req.basicAuthToken
23+
basic_auth_token = req.state.basicAuthToken
2224
body= req.state.body
2325
session = body.get("session", {})
2426
token = session.get("token")
@@ -30,12 +32,13 @@ async def validate_session(req: Request):
3032

3133
if not session or not token:
3234
try:
35+
# If session or token is missing, attempt to login and validate session
3336
fm_session_token = await fm_login(fm_server, database, basic_auth_token)
3437

3538
if fm_session_token:
3639
is_session_valid = await fm_validate_session(fm_server, fm_session_token)
3740
if is_session_valid:
38-
req.state.body["fmSessionToken"] = fm_session_token
41+
req.state.fmSessionToken = fm_session_token
3942

4043
else:
4144
return JSONResponse(status_code=401, content={"error": "Session token validation failed"})
@@ -45,15 +48,15 @@ async def validate_session(req: Request):
4548
try:
4649
is_session_valid = await fm_validate_session(fm_server, token)
4750
if is_session_valid:
48-
req.state.body["fmSessionToken"] = token
51+
req.state.fmSessionToken = token
4952
else:
5053
if token:
5154
try:
5255
fm_session_token = await fm_login(fm_server, database, basic_auth_token)
5356
if fm_session_token:
5457
is_session_valid = await fm_validate_session(fm_server, fm_session_token)
5558
if is_session_valid:
56-
req.state.body["fmSessionToken"] = fm_session_token
59+
req.state.fmSessionToken = fm_session_token
5760

5861
else:
5962
return JSONResponse(status_code=401, content={"error": "Re-validation of session token failed"})
@@ -69,7 +72,7 @@ async def validate_session(req: Request):
6972
async def signin(req: Request):
7073
try:
7174
await validate_token(req)
72-
basic_auth_token = req.basicAuthToken
75+
basic_auth_token = req.state.basicAuthToken
7376
body =req.state.body
7477
fm_server = body.get("fmServer")
7578
method_body = body.get("methodBody", {})
@@ -91,7 +94,6 @@ async def signin(req: Request):
9194
raise HTTPException(status_code=500, detail=f"Signin failed: {str(e)}")
9295

9396
async def fm_login(fm_server, database, basic_auth_token):
94-
print("reaching here---fmlogin")
9597
url = f"https://{fm_server}/fmi/data/vLatest/databases/{database}/sessions"
9698

9799
headers = {
@@ -113,8 +115,9 @@ async def fm_login(fm_server, database, basic_auth_token):
113115
response_json["error"] = error.response.json()
114116
raise response_json
115117

118+
119+
# Validates session token against the FileMaker server
116120
async def fm_validate_session(fm_server, session_token):
117-
print("reaching here---fmValidateSession")
118121
url = f"https://{fm_server}/fmi/data/vLatest/validateSession"
119122

120123
headers = {
@@ -136,8 +139,7 @@ async def signout(req: Request):
136139
method_body = body.get("methodBody", {})
137140
database = method_body.get("database")
138141
fm_server = body.get("fmServer")
139-
token = body.get("fmSessionToken")
140-
142+
token = req.state.fmSessionToken
141143
if not (fm_server and database):
142144
raise HTTPException(status_code=400, detail="Missing fmServer, database.")
143145

controllers/index.py renamed to python_fm_dapi_weaver/controllers/index.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
upload_container
1010
)
1111

12+
# List of method names that do not require token/session validation.
1213
controllers_to_skip_validation = ["signin"]
14+
15+
16+
# Mapping of method names to their corresponding handler functions
1317
METHOD_HANDLERS = {
1418
"createRecord": create_record,
1519
"getAllRecords": get_all_records,

0 commit comments

Comments
 (0)