Skip to content

Conversation

@mvidner
Copy link
Contributor

@mvidner mvidner commented Apr 9, 2025

mvidner added a commit to agama-project/agama that referenced this pull request Apr 10, 2025
## Problem

`agama profile` still executes its actions directly from the CLI client,
not using the web service. Fix it to make it work like `agama --api $URL
config ...` already does.

- https://trello.com/c/fqPGL2qe

`agama profile` command summary... it is a diverse bunch! (related,
unplanned stub:
https://trello.com/c/3aUupc2F/461-unify-config-and-profile-commands-in-the-cli
)
```
profile_evaluate(jsonnet_path) -> json stdout
profile_validate(json_path) -> print whether valid, what problems
profile_autoyast(autoyast_url) -> json stdout
profile_import(url) -> performs config_load
  # oh fun!
  if url ends with .xml OR .erb OR /
    profile_autoyast
  else download the file and analyze content
    if is_script # starts with hash-bang and the program is not "jsonnet"
      EXECVE it # which means replace current process. OMG WTF inconsistent UX
    else if is_jsonnet
      profile_evaluate
    else if is_json
      cat
    else
      return Error
  # at this point we have a JSON file
  profile_validate # NOTE that invalid profile is just a message and we continue
  agama_config_load
```

## Solution

Added these 3 new web API paths corresponding 1-1 to the CLI commands:
- POST /api/profile/validate ?url= ?path= (or body)
- POST /api/profile/evaluate ?url= ?path= (or body)
- POST /api/profile/autoyast ?url=

But `agama profile import` is notable that it effectively includes an
`agama
config load` which is implemented as multiple backend calls, so `import`
stays at the front end and the back end only gets what's needed to make
it work,
which is running a script:
- POST /api/profile/execute_script ?url= ?path= (or body)

(TODO explain the rest)

### Backend errors now include their causes 

Before:
> Anyhow(Backend call failed with status 400 and text '{"error":"Error:
Could not evaluate the profile"}')
    
After:
> Anyhow(Backend call failed with status 400 and text '{"error":"Error:
Could not evaluate the profile: Failed to read system's hardware
information: Failed to read agama.libsonnet: No such file or directory
(os error 2)"}')

### JSON validation errors are more readable now

<details>
<summary>
We used to include a debug representation of the validation error but
reading the manual(!) shows there is a way to just point to the
offending piece of JSON
</summary>

```console
$ cat ...
{  "product": {    "ID": "Tumbleweed"  }}
$ agama profile validate rust/agama-lib/share/examples/profile_tw_invalid.json
The profile is not valid. Please, check the following errors:
```

Before:
> * Additional properties are not allowed ('ID' was unexpected).
ValidationError { instance: Object {"ID": String("Tumbleweed")}, kind:
AdditionalProperties { unexpected: ["ID"] }, instance_path:
JSONPointer([Property("product")]), schema_path:
JSONPointer([Keyword("properties"), Property("product"),
Keyword("additionalProperties")]) }
> * "id" is a required property. ValidationError { instance: Object
{"ID": String("Tumbleweed")}, kind: Required { property: String("id") },
instance_path: JSONPointer([Property("product")]), schema_path:
JSONPointer([Keyword("properties"), Property("product"),
Keyword("required")]) }

After:
> * Additional properties are not allowed ('ID' was unexpected).
/product
> * "id" is a required property. /product
</details>

## Testing

Unit tests: no

### Manual tests

...

### Added integration tests expecting a running web service.

Run like (part of .github/workflows/ci-integration-tests.yml)
```sh
(cd service/; bundle exec rspec --pattern 'test/integration/**_itest.rb')
```
- [x] agama profile validate
- [x] agama profile evaluate
- [x] agama profile autoyast ... turns out hard to test with the
AY-special URLs as **none** of them work in my container
- [x] agama profile import
- [ ] agama --api ... profile ... hitting an opaque SSL handshake error
:sob:


## Screenshots

(textual screenshots coming up)

## Documentation

Documented the extended argument handling:

- autoinstallation/README.md adjusted
- agama-project/agama-project.github.io#70

But we are actually still missing documentation for the `--api` option
itself, except for [a mention in the
blog](https://agama-project.github.io/blog/2025/01/21/Agama-11#remotecli).
IMHO we should add it as part of the `config`/`profile` cleanup.
@mvidner mvidner merged commit 666fb8f into main Apr 11, 2025
3 checks passed
@mvidner mvidner deleted the agama-profile-apiurl branch April 11, 2025 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants