redfishLiteApi 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- redfishliteapi-1.0.0/PKG-INFO +165 -0
- redfishliteapi-1.0.0/README.md +141 -0
- redfishliteapi-1.0.0/redfishLiteApi.egg-info/PKG-INFO +165 -0
- redfishliteapi-1.0.0/redfishLiteApi.egg-info/SOURCES.txt +9 -0
- redfishliteapi-1.0.0/redfishLiteApi.egg-info/dependency_links.txt +1 -0
- redfishliteapi-1.0.0/redfishLiteApi.egg-info/entry_points.txt +2 -0
- redfishliteapi-1.0.0/redfishLiteApi.egg-info/requires.txt +1 -0
- redfishliteapi-1.0.0/redfishLiteApi.egg-info/top_level.txt +1 -0
- redfishliteapi-1.0.0/redfishLiteApi.py +114 -0
- redfishliteapi-1.0.0/setup.cfg +4 -0
- redfishliteapi-1.0.0/setup.py +31 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: redfishLiteApi
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A lightweight Redfish API command-line tool
|
|
5
|
+
Home-page: https://github.com/jeffery12240122/redfishLiteAPI
|
|
6
|
+
Author: Jeffery Lin
|
|
7
|
+
Author-email: jeffery12240122@gmail.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Requires-Python: >=3.6
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: requests>=2.25.1
|
|
15
|
+
Dynamic: author
|
|
16
|
+
Dynamic: author-email
|
|
17
|
+
Dynamic: classifier
|
|
18
|
+
Dynamic: description
|
|
19
|
+
Dynamic: description-content-type
|
|
20
|
+
Dynamic: home-page
|
|
21
|
+
Dynamic: requires-dist
|
|
22
|
+
Dynamic: requires-python
|
|
23
|
+
Dynamic: summary
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# ๐ง redfishLiteApi
|
|
27
|
+
|
|
28
|
+
A lightweight command-line tool to interact with Redfish APIs using `GET`, `POST`, and `PATCH` methods. Designed for quick testing, debugging, and field extraction.
|
|
29
|
+
|
|
30
|
+
----------
|
|
31
|
+
|
|
32
|
+
## ๐ฆ Features
|
|
33
|
+
|
|
34
|
+
- โ
Support for `GET`, `POST`, and `PATCH`
|
|
35
|
+
|
|
36
|
+
- ๐ Basic Authentication (`-U` / `-P`)
|
|
37
|
+
|
|
38
|
+
- ๐ JSON body input via file (`--json_file`)
|
|
39
|
+
|
|
40
|
+
- ๐ Recursive field value search with `--find` (supports multiple fields)
|
|
41
|
+
|
|
42
|
+
- ๐พ Save response to file (`--save`)
|
|
43
|
+
|
|
44
|
+
- ๐งพ Custom HTTP headers (`--header`)
|
|
45
|
+
|
|
46
|
+
- โฑ๏ธ 10-second request timeout to prevent hanging
|
|
47
|
+
|
|
48
|
+
- ๐งฏ Disable SSL verification warnings
|
|
49
|
+
|
|
50
|
+
- ๐ก HTTP Status display
|
|
51
|
+
|
|
52
|
+
- โ ๏ธ JSON parse error handling with fallback to raw text
|
|
53
|
+
|
|
54
|
+
- ๐ข `--version` support
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
----------
|
|
58
|
+
|
|
59
|
+
## ๐ Usage
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
`python redfishLiteApi.py --url <API_URL> --method <get|post|patch> [OPTIONS]`
|
|
63
|
+
|
|
64
|
+
### โ
Example: Basic GET request
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
`python redfishLiteApi.py --url https://<host>/redfish/v1/Systems --method get`
|
|
68
|
+
|
|
69
|
+
### ๐ Example: Authenticated GET with header and find field
|
|
70
|
+
|
|
71
|
+
`python redfishLiteApi.py --url https://<host>/redfish/v1/Systems --method get \
|
|
72
|
+
-U admin -P password \
|
|
73
|
+
--header "If-Match:W/\"etag-value\"" \
|
|
74
|
+
--find Id Name PowerState`
|
|
75
|
+
|
|
76
|
+
### ๐ Example: PATCH with body file
|
|
77
|
+
|
|
78
|
+
`python redfishLiteApi.py --url https://<host>/redfish/v1/Managers/1/EthernetInterfaces/1 \
|
|
79
|
+
--method patch -U admin -P password --json_file update.json`
|
|
80
|
+
|
|
81
|
+
### ๐พ Example: Save output to file
|
|
82
|
+
|
|
83
|
+
`python redfishLiteApi.py --url https://<host>/redfish/v1/Systems --method get --save output.json`
|
|
84
|
+
|
|
85
|
+
### ๐ Check version
|
|
86
|
+
|
|
87
|
+
`python redfishLiteApi.py --version`
|
|
88
|
+
|
|
89
|
+
----------
|
|
90
|
+
|
|
91
|
+
## ๐ง Argument Summary
|
|
92
|
+
|
|
93
|
+
Argument
|
|
94
|
+
|
|
95
|
+
Description
|
|
96
|
+
|
|
97
|
+
`--url`
|
|
98
|
+
|
|
99
|
+
Redfish API endpoint URL (required)
|
|
100
|
+
|
|
101
|
+
`--method`
|
|
102
|
+
|
|
103
|
+
HTTP method: `get`, `post`, or `patch` (required)
|
|
104
|
+
|
|
105
|
+
`-U` / `--username`
|
|
106
|
+
|
|
107
|
+
Basic auth username
|
|
108
|
+
|
|
109
|
+
`-P` / `--password`
|
|
110
|
+
|
|
111
|
+
Basic auth password
|
|
112
|
+
|
|
113
|
+
`--json_file`
|
|
114
|
+
|
|
115
|
+
Path to JSON file for POST or PATCH body
|
|
116
|
+
|
|
117
|
+
`--find`
|
|
118
|
+
|
|
119
|
+
One or more JSON field names to recursively extract (GET only)
|
|
120
|
+
|
|
121
|
+
`--save`
|
|
122
|
+
|
|
123
|
+
Save the response body to a file
|
|
124
|
+
|
|
125
|
+
`--header`
|
|
126
|
+
|
|
127
|
+
Custom headers in `Key:Value` format (can be repeated)
|
|
128
|
+
|
|
129
|
+
`--version`
|
|
130
|
+
|
|
131
|
+
Show current version and exit
|
|
132
|
+
|
|
133
|
+
----------
|
|
134
|
+
|
|
135
|
+
## โ ๏ธ Notes
|
|
136
|
+
|
|
137
|
+
- SSL certificate verification is disabled (`verify=False`).
|
|
138
|
+
|
|
139
|
+
- Timeout is hardcoded to 10 seconds.
|
|
140
|
+
|
|
141
|
+
- HTTP error handling is basic โ be sure to inspect the response if you encounter unexpected results.
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
----------
|
|
145
|
+
|
|
146
|
+
## ๐ Dependencies
|
|
147
|
+
|
|
148
|
+
- Python 3.x
|
|
149
|
+
|
|
150
|
+
- `requests`
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
Install dependencies via:
|
|
154
|
+
|
|
155
|
+
`pip install -r requirements.txt`
|
|
156
|
+
|
|
157
|
+
`requirements.txt` content:
|
|
158
|
+
|
|
159
|
+
`requests`
|
|
160
|
+
|
|
161
|
+
----------
|
|
162
|
+
|
|
163
|
+
## ๐ License
|
|
164
|
+
|
|
165
|
+
MIT License
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
|
|
2
|
+
# ๐ง redfishLiteApi
|
|
3
|
+
|
|
4
|
+
A lightweight command-line tool to interact with Redfish APIs using `GET`, `POST`, and `PATCH` methods. Designed for quick testing, debugging, and field extraction.
|
|
5
|
+
|
|
6
|
+
----------
|
|
7
|
+
|
|
8
|
+
## ๐ฆ Features
|
|
9
|
+
|
|
10
|
+
- โ
Support for `GET`, `POST`, and `PATCH`
|
|
11
|
+
|
|
12
|
+
- ๐ Basic Authentication (`-U` / `-P`)
|
|
13
|
+
|
|
14
|
+
- ๐ JSON body input via file (`--json_file`)
|
|
15
|
+
|
|
16
|
+
- ๐ Recursive field value search with `--find` (supports multiple fields)
|
|
17
|
+
|
|
18
|
+
- ๐พ Save response to file (`--save`)
|
|
19
|
+
|
|
20
|
+
- ๐งพ Custom HTTP headers (`--header`)
|
|
21
|
+
|
|
22
|
+
- โฑ๏ธ 10-second request timeout to prevent hanging
|
|
23
|
+
|
|
24
|
+
- ๐งฏ Disable SSL verification warnings
|
|
25
|
+
|
|
26
|
+
- ๐ก HTTP Status display
|
|
27
|
+
|
|
28
|
+
- โ ๏ธ JSON parse error handling with fallback to raw text
|
|
29
|
+
|
|
30
|
+
- ๐ข `--version` support
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
----------
|
|
34
|
+
|
|
35
|
+
## ๐ Usage
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
`python redfishLiteApi.py --url <API_URL> --method <get|post|patch> [OPTIONS]`
|
|
39
|
+
|
|
40
|
+
### โ
Example: Basic GET request
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
`python redfishLiteApi.py --url https://<host>/redfish/v1/Systems --method get`
|
|
44
|
+
|
|
45
|
+
### ๐ Example: Authenticated GET with header and find field
|
|
46
|
+
|
|
47
|
+
`python redfishLiteApi.py --url https://<host>/redfish/v1/Systems --method get \
|
|
48
|
+
-U admin -P password \
|
|
49
|
+
--header "If-Match:W/\"etag-value\"" \
|
|
50
|
+
--find Id Name PowerState`
|
|
51
|
+
|
|
52
|
+
### ๐ Example: PATCH with body file
|
|
53
|
+
|
|
54
|
+
`python redfishLiteApi.py --url https://<host>/redfish/v1/Managers/1/EthernetInterfaces/1 \
|
|
55
|
+
--method patch -U admin -P password --json_file update.json`
|
|
56
|
+
|
|
57
|
+
### ๐พ Example: Save output to file
|
|
58
|
+
|
|
59
|
+
`python redfishLiteApi.py --url https://<host>/redfish/v1/Systems --method get --save output.json`
|
|
60
|
+
|
|
61
|
+
### ๐ Check version
|
|
62
|
+
|
|
63
|
+
`python redfishLiteApi.py --version`
|
|
64
|
+
|
|
65
|
+
----------
|
|
66
|
+
|
|
67
|
+
## ๐ง Argument Summary
|
|
68
|
+
|
|
69
|
+
Argument
|
|
70
|
+
|
|
71
|
+
Description
|
|
72
|
+
|
|
73
|
+
`--url`
|
|
74
|
+
|
|
75
|
+
Redfish API endpoint URL (required)
|
|
76
|
+
|
|
77
|
+
`--method`
|
|
78
|
+
|
|
79
|
+
HTTP method: `get`, `post`, or `patch` (required)
|
|
80
|
+
|
|
81
|
+
`-U` / `--username`
|
|
82
|
+
|
|
83
|
+
Basic auth username
|
|
84
|
+
|
|
85
|
+
`-P` / `--password`
|
|
86
|
+
|
|
87
|
+
Basic auth password
|
|
88
|
+
|
|
89
|
+
`--json_file`
|
|
90
|
+
|
|
91
|
+
Path to JSON file for POST or PATCH body
|
|
92
|
+
|
|
93
|
+
`--find`
|
|
94
|
+
|
|
95
|
+
One or more JSON field names to recursively extract (GET only)
|
|
96
|
+
|
|
97
|
+
`--save`
|
|
98
|
+
|
|
99
|
+
Save the response body to a file
|
|
100
|
+
|
|
101
|
+
`--header`
|
|
102
|
+
|
|
103
|
+
Custom headers in `Key:Value` format (can be repeated)
|
|
104
|
+
|
|
105
|
+
`--version`
|
|
106
|
+
|
|
107
|
+
Show current version and exit
|
|
108
|
+
|
|
109
|
+
----------
|
|
110
|
+
|
|
111
|
+
## โ ๏ธ Notes
|
|
112
|
+
|
|
113
|
+
- SSL certificate verification is disabled (`verify=False`).
|
|
114
|
+
|
|
115
|
+
- Timeout is hardcoded to 10 seconds.
|
|
116
|
+
|
|
117
|
+
- HTTP error handling is basic โ be sure to inspect the response if you encounter unexpected results.
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
----------
|
|
121
|
+
|
|
122
|
+
## ๐ Dependencies
|
|
123
|
+
|
|
124
|
+
- Python 3.x
|
|
125
|
+
|
|
126
|
+
- `requests`
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
Install dependencies via:
|
|
130
|
+
|
|
131
|
+
`pip install -r requirements.txt`
|
|
132
|
+
|
|
133
|
+
`requirements.txt` content:
|
|
134
|
+
|
|
135
|
+
`requests`
|
|
136
|
+
|
|
137
|
+
----------
|
|
138
|
+
|
|
139
|
+
## ๐ License
|
|
140
|
+
|
|
141
|
+
MIT License
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: redfishLiteApi
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A lightweight Redfish API command-line tool
|
|
5
|
+
Home-page: https://github.com/jeffery12240122/redfishLiteAPI
|
|
6
|
+
Author: Jeffery Lin
|
|
7
|
+
Author-email: jeffery12240122@gmail.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Requires-Python: >=3.6
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: requests>=2.25.1
|
|
15
|
+
Dynamic: author
|
|
16
|
+
Dynamic: author-email
|
|
17
|
+
Dynamic: classifier
|
|
18
|
+
Dynamic: description
|
|
19
|
+
Dynamic: description-content-type
|
|
20
|
+
Dynamic: home-page
|
|
21
|
+
Dynamic: requires-dist
|
|
22
|
+
Dynamic: requires-python
|
|
23
|
+
Dynamic: summary
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# ๐ง redfishLiteApi
|
|
27
|
+
|
|
28
|
+
A lightweight command-line tool to interact with Redfish APIs using `GET`, `POST`, and `PATCH` methods. Designed for quick testing, debugging, and field extraction.
|
|
29
|
+
|
|
30
|
+
----------
|
|
31
|
+
|
|
32
|
+
## ๐ฆ Features
|
|
33
|
+
|
|
34
|
+
- โ
Support for `GET`, `POST`, and `PATCH`
|
|
35
|
+
|
|
36
|
+
- ๐ Basic Authentication (`-U` / `-P`)
|
|
37
|
+
|
|
38
|
+
- ๐ JSON body input via file (`--json_file`)
|
|
39
|
+
|
|
40
|
+
- ๐ Recursive field value search with `--find` (supports multiple fields)
|
|
41
|
+
|
|
42
|
+
- ๐พ Save response to file (`--save`)
|
|
43
|
+
|
|
44
|
+
- ๐งพ Custom HTTP headers (`--header`)
|
|
45
|
+
|
|
46
|
+
- โฑ๏ธ 10-second request timeout to prevent hanging
|
|
47
|
+
|
|
48
|
+
- ๐งฏ Disable SSL verification warnings
|
|
49
|
+
|
|
50
|
+
- ๐ก HTTP Status display
|
|
51
|
+
|
|
52
|
+
- โ ๏ธ JSON parse error handling with fallback to raw text
|
|
53
|
+
|
|
54
|
+
- ๐ข `--version` support
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
----------
|
|
58
|
+
|
|
59
|
+
## ๐ Usage
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
`python redfishLiteApi.py --url <API_URL> --method <get|post|patch> [OPTIONS]`
|
|
63
|
+
|
|
64
|
+
### โ
Example: Basic GET request
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
`python redfishLiteApi.py --url https://<host>/redfish/v1/Systems --method get`
|
|
68
|
+
|
|
69
|
+
### ๐ Example: Authenticated GET with header and find field
|
|
70
|
+
|
|
71
|
+
`python redfishLiteApi.py --url https://<host>/redfish/v1/Systems --method get \
|
|
72
|
+
-U admin -P password \
|
|
73
|
+
--header "If-Match:W/\"etag-value\"" \
|
|
74
|
+
--find Id Name PowerState`
|
|
75
|
+
|
|
76
|
+
### ๐ Example: PATCH with body file
|
|
77
|
+
|
|
78
|
+
`python redfishLiteApi.py --url https://<host>/redfish/v1/Managers/1/EthernetInterfaces/1 \
|
|
79
|
+
--method patch -U admin -P password --json_file update.json`
|
|
80
|
+
|
|
81
|
+
### ๐พ Example: Save output to file
|
|
82
|
+
|
|
83
|
+
`python redfishLiteApi.py --url https://<host>/redfish/v1/Systems --method get --save output.json`
|
|
84
|
+
|
|
85
|
+
### ๐ Check version
|
|
86
|
+
|
|
87
|
+
`python redfishLiteApi.py --version`
|
|
88
|
+
|
|
89
|
+
----------
|
|
90
|
+
|
|
91
|
+
## ๐ง Argument Summary
|
|
92
|
+
|
|
93
|
+
Argument
|
|
94
|
+
|
|
95
|
+
Description
|
|
96
|
+
|
|
97
|
+
`--url`
|
|
98
|
+
|
|
99
|
+
Redfish API endpoint URL (required)
|
|
100
|
+
|
|
101
|
+
`--method`
|
|
102
|
+
|
|
103
|
+
HTTP method: `get`, `post`, or `patch` (required)
|
|
104
|
+
|
|
105
|
+
`-U` / `--username`
|
|
106
|
+
|
|
107
|
+
Basic auth username
|
|
108
|
+
|
|
109
|
+
`-P` / `--password`
|
|
110
|
+
|
|
111
|
+
Basic auth password
|
|
112
|
+
|
|
113
|
+
`--json_file`
|
|
114
|
+
|
|
115
|
+
Path to JSON file for POST or PATCH body
|
|
116
|
+
|
|
117
|
+
`--find`
|
|
118
|
+
|
|
119
|
+
One or more JSON field names to recursively extract (GET only)
|
|
120
|
+
|
|
121
|
+
`--save`
|
|
122
|
+
|
|
123
|
+
Save the response body to a file
|
|
124
|
+
|
|
125
|
+
`--header`
|
|
126
|
+
|
|
127
|
+
Custom headers in `Key:Value` format (can be repeated)
|
|
128
|
+
|
|
129
|
+
`--version`
|
|
130
|
+
|
|
131
|
+
Show current version and exit
|
|
132
|
+
|
|
133
|
+
----------
|
|
134
|
+
|
|
135
|
+
## โ ๏ธ Notes
|
|
136
|
+
|
|
137
|
+
- SSL certificate verification is disabled (`verify=False`).
|
|
138
|
+
|
|
139
|
+
- Timeout is hardcoded to 10 seconds.
|
|
140
|
+
|
|
141
|
+
- HTTP error handling is basic โ be sure to inspect the response if you encounter unexpected results.
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
----------
|
|
145
|
+
|
|
146
|
+
## ๐ Dependencies
|
|
147
|
+
|
|
148
|
+
- Python 3.x
|
|
149
|
+
|
|
150
|
+
- `requests`
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
Install dependencies via:
|
|
154
|
+
|
|
155
|
+
`pip install -r requirements.txt`
|
|
156
|
+
|
|
157
|
+
`requirements.txt` content:
|
|
158
|
+
|
|
159
|
+
`requests`
|
|
160
|
+
|
|
161
|
+
----------
|
|
162
|
+
|
|
163
|
+
## ๐ License
|
|
164
|
+
|
|
165
|
+
MIT License
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
redfishLiteApi.py
|
|
3
|
+
setup.py
|
|
4
|
+
redfishLiteApi.egg-info/PKG-INFO
|
|
5
|
+
redfishLiteApi.egg-info/SOURCES.txt
|
|
6
|
+
redfishLiteApi.egg-info/dependency_links.txt
|
|
7
|
+
redfishLiteApi.egg-info/entry_points.txt
|
|
8
|
+
redfishLiteApi.egg-info/requires.txt
|
|
9
|
+
redfishLiteApi.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.25.1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
redfishLiteApi
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import json
|
|
3
|
+
import requests
|
|
4
|
+
from requests.auth import HTTPBasicAuth
|
|
5
|
+
import sys
|
|
6
|
+
import urllib3
|
|
7
|
+
|
|
8
|
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
9
|
+
|
|
10
|
+
VERSION = "1.0.0"
|
|
11
|
+
|
|
12
|
+
def parse_args():
|
|
13
|
+
parser = argparse.ArgumentParser(description='Redfish Lite API Tool')
|
|
14
|
+
parser.add_argument('--url', required=True, help='Target Redfish API endpoint')
|
|
15
|
+
parser.add_argument('--method', required=True, choices=['get', 'post', 'patch'], help='HTTP method')
|
|
16
|
+
parser.add_argument('-U', '--username', help='Username for authentication')
|
|
17
|
+
parser.add_argument('-P', '--password', help='Password for authentication')
|
|
18
|
+
parser.add_argument('--json_file', help='Path to JSON file for request body (only for POST or PATCH)')
|
|
19
|
+
parser.add_argument('--find', nargs='+', help='Find and display value(s) of specific field(s) in JSON response (only for GET)')
|
|
20
|
+
parser.add_argument('--save', help='Save response output to specified file')
|
|
21
|
+
parser.add_argument('--header', action='append', help='Custom header(s), format: Key:Value')
|
|
22
|
+
parser.add_argument('--version', action='store_true', help='Show tool version and exit')
|
|
23
|
+
return parser.parse_args()
|
|
24
|
+
|
|
25
|
+
def load_json(file_path):
|
|
26
|
+
try:
|
|
27
|
+
with open(file_path, 'r') as f:
|
|
28
|
+
return json.load(f)
|
|
29
|
+
except Exception as e:
|
|
30
|
+
print(f"โ Error loading JSON file: {e}")
|
|
31
|
+
sys.exit(1)
|
|
32
|
+
|
|
33
|
+
def extract_fields(obj, field_names):
|
|
34
|
+
results = []
|
|
35
|
+
def recursive_search(o):
|
|
36
|
+
if isinstance(o, dict):
|
|
37
|
+
for k, v in o.items():
|
|
38
|
+
if k in field_names:
|
|
39
|
+
results.append(f"{k}: {v}")
|
|
40
|
+
recursive_search(v)
|
|
41
|
+
elif isinstance(o, list):
|
|
42
|
+
for item in o:
|
|
43
|
+
recursive_search(item)
|
|
44
|
+
recursive_search(obj)
|
|
45
|
+
return results
|
|
46
|
+
|
|
47
|
+
def handle_save_response(resp, save_path):
|
|
48
|
+
if save_path:
|
|
49
|
+
try:
|
|
50
|
+
content = resp.json()
|
|
51
|
+
with open(save_path, 'w', encoding='utf-8') as f:
|
|
52
|
+
json.dump(content, f, indent=4, ensure_ascii=False)
|
|
53
|
+
except ValueError:
|
|
54
|
+
with open(save_path, 'w', encoding='utf-8') as f:
|
|
55
|
+
f.write(resp.text)
|
|
56
|
+
print(f"๐พ Response saved to {save_path}")
|
|
57
|
+
|
|
58
|
+
def main():
|
|
59
|
+
args = parse_args()
|
|
60
|
+
|
|
61
|
+
if args.version:
|
|
62
|
+
print(f"redfishLiteApi version: {VERSION}")
|
|
63
|
+
return
|
|
64
|
+
|
|
65
|
+
headers = {
|
|
66
|
+
'Accept': 'application/json',
|
|
67
|
+
'Content-Type': 'application/json'
|
|
68
|
+
}
|
|
69
|
+
if args.header:
|
|
70
|
+
for header in args.header:
|
|
71
|
+
try:
|
|
72
|
+
key, value = header.split(':', 1)
|
|
73
|
+
headers[key.strip()] = value.strip()
|
|
74
|
+
except ValueError:
|
|
75
|
+
print(f"โ Invalid header format: {header}. Use Key:Value")
|
|
76
|
+
sys.exit(1)
|
|
77
|
+
|
|
78
|
+
payload = load_json(args.json_file) if args.json_file else None
|
|
79
|
+
auth = HTTPBasicAuth(args.username, args.password) if args.username and args.password else None
|
|
80
|
+
|
|
81
|
+
try:
|
|
82
|
+
timeout = 10 # seconds
|
|
83
|
+
|
|
84
|
+
if args.method == 'get':
|
|
85
|
+
resp = requests.get(args.url, auth=auth, headers=headers, verify=False, timeout=timeout)
|
|
86
|
+
elif args.method == 'post':
|
|
87
|
+
resp = requests.post(args.url, auth=auth, headers=headers, json=payload, verify=False, timeout=timeout)
|
|
88
|
+
elif args.method == 'patch':
|
|
89
|
+
resp = requests.patch(args.url, auth=auth, headers=headers, json=payload, verify=False, timeout=timeout)
|
|
90
|
+
|
|
91
|
+
print(f"๐ HTTP Status: {resp.status_code}")
|
|
92
|
+
try:
|
|
93
|
+
data = resp.json()
|
|
94
|
+
if args.method == 'get' and args.find:
|
|
95
|
+
matches = extract_fields(data, args.find)
|
|
96
|
+
if matches:
|
|
97
|
+
for i, match in enumerate(matches, 1):
|
|
98
|
+
print(f"[{i}] {match}")
|
|
99
|
+
else:
|
|
100
|
+
print("โ ๏ธ No matching fields found.")
|
|
101
|
+
else:
|
|
102
|
+
print(json.dumps(data, indent=4))
|
|
103
|
+
handle_save_response(resp, args.save)
|
|
104
|
+
except ValueError:
|
|
105
|
+
print("โ ๏ธ Response is not JSON:")
|
|
106
|
+
print(resp.text)
|
|
107
|
+
handle_save_response(resp, args.save)
|
|
108
|
+
|
|
109
|
+
except requests.exceptions.RequestException as e:
|
|
110
|
+
print(f"โ Request failed: {e}")
|
|
111
|
+
sys.exit(1)
|
|
112
|
+
|
|
113
|
+
if __name__ == '__main__':
|
|
114
|
+
main()
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
with open("README.md", "r", encoding="utf-8") as fh:
|
|
4
|
+
long_description = fh.read()
|
|
5
|
+
|
|
6
|
+
setup(
|
|
7
|
+
name="redfishLiteApi",
|
|
8
|
+
version="1.0.0",
|
|
9
|
+
author="Jeffery Lin",
|
|
10
|
+
author_email="jeffery12240122@gmail.com",
|
|
11
|
+
description="A lightweight Redfish API command-line tool",
|
|
12
|
+
long_description=long_description,
|
|
13
|
+
long_description_content_type="text/markdown",
|
|
14
|
+
url="https://github.com/jeffery12240122/redfishLiteAPI",
|
|
15
|
+
py_modules=["redfishLiteApi"],
|
|
16
|
+
classifiers=[
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Environment :: Console",
|
|
20
|
+
"License :: OSI Approved :: MIT License"
|
|
21
|
+
],
|
|
22
|
+
python_requires='>=3.6',
|
|
23
|
+
install_requires=[
|
|
24
|
+
"requests>=2.25.1"
|
|
25
|
+
],
|
|
26
|
+
entry_points={
|
|
27
|
+
'console_scripts': [
|
|
28
|
+
'redfishLiteApi=redfishLiteApi:main',
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
)
|