canonical / canonical/python-libmaas

ActionAPIs with name "import" are broken due to using a reserved keyword

Aperta
#275 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug
Lingua principale
Python
Stelle
65
Fork
71
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

```
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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia dal percorso SessionAPI.fromURL e dalla gestione di ActionAPI che trasforma i nomi delle azioni del JSON di descrizione dell’API in attributi Python. Riproduci il SSHKeys.import SyntaxError, quindi verifica che le azioni con parole riservate rimangano invocabili in tutti gli handler senza modificare la loro operazione, i percorsi o gli URI.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
api
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.