Skip to content
This repository was archived by the owner on Aug 9, 2024. It is now read-only.

Commit 65ff7ff

Browse files
feat(action): allow additional request types
1 parent ed2bf5f commit 65ff7ff

File tree

3 files changed

+67
-22
lines changed

3 files changed

+67
-22
lines changed

action.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ inputs:
99
description: Accept Plex's EULA.
1010
default: "false"
1111
required: false
12-
additional_server_queries_put:
12+
additional_server_queries:
1313
description: >-
14-
Space separated list of additional PUT requests to send to the server. The requests are sent before the
15-
library sections are created. You can use this to enable third party metadata agents, as an example.
16-
e.g. `/system/agents/com.plexapp.agents.imdb/config/1?order=com.plexapp.agents.imdb%2C<my_movie_agent>`
14+
Space separated list of additional requests to send to the server. The type of request should be at the beginning
15+
of the endpoint, followed by a `|`. If no `|` is found the default request type of `PUT` will be used.
16+
The requests are sent before the library sections are created.
17+
You can use this to enable third party metadata agents, as an example.
18+
e.g. `put|/system/agents/com.plexapp.agents.imdb/config/1?order=com.plexapp.agents.imdb%2C<my_movie_agent>`
1719
default: ""
1820
required: false
1921
bootstrap_timeout:
@@ -325,9 +327,9 @@ runs:
325327
if [[ "${{ inputs.accept_eula }}" == "true" ]]; then
326328
accept_eula="--accept-eula"
327329
fi
328-
if [[ -n "${{ inputs.additional_server_queries_put }}" ]]; then
329-
echo "additional_server_queries_put: ${{ inputs.additional_server_queries_put }}"
330-
server_queries_put="--additional-server-queries-put ${{ inputs.additional_server_queries_put }}"
330+
if [[ -n "${{ inputs.additional_server_queries }}" ]]; then
331+
echo "additional_server_queries: ${{ inputs.additional_server_queries }}"
332+
server_queries_put="--additional-server-queries ${{ inputs.additional_server_queries }}"
331333
fi
332334
if [[ "${{ inputs.use_docker }}" == "false" ]]; then
333335
use_docker="--no-docker"

docs/source/about/github_action.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ Inputs
2828
- Accept Plex's EULA.
2929
- ``false``
3030
- false
31-
* - ``additional_server_queries_put``
32-
- Space separated list of additional PUT requests to send to the server. The requests are sent before the
33-
library sections are created. You can use this to enable third party metadata agents, as an example.
34-
e.g. `/system/agents/com.plexapp.agents.imdb/config/1?order=com.plexapp.agents.imdb%2C<my_movie_agent>`
31+
* - ``additional_server_queries``
32+
- Space separated list of additional requests to send to the server. The type of request should be at the beginning
33+
of the endpoint, followed by a `|`. If no `|` is found the default request type of `PUT` will be used.
34+
The requests are sent before the library sections are created.
35+
You can use this to enable third party metadata agents, as an example.
36+
e.g. `put|/system/agents/com.plexapp.agents.imdb/config/1?order=com.plexapp.agents.imdb%2C<my_movie_agent>`
3537
- ``""``
3638
- false
3739
* - ``bootstrap_timeout``

scripts/plex_bootstraptest.py

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,14 @@ def alert_callback(data):
385385
"--accept-eula", help="Accept Plex's EULA", default=False, action="store_true"
386386
) # noqa
387387
parser.add_argument(
388-
"--additional-server-queries-put",
389-
help="Comma separated list of additional PUT requests to send to the server. The requests are sent before the "
390-
"library sections are created. You can use this to enable third party metadata agents, as an example. "
391-
"e.g. `/system/agents/com.plexapp.agents.imdb/config/1?order=com.plexapp.agents.imdb%2C<my_movie_agent>`",
388+
"--additional-server-queries",
389+
help="Space separated list of additional requests to send to the server. The type of request should be at the "
390+
"beginning of the endpoint, followed by a `|`. "
391+
"If no `|` is found the default request type of `PUT` will be used. "
392+
"The requests are sent before the library sections are created. "
393+
"You can use this to enable third party metadata agents, as an example. "
394+
"e.g. "
395+
"`put|/system/agents/com.plexapp.agents.imdb/config/1?order=com.plexapp.agents.imdb%2C<my_movie_agent>` ",
392396
default=[],
393397
nargs='*',
394398
) # noqa
@@ -734,13 +738,50 @@ def alert_callback(data):
734738
)
735739

736740
# send additional server queries
737-
if opts.additional_server_queries_put:
738-
print("Sending additional PUT requests to the server")
739-
print("Additional PUT requests: {}".format(opts.additional_server_queries_put))
740-
for query in opts.additional_server_queries_put:
741-
query = query.strip()
742-
print("Sending PUT request to {}".format(query))
743-
server.query(key=query, method=server._session.put)
741+
if opts.additional_server_queries:
742+
request_map = {
743+
"delete": server._session.delete,
744+
"get": server._session.get,
745+
"post": server._session.post,
746+
"put": server._session.put,
747+
}
748+
749+
print("Sending additional requests to the server")
750+
print("Additional requests: {}".format(opts.additional_server_queries))
751+
752+
completed_queries = []
753+
start = time.time()
754+
runtime = 0
755+
while runtime < 60 and len(completed_queries) < len(opts.additional_server_queries):
756+
for query in opts.additional_server_queries:
757+
query = query.strip()
758+
if query not in completed_queries:
759+
if '|' in query:
760+
method, key = query.split('|')
761+
method = method.strip()
762+
key = key.strip()
763+
else:
764+
method = 'put'
765+
key = query.strip()
766+
767+
if method not in request_map:
768+
raise SystemExit("Invalid method specified: {}".format(method))
769+
if not key.startswith('/'):
770+
raise SystemExit("Invalid key specified: {}".format(key))
771+
print("Sending {} request to {}".format(method, key))
772+
try:
773+
server.query(key=key, method=request_map[method])
774+
except NotFound as err:
775+
# if 404, wait
776+
print("error: {}".format(err))
777+
time.sleep(5)
778+
else:
779+
completed_queries.append(query)
780+
finally:
781+
runtime = time.time() - start
782+
783+
if len(completed_queries) < len(opts.additional_server_queries):
784+
raise SystemExit("Did not successfully complete all additional server queries")
744785

745786
# Create the Plex library in our instance
746787
if sections:

0 commit comments

Comments
 (0)