Skip to content

Commit 48a08ef

Browse files
authored
Merge pull request #88 from clowder-framework/add-file-deletion
add file deletion endpoints
2 parents 946e56b + ca463ea commit 48a08ef

File tree

5 files changed

+56
-3
lines changed

5 files changed

+56
-3
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](https://semver.org/).
77

8+
- ## 3.0.5 - 2023-10-09
9+
10+
### Added
11+
12+
- Support for deletion of individual files.
13+
814
## 3.0.4 - 2023-09-27
915

1016
### Fixed
1117

1218
- Fixed host bug on v1 file thumbnail endpoint.
13-
-
14-
- ## 3.0.3 - 2023-08-29
19+
20+
## 3.0.3 - 2023-08-29
1521

1622
### Added
1723

pyclowder/api/v1/files.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,22 @@ def download_metadata(connector, client, fileid, extractor=None):
129129
return result
130130

131131

132+
def delete(connector, client, fileid):
133+
"""Delete file from Clowder.
134+
135+
Keyword arguments:
136+
connector -- connector information, used to get missing parameters and send status updates
137+
client -- ClowderClient containing authentication credentials
138+
fileid -- the dataset to delete
139+
"""
140+
url = "%s/api/files/%s?key=%s" % (client.host, fileid, client.key)
141+
142+
result = requests.delete(url, verify=connector.ssl_verify if connector else True)
143+
result.raise_for_status()
144+
145+
return json.loads(result.text)
146+
147+
132148
def submit_extraction(connector, client, fileid, extractorname):
133149
"""Submit file for extraction by given extractor.
134150

pyclowder/api/v2/files.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,22 @@ def download_metadata(connector, client, fileid, extractor=None):
132132
return result
133133

134134

135+
def delete(connector, client , fileid):
136+
"""Delete file from Clowder.
137+
138+
Keyword arguments:
139+
connector -- connector information, used to get missing parameters and send status updates
140+
client -- ClowderClient containing authentication credentials
141+
fileid -- the dataset to delete
142+
"""
143+
headers = {"X-API-KEY": client.key}
144+
url = "%s/api/v2/files/%s" % (client.host, fileid)
145+
146+
result = requests.delete(url, headers=headers, verify=connector.ssl_verify if connector else True)
147+
result.raise_for_status()
148+
149+
return json.loads(result.text)
150+
135151
def submit_extraction(connector, client, fileid, extractorname):
136152
"""Submit file for extraction by given extractor.
137153

pyclowder/files.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,21 @@ def download_metadata(connector, host, key, fileid, extractor=None):
9898
return result.json()
9999

100100

101+
def delete(connector, host, key, fileid):
102+
"""Delete file from Clowder.
103+
104+
Keyword arguments:
105+
connector -- connector information, used to get missing parameters and send status updates
106+
host -- the clowder host, including http and port, should end with a /
107+
key -- the secret key to login to clowder
108+
fileid -- the file to delete
109+
"""
110+
client = ClowderClient(host=host, key=key)
111+
result = files.delete(connector, client, fileid)
112+
result.raise_for_status()
113+
114+
return json.loads(result.text)
115+
101116
def submit_extraction(connector, host, key, fileid, extractorname):
102117
"""Submit file for extraction by given extractor.
103118

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name='pyclowder',
11-
version='3.0.4',
11+
version='3.0.5',
1212
description='Python SDK for the Clowder Data Management System',
1313
long_description=long_description,
1414

0 commit comments

Comments
 (0)