canonical / canonical/python-libmaas
ActionAPIs with name "import" are broken due to using a reserved keyword
- Lenguaje dominante
- Python
- Estrellas
- 65
- Forks
- 71
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
```
Python 3.8.10 (default, Mar 15 2022, 12:22:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from maas.client.bones import SessionAPI
>>> credentials=['zbL4fkkuxqxhDRauv9', 'tfymrvVay9qZGJFAR9', 'A4dJNDB8LUNFKUWx46gtCdhsVAg8aSkB']
>>> client = SessionAPI.fromURL(url="http://192.168.61.8:5240/MAAS/api/2.0/",credentials=credentials, insecure=True)
>>> client.SSHKeys.import(keysource='gh:canozyurt')
File "", line 1
client.SSHKeys.import(keysource='gh:canozyurt')
^
SyntaxError: invalid syntax
>>>
```
I modified the API description json to export "import" action as "add" instead and published the json via 8080. I left the paths and URIs untouched so SessionAPI can still connect to the same MAAS instance.
```
{
"anon":null,
"auth":{
"actions":[
{
"method":"POST",
"name":"add",
"doc":"Import SSH keys\n\nImport the requesting user's SSH keys for a given protocol\nand authorization ID in protocol:auth_id format.\n\n:param keysource: Required. The source\nof the keys to import should be provided in the request payload as form\ndata:\n\nE.g.\n\n source:user\n\n- ``source``: lp (Launchpad), gh (GitHub)\n- ``user``: User login\n:type keysource: String\n\n ",
"op":"import",
"restful":false
},
{
"method":"GET",
"name":"read",
"doc":"List SSH keys\n\nList all keys belonging to the requesting user.\n\n",
"op":null,
"restful":true
},
{
"method":"POST",
"name":"create",
"doc":"Add a new SSH key\n\nAdd a new SSH key to the requesting or supplied user's\naccount.\n\n:param key: Required. A public SSH key\nshould be provided in the request payload as form data with the name\n'key':\n\n key: \"key-type public-key-data\"\n\n- ``key-type``: ecdsa-sha2-nistp256, ecdsa-sha2-nistp384,\n ecdsa-sha2-nistp521, ssh-dss, ssh-ed25519, ssh-rsa\n- ``public key data``: Base64-encoded key data.\n:type key: String\n\n ",
"op":null,
"restful":true
}
],
"doc":"Manage the collection of all the SSH keys in this MAAS.",
"name":"SSHKeysHandler",
"params":[
],
"path":"/MAAS/api/2.0/account/prefs/sshkeys/",
"uri":"http://192.168.61.8:5240/MAAS/api/2.0/account/prefs/sshkeys/"
},
"name":"SSHKeysHandler"
},
```
The request went through and returned success.
```
>>> client = SessionAPI.fromURL(url="http://192.168.61.8:8080/",credentials=credentials, insecure=True)
>>> client.SSHKeys.add(keysource='gh:canozyurt')
[{'key': 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDmtjegTY011FoyM5u1wQABWWg1bwEzQ8CoOG0DLcqATLt4wVK3+MaxzIVZElcQG9M4H7ghekqRaaV+vVt/OnM6p97qyQ40urqco+H5fBkVuygFXtZeQngL2QUSUhB8nm2pVHu4eI1P/ObcIejFSfmDcAKRgcKZLoLqY86CD7e4dBOOGBfMw5cWMsuB2derRt1gimAMcnGDh9DapaAX9Qu7oLwWwQc5qWYntyhRtLpAEXcWuptN+zbJGz2ydzCVqD9SqPhsTemdItUrSMngPYxThzvuxVCgr1PuTwtpYNF0FGOJ5JI0T1E3b3hTI+BB0ckyuSzJR5GSCYMWWAm8/vp6bzWsoFXgJUW8fvLbH6pIboSg5uQ1Toic9YgT1qWdt2u/0Uii+Y6FUQ5HqfK1BcmdqdjMPwkgmAiAKCD5y6hfb88ElF5JiZaxNvH/YgH5LMJzO6XAzShvayqvoXu+EUXGhfZRBvfTHzzlbw7+MjoH+he0nSNlVPp7gJrOsrhkWNE=', 'keysource': 'gh:canozyurt', 'id': 7, 'resource_uri': '/MAAS/api/2.0/account/prefs/sshkeys/7/'}]
>>>
```
All other import actions available in other handlers seem affected too.
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Comienza con la ruta SessionAPI.fromURL y el manejo de ActionAPI que convierte los nombres de acciones del JSON de descripción de la API en atributos de Python. Reproduce el SSHKeys.import SyntaxError y verifica después que las acciones con palabras reservadas sigan pudiéndose invocar en todos los handlers sin cambiar su operación, rutas ni URIs.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- api
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 42/100