We usually refrain from exposing DB id publically. In URLs, especially. We
have a couple of exception and since there is no alternative here, I think
it's fine.
Can we rename that to ssh_keys? Unfortunately, you can't use exported_as
because of bug 546324. I think there isn't that many call sites, but feel free
to push back if this is too daunting a task.
> +== SSH keys ===
> +
> +People have SSH keys which we can manipulate over the API.
> +
> +The sample person "name12" doesn't have any keys to begin with:
> +
> + >>> sample_person = webservice.get("/~name12").jsonBody()
> + >>> sshkeys = sample_person['sshkeys_collection_link']
> + >>> print sshkeys
> + http://.../~name12/sshkeys
> + >>> print_self_link_of_entries(webservice.get(sshkeys).jsonBody())
> + http://.../~name12/+ssh-keys/1
It seems it has a key! (You say it doesn't) You should also ellide the DB id
in the URL.
You probably want to use no-priv here who shouldn't have any key to begin
with.
> +
> +Let's give "name12" a key via the back door of our internal Python APIs:
> +
> + >>> from zope.component import getUtility
> + >>> from lp.registry.interfaces.person import IPersonSet
> + >>> login(ANONYMOUS)
> + >>> ssh_user = getUtility(IPersonSet).getByName('name12')
> + >>> ssh_key = factory.makeGPGKey(ssh_user)
You are creating a GPG key here, not a SSH key. (makeSSHKey is what you want
to use)
> + >>> logout()
> +
> +Now when we get the sshkey collection for 'name12' again, the key should show
> +up:
> +
> + >>> keys = webservice.get(sshkeys).jsonBody()
> + >>> print_self_link_of_entries(keys)
> + http://.../~name12/+ssh-keys/1
> +
I would expect a new key here, not the one you showed previously.
You'll want to ellide the DB id in the resulting URL. Probably also the
keytext which should be random. You probably want to modify the makeSSH
factory method to take a fixed comment field. That way you could show it in
the output.
Your test is not working yet, but we are getting there!
> === modified file 'lib/lp/ registry/ browser/ configure. zcml' registry/ browser/ configure. zcml 2010-03-08 01:51:58 +0000 registry/ browser/ configure. zcml 2010-03-09 19:30:49 +0000 cets" "lp.registry. browser. personproduct" /> registry. interfaces. ssh.ISSHKey" ="string: +ssh-keys/ ${id}" to_parent= "person" />
> --- lib/lp/
> +++ lib/lp/
> @@ -2172,4 +2172,9 @@
> classes="
> PersonProductFa
> module=
> + <browser:url
> + for="lp.
> + path_expression
> + rootsite="api"
> + attribute_
> </configure>
We usually refrain from exposing DB id publically. In URLs, especially. We
have a couple of exception and since there is no alternative here, I think
it's fine.
> === modified file 'lib/lp/ registry/ interfaces/ person. py' registry/ interfaces/ person. py 2010-03-05 14:50:47 +0000
> --- lib/lp/
> tokens = Attribute( _("Non- expired request tokens")) Reference( schema= ISSHKey) ))
> oauth_request_
>
> - sshkeys = Attribute(_('List of SSH keys'))
> + sshkeys = exported(
> + CollectionField(
> + title= _('List of SSH keys'),
> + readonly=False, required=False,
> + value_type=
Can we rename that to ssh_keys? Unfortunately, you can't use exported_as
because of bug 546324. I think there isn't that many call sites, but feel free
to push back if this is too daunting a task.
> === modified file 'lib/lp/ registry/ interfaces/ ssh.py' registry/ interfaces/ ssh.py 2009-06-25 04:06:00 +0000 registry/ interfaces/ ssh.py 2010-03-09 19:30:49 +0000 declarations import (export_ as_webservice_ entry, exported) _("Database ID"), required=True, readonly=True) as_webservice_ entry(' ssh_key' ) Int(title= _("Database ID"), required=True, readonly=True)) _("Owner" ), required=True, readonly=True)
> --- lib/lp/
> +++ lib/lp/
> @@ -16,6 +16,7 @@
> from zope.schema import Choice, Int, TextLine
> from zope.interface import Interface
> from lazr.enum import DBEnumeratedType, DBItem
> +from lazr.restful.
>
> from canonical.launchpad import _
>
> @@ -42,14 +43,18 @@
>
> class ISSHKey(Interface):
> """SSH public key"""
> - id = Int(title=
> +
> + export_
> +
> + id = exported(
> person = Int(title=
We don't want to export the DB id. It's not useful at all. I know it's leaked
into the URL, but that's an artefact.
> personID = Int(title=_('Owner ID'), required=True, readonly=True) SSHKeyType) title=_ ("Key text"), required=True) title=_ ("Comment describing this key"), Choice( title=_ ("Key type"), required=True, SSHKeyType, readonly=True)) TextLine( title=_ ("Key text"), required=True, TextLine( title=_ ("Comment describing this key"),
> - keytype = Choice(title=_("Key type"), required=True,
> - vocabulary=
> - keytext = TextLine(
> - comment = TextLine(
> - required=True)
> + keytype = exported(
> + vocabulary=
> + keytext = exported(
> + readonly=True))
> + comment = exported(
> + required=True, readonly=True))
> === modified file 'lib/lp/ registry/ stories/ webservice/ xx-person. txt'
> +== SSH keys === get("/~ name12" ).jsonBody( ) person[ 'sshkeys_ collection_ link'] .../~name12/ sshkeys link_of_ entries( webservice. get(sshkeys) .jsonBody( )) .../~name12/ +ssh-keys/ 1
> +
> +People have SSH keys which we can manipulate over the API.
> +
> +The sample person "name12" doesn't have any keys to begin with:
> +
> + >>> sample_person = webservice.
> + >>> sshkeys = sample_
> + >>> print sshkeys
> + http://
> + >>> print_self_
> + http://
It seems it has a key! (You say it doesn't) You should also ellide the DB id
in the URL.
You probably want to use no-priv here who shouldn't have any key to begin
with.
> + interfaces. person import IPersonSet IPersonSet) .getByName( 'name12' ) makeGPGKey( ssh_user)
> +Let's give "name12" a key via the back door of our internal Python APIs:
> +
> + >>> from zope.component import getUtility
> + >>> from lp.registry.
> + >>> login(ANONYMOUS)
> + >>> ssh_user = getUtility(
> + >>> ssh_key = factory.
You are creating a GPG key here, not a SSH key. (makeSSHKey is what you want
to use)
> + >>> logout() get(sshkeys) .jsonBody( ) link_of_ entries( keys) .../~name12/ +ssh-keys/ 1
> +
> +Now when we get the sshkey collection for 'name12' again, the key should show
> +up:
> +
> + >>> keys = webservice.
> + >>> print_self_
> + http://
> +
I would expect a new key here, not the one you showed previously.
> + entry(keys[ 'entries' ][0]) 3MAAAEBAPfhCA15 ZaT08brwVXwpJjc ZT6QFIipzF1sGy5 7HY7QPi/ W+uljr1VcCHzWdl Smda7YpTCTx0NFY YQIccQRGX6zYL8v 1w9FSRCAnxxUJmq EhsUDFYFdVTa9uL Crs3MSbmh7wwFPd RrGrO6X5x7T4dMZ QwykSZrOVdpLcCH RgrMZslLomIAjER n6OAQNiGFz7B2tE i/3Soqd52bGJwOt GymRiAXkPSLbH7K fzSCe34ytdh6BD+ 4SrgSoa+ TL3VDV70QAdlOFX D42ZHl3Sc0Tde4L bZeYq2Uf84DOATL ZBbOYpRSqTLkM9X ngpnvCRVb6dxEQf gODDw783tEuPpyS Lj2EAAAAVANpUVg ivDjt9gFibN/ AXfYy1meeBAAABA B6FtnMywmWZg2lr 2I3nDfE5U5QbGUQ B/ZEP98ZkSkhOcF 29VlnGOxyb2/ VZbVTLa/ btlPF82L4An/ c8VKtKZnel7LnAl MoArdgzQNXGVQQV tnaWwM26ydgDzkS SIes3elNZgsfnPR BvaF0ol9Tqju0rN GKjnr3ZOX/ NX+42bxpjRnxYj1 h56yP2jKKeGfjor I6JK1YfqBAiTxza DMzSpknnrbztaKJ oh7IFqMMOp9ANSF h7H106pEaCv3ebC TJZprtWqNKjb2zu m7OQPRz3upA0qx2 2ocTokjv4itXJ6y j/BvGu9qdOIQFXu B2rsFtLZtS8ATue Oly0GzyeiZBx/ AEAAAEBAO8jRYjL 7tAYnVlO1p6UzPO icAuGCFWfNbBEDR AXoSgLNdj451jSt w+eUc9ZVz7tG/ XRVZsiavtFHb2cb rcfX1YOd69xi0m+ IY6mo3yKt3irQRo kDtt376sHoUdHgj 2ozySZJgG8IJndt oS+VQQy6NdClA3f NFb96bF865eNaRY oHJO9ZI84lkWQL+ +MLzIuyFfCs1hSl apyyuHC8kFmF7AQ drVZvbohSbnWs+ w53nIW8nAA7z21w AukvE1Pl6AQyG0e 7U1sYS8Pc8dtmzJ vdtVZWBl02/ gqQJ7f06mFvnsN4 5rR1Uyxnrwl6rbF wqabZDlyD5Ac6Ic bvz9SG1gBOiI= ' .../#ssh_ key' .../~name12/ +ssh-keys/ 1'
> +And then we can actually retrieve the key:
> +
> + >>> pprint_
> + comment: u'andrew@trogdor'
> + id: 1
> + keytext: u'AAAAB3NzaC1kc
> + keytype: u'DSA'
> + resource_type_link: u'http://
> + self_link: u'http://
You'll want to ellide the DB id in the resulting URL. Probably also the
keytext which should be random. You probably want to modify the makeSSH
factory method to take a fixed comment field. That way you could show it in
the output.