-
Notifications
You must be signed in to change notification settings - Fork 263
Add cli option to publish to core db. #744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
4a229af
to
c460517
Compare
print("Aborted.") | ||
return False | ||
|
||
target = uri + "/v1/publish/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The APIs entry point is at /api
, so the full path /api/v1/publish/
(see Publish a core file).
Seems like the /api
part is missing in the target generated URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I choose to put the api
part in the publish-uri
setting (e.g. publish-uri = https://fscpd.qamcom.se/api
). I thought it made more sense to let that that point to the root of the api, and then let the code build in that.
I think it would be great to have an additional CLI interface to validate a core using the server’s API endpoint (see Validate a core file). |
sf_data = None | ||
if pem: | ||
print("with certificate from: " + pem) | ||
print("to api at: " + uri) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails if uri is not defined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want a hardcoded default uri? If so, what should it point to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you like to add a default, pointing to the "official" FOSSI Foundation server instance might be a good option:
https://fusesoc.fossi-foundation.net/
We need some documentation as well. |
def core_publish(fs, args): | ||
core = _get_core(fs, args.core) | ||
uri = fs.config.publish_uri | ||
pem = fs.config.publish_uri_pem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean specifically the pem option? It was needed during development since that server was self signed, and why not keep the option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowing HTTPS connections with self-signed certificates - or even HTTP connections - could be a useful feature for local deployments or testing of the FuseSoC Package Directory Server.
res = requests.post(target, files=body, allow_redirects=True, verify=pem) | ||
if not res.ok: | ||
print("Request returned http result", res.status_code, res.reason) | ||
err = json.loads(res.content) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to catch more errors here. If the server responds 404 it looks like there isn't a valid json reply at all
Request returned http result 404 Not Found
Traceback (most recent call last):
File "/home/olof/projects/serv/bin/fusesoc", line 8, in <module>
sys.exit(main())
^^^^^^
File "/home/olof/projects/fusesoc/fusesoc/fusesoc/main.py", line 950, in main
fusesoc(args)
File "/home/olof/projects/fusesoc/fusesoc/fusesoc/main.py", line 940, in fusesoc
args.func(fs, args)
File "/home/olof/projects/fusesoc/fusesoc/fusesoc/main.py", line 417, in core_publish
err = json.loads(res.content)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is a good server to test this against today without causing havoc? I have not been keeping up with recent deployments and deprecations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our internal test server is still up an running.
Alternative you can spin up your own test server following FuseSoC Package Directory Quick Start or Development Guide.
if not res.ok: | ||
print("Request returned http result", res.status_code, res.reason) | ||
err = json.loads(res.content) | ||
print(json.dumps(err, indent=4)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to handle known errors, e.g. validation errors, in a more user-friendly way. Instead of
Request returned http result 400 Bad Request
{
"non_field_errors": [
"Validation error in core::: 'description' is a required property"
]
}
we could look for non_field_errors
and write something like Validation error: 'description' is a required property
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be just the forwarded error messages from the FuseSoC-PD Server. So I guess it is more an server side issue.
On server side, there are already some mechanism in place to replace the default error messages from core parsing/validation with custom messages (but there aren't much implemented right now, see end of core_directory/serializers.py)
print(f"{sigfile} created") | ||
|
||
|
||
def guess_provider(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is quite a lot of new code, I would prefer to have this in a separate publish.py
. main.py
is already way too large for its own good.
) | ||
print(provider_info["yaml"]) | ||
return False | ||
print("Adding the following provider section to the core file.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to avoid adding the provider section to the .core file in the repo. Let's copy the core file to a temporary file instead where we can add the section and publish
def guess_provider(): | ||
guess = {"found": False} | ||
cmd = ["git", "remote", "-v"] | ||
res = subprocess.run(cmd, capture_output=True).stdout.decode("utf-8").strip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's run this from the root directory of the core instead. We can pick up the directory from core.core_root
in core_publish
and send it to guess_provider
as an argument. The reason is that most FuseSoC users have a workspace which is separate from the directories where the cores are.
if len(fetchlines) < 1: | ||
return guess | ||
comps = fetchlines[0].split("/") | ||
if comps[2] == "github.com": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails when there are more than one remote, e g.
$ git remote -v
fork [email protected]:olofk/common_cells.git (fetch)
fork [email protected]:olofk/common_cells.git (push)
origin https://github.com/pulp-platform/common_cells (fetch)
origin https://github.com/pulp-platform/common_cells (push)
In this particular case we might detect this situation and query the user, but my gut feeling tells me that there might be several more cases like this, so I think it would be good to have CLI options to manually specify at least the upstream URI
This depends on changes in pending pull request #743 (signing and verifying).