opalstack / opalstack-python Goto Github PK
View Code? Open in Web Editor NEWOpalstack Python API Library
License: MIT License
Opalstack Python API Library
License: MIT License
clone_wp_site.py does not update the cloned wp-config to point to the dst database. And so the dst app unintentionally reads and writes to the src database.
This means that when the script updates the siteurl
and home
options through the wp-cli tool, it modifies the src database, even though it's intended for the dst app.
opalstack-python/examples/clone_wp_site.py
Lines 159 to 161 in 13642f1
So you end up with the src app redirecting to the dst domain, which is serving the dst app, but is still using the src database.
Issue:
Endpoint methods currently return the JSON result from the API as a python object.
This means all other information regarding the response is lost, such as the status code. It also means the return type is unknown as it can sometimes be a list and other times a dict.
This leads to the issue that the only way to determine if a response was a 400 or 200 is by inspecting the returned result.
Proposed solution:
Return response objects with either the the decoded json content is available with content
attribute decoded and replaced in place or with another attribute result
with the decoded JSON.response.json()
I am happy to make a PR for this but it's a backwards incompatible change!
Perhaps there is a way to make it backwards compatible by returning an object of a custom class that behaves as the list/dict but with extra attributes for the response object. But this sounds complicated =]
An app created by clone_wp_site.py will have an "empty" config.
Some consequences:
I expected the script to clone the config from the src app, or use defaults that matched dashboard-created apps.
Thanks,
Chad
For reference, this is the current app creation code.
opalstack-python/examples/clone_wp_site.py
Lines 108 to 115 in 13642f1
Issue:
In my application I need to be able to handle when the API returns with a 400 status code for a "create" endpoint so I can display the returned form errors to the user.
Currently when a 400 is returned a RuntimeError is raised with a message along the lines of Unexpected status_code: 400, result: {"non_field_errors": ...}
this means the result is swallowed along with the status code.
In this case I don't think any exception should be raised because we can expect a 400 as a valid response for the API.
The same is true for when a 404 is returned for a "delete" or "update" endpoint.
Proposed solution:
Update the appropriate calls to http_post_result
throughout and add the appropriate status in the ensure_status
kwarg.
I can make a PR for this but it's not as simple as this. There are considerations at least for when wait=True
in ApiModelManager.create
and I expect there will be more. If I can get a test API key so I can run the tests I'll gladly proceed.
Hi, I'm getting an error using clone_wp_site.py to clone an app locally.
Traceback (most recent call last):
...
File "clone_mysite.py", line 156, in main
mariatool_remote.import_remote_db(sshrunner, sql_filepath_remote)
...
RuntimeError: ... /home/myuser/mysite.sql: No such file or directory
[myuser@opal1 ~]$ python3 clone_mysite.py
2022-09-29 15:21:00 : INFO : Retrieving webserver information for opal1.opalstack.com
2022-09-29 15:21:01 : INFO : Retrieving existing osuser myuser
2022-09-29 15:21:02 : INFO : Creating domain test.mysite.com
2022-09-29 15:21:13 : INFO : Creating application mysite
2022-09-29 15:21:35 : INFO : Creating site mysite
2022-09-29 15:21:41 : INFO : Retrieving database configurations
2022-09-29 15:21:45 : INFO : Exporting database
2022-09-29 15:21:46 : INFO : Copying files
2022-09-29 15:21:49 : INFO : Copying database content
2022-09-29 15:21:49 : INFO : Importing database
Traceback (most recent call last):
File "clone_mysite.py", line 170, in <module>
main(args)
File "clone_mysite.py", line 156, in main
mariatool_remote.import_remote_db(sshrunner, sql_filepath_remote)
File "/usr/local/lib/python3.6/site-packages/opalstack/util.py", line 361, in import_remote_db
sshrunner.run_ssh(cmd)
File "/usr/local/lib/python3.6/site-packages/opalstack/util.py", line 259, in run_ssh
return self.run_passbased_ssh(remote_cmd, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/opalstack/util.py", line 144, in run_passbased_ssh
return self.run_via_sshpass(prelude + [remote_cmd], *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/opalstack/util.py", line 133, in run_via_sshpass
return run(prelude + cmd, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/opalstack/util.py", line 23, in run
raise RuntimeError(f'Command "{cmd}" exited with status {p.returncode}. Stderr: {stderr}')
RuntimeError: Command "['sshpass', '-f', 'myuser.sshpass', '/usr/bin/ssh', '-q', '-o', 'PasswordAuthentication=yes', '-o', 'PubkeyAuthentication=no', '-o', 'StrictHostKeyChecking=no', '[[email protected]](mailto:[email protected])', 'mysql --defaults-extra-file=/home/myuser/mysite.sqlpasswd -u mysite_12345678 mysite_12345678 < /home/myuser/mysite.sql']" exited with status 1. Stderr: bash: /home/myuser/mysite.sql: No such file or directory
When src and dst are the same server, line 152 copies the exported sql file to itself, line 153 deletes it, and then line 156 fails when it tries to import the missing file.
opalstack-python/examples/clone_wp_site.py
Lines 151 to 157 in 13642f1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.