-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-129798 / 24.10 / New plugin that checks for the vendor sentinel f…
…ile (#13970) * Create `vendor.py` * removed potential TOCTOU vulnerability * add `private` option to `api_method` decorator * shift `vendor.py` to use new api style * remove proposed common models for version release safety * deserialize the file * catch `JSONDecodeError`
- Loading branch information
1 parent
7687364
commit 5215f5a
Showing
4 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from middlewared.api.base import BaseModel | ||
|
||
|
||
class VendorNameArgs(BaseModel): | ||
pass | ||
|
||
|
||
class VendorNameResult(BaseModel): | ||
result: str | None | ||
|
||
|
||
class UnvendorArgs(BaseModel): | ||
pass | ||
|
||
|
||
class UnvendorResult(BaseModel): | ||
result: None |
28 changes: 28 additions & 0 deletions
28
src/middlewared/middlewared/plugins/system/vendor/vendor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import json | ||
import os | ||
|
||
from middlewared.api import api_method | ||
from middlewared.api.current import VendorNameArgs, VendorNameResult, UnvendorArgs, UnvendorResult | ||
from middlewared.service import Service | ||
|
||
|
||
SENTINEL_FILE_PATH = '/data/.vendor' | ||
|
||
|
||
class VendorService(Service): | ||
|
||
@api_method(VendorNameArgs, VendorNameResult, private=True) | ||
def name(self) -> str | None: | ||
try: | ||
with open(SENTINEL_FILE_PATH, 'r') as file: | ||
if contents := file.read(): | ||
return json.loads(contents).get('name') | ||
except (FileNotFoundError, json.JSONDecodeError): | ||
return None | ||
|
||
@api_method(UnvendorArgs, UnvendorResult, private=True) | ||
def unvendor(self): | ||
try: | ||
os.remove(SENTINEL_FILE_PATH) | ||
except FileNotFoundError: | ||
return None |