File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -105,6 +105,27 @@ def test_key_hook(self):
105105 {'key' : public2 , 'fingerprint' : '43:fd:22:bc:dc:ca:6a:28:ba:71:4c:18:41:1d:d1:e2' }
106106 ]})
107107
108+ # Fetch a valid ssh key
109+ url = '/v2/hooks/key/54:6d:da:1f:91:b5:2b:6f:a2:83:90:c4:f9:73:76:f5'
110+ response = self .client .get (url , HTTP_X_DEIS_BUILDER_AUTH = settings .BUILDER_KEY )
111+ self .assertEqual (response .status_code , 200 )
112+ self .assertEqual (response .data , {
113+ "username" : str (self .user ),
114+ "apps" : [
115+ app_id
116+ ]
117+ })
118+
119+ # Fetch an non-existent base64 encoded ssh key
120+ url = '/v2/hooks/key/54:6d:da:1f:91:b5:2b:6f:a2:83:90:c4:f9:73:76:wooooo'
121+ response = self .client .get (url , HTTP_X_DEIS_BUILDER_AUTH = settings .BUILDER_KEY )
122+ self .assertEqual (response .status_code , 404 )
123+
124+ # Fetch an invalid (not encoded) ssh key
125+ url = '/v2/hooks/key/nope'
126+ response = self .client .get (url , HTTP_X_DEIS_BUILDER_AUTH = settings .BUILDER_KEY )
127+ self .assertEqual (response .status_code , 404 )
128+
108129 def test_push_hook (self ):
109130 """Test creating a Push via the API"""
110131 url = '/v2/apps'
Original file line number Diff line number Diff line change 7676 views .KeyHookViewSet .as_view ({'get' : 'users' })),
7777 url (r'^hooks/keys/(?P<id>{})/?' .format (settings .APP_URL_REGEX ),
7878 views .KeyHookViewSet .as_view ({'get' : 'app' })),
79+ url (r'^hooks/key/(?P<fingerprint>.+)/?' ,
80+ views .KeyHookViewSet .as_view ({'get' : 'public_key' })),
7981 url (r'^hooks/push/?' ,
8082 views .PushHookViewSet .as_view ({'post' : 'create' })),
8183 url (r'^hooks/build/?' ,
Original file line number Diff line number Diff line change @@ -427,6 +427,25 @@ class KeyHookViewSet(BaseHookViewSet):
427427 model = models .Key
428428 serializer_class = serializers .KeySerializer
429429
430+ def public_key (self , request , * args , ** kwargs ):
431+ fingerprint = kwargs ['fingerprint' ].strip ()
432+ key = get_object_or_404 (models .Key , fingerprint = fingerprint )
433+
434+ queryset = models .App .objects .all () | \
435+ get_objects_for_user (self .request .user , 'api.use_app' )
436+ items = self .filter_queryset (queryset )
437+
438+ apps = []
439+ for item in items :
440+ apps .append (item .id )
441+
442+ data = {
443+ 'username' : key .owner .username ,
444+ 'apps' : apps
445+ }
446+
447+ return Response (data , status = status .HTTP_200_OK )
448+
430449 def app (self , request , * args , ** kwargs ):
431450 app = get_object_or_404 (models .App , id = kwargs ['id' ])
432451
You can’t perform that action at this time.
0 commit comments