{"action":"created","comment":{"url":"https://api.github.com/repos/cozy/cozy-keys-browser/pulls/comments/354438570","pull_request_review_id":327709290,"id":354438570,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDM1NDQzODU3MA==","diff_hunk":"@@ -0,0 +1,102 @@\n+import { Registry } from 'cozy-client';\n+import { CipherService } from 'jslib/abstractions/cipher.service';\n+import { Utils } from 'jslib/misc/utils';\n+import { CipherView } from 'jslib/models/view/cipherView';\n+import { CozyClientService } from './cozyClient.service';\n+\n+export class KonnectorsService {\n+    constructor(private cipherService: CipherService, protected cozyClientService: CozyClientService) {\n+    }\n+\n+    /**\n+     *  Create konnector's suggestion based on the available konnectors and ciphers.\n+     *\n+     *  On a privacy note, this discloses to the server which services having an associated konnector\n+     *  exist in the vault. Knowing that the konnector itself is not considered as secret\n+     *  on the server, we consider it as acceptable.\n+     */\n+    async createSuggestions() {\n+        const cozyClient = await this.cozyClientService.createClient();\n+        const allKonnectors = await this.getRegistryKonnectors(cozyClient);\n+        const installedKonnectors = await this.getInstalledKonnectors(cozyClient);\n+        const suggestedKonnectors = await this.getSuggestedKonnectors(cozyClient);\n+        const ciphers = await this.cipherService.getAllDecrypted();\n+        const suggested = await this.suggestedKonnectorsFromCiphers(\n+            allKonnectors, installedKonnectors, suggestedKonnectors, ciphers);\n+        await this.sendKonnectorsSuggestion(cozyClient, suggested);\n+    }\n+\n+    async getRegistryKonnectors(client: any) {\n+        const registry = new Registry({client: client});\n+        return registry.fetchApps({channel: 'stable', type: 'konnector'});\n+    }\n+\n+    async getInstalledKonnectors(client: any) {\n+        const konnectors = await client.query(client.find('io.cozy.konnectors'));\n+        return konnectors ? konnectors.data : null;\n+    }\n+\n+    async getSuggestedKonnectors(client: any) {\n+        const suggestions = await client.query(client.find('io.cozy.apps.suggestions'));\n+        return suggestions ? suggestions.data : null;\n+    }\n+\n+    async sendKonnectorsSuggestion(client: any, konnectors: any[]) {\n+        const creationPromises = konnectors.map((konnector) => {\n+            const suggested = {\n+                slug: konnector.slug,\n+                silenced: false,\n+                reason: {\n+                    code: 'FOUND_CIPHER',\n+                },\n+            };\n+            return client.create('io.cozy.apps.suggestions', suggested);\n+        });\n+        await Promise.all(creationPromises);\n+    }\n+\n+    removeWWW(hostname: string): string {\n+        const split = hostname.split('www.');\n+        return split.length > 1 ? split[1] : split[0];\n+    }\n+\n+    hasMatchingCipher(konnector: any, ciphers: CipherView[]): boolean {\n+        return ciphers.some((cipher) => {","path":"src/popup/services/konnectors.service.ts","position":64,"original_position":64,"commit_id":"7df70610da101e09021b897de1250727238a7d1d","original_commit_id":"7df70610da101e09021b897de1250727238a7d1d","user":{"login":"edas","id":15271,"node_id":"MDQ6VXNlcjE1Mjcx","avatar_url":"https://avatars0.githubusercontent.com/u/15271?v=4","gravatar_id":"","url":"https://api.github.com/users/edas","html_url":"https://github.com/edas","followers_url":"https://api.github.com/users/edas/followers","following_url":"https://api.github.com/users/edas/following{/other_user}","gists_url":"https://api.github.com/users/edas/gists{/gist_id}","starred_url":"https://api.github.com/users/edas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edas/subscriptions","organizations_url":"https://api.github.com/users/edas/orgs","repos_url":"https://api.github.com/users/edas/repos","events_url":"https://api.github.com/users/edas/events{/privacy}","received_events_url":"https://api.github.com/users/edas/received_events","type":"User","site_admin":false},"body":"La double boucle me parait difficilement une bonne solution.\r\n\r\nTu peux d'un côté construire tes URLs de connecteurs, de l'autre construire tes url de cipher, et faire un diff.\r\nÀ défaut tu peux utiliser un objet (hashmap) avec qui sera peut-être plus rapide qu'un parcours du gros tableau de tous les connecteurs.","created_at":"2019-12-05T17:08:55Z","updated_at":"2019-12-05T17:13:39Z","html_url":"https://github.com/cozy/cozy-keys-browser/pull/24#discussion_r354438570","pull_request_url":"https://api.github.com/repos/cozy/cozy-keys-browser/pulls/24","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/cozy/cozy-keys-browser/pulls/comments/354438570"},"html":{"href":"https://github.com/cozy/cozy-keys-browser/pull/24#discussion_r354438570"},"pull_request":{"href":"https://api.github.com/repos/cozy/cozy-keys-browser/pulls/24"}}},"pull_request":{"url":"https://api.github.com/repos/cozy/cozy-keys-browser/pulls/24","id":349530025,"node_id":"MDExOlB1bGxSZXF1ZXN0MzQ5NTMwMDI1","html_url":"https://github.com/cozy/cozy-keys-browser/pull/24","diff_url":"https://github.com/cozy/cozy-keys-browser/pull/24.diff","patch_url":"https://github.com/cozy/cozy-keys-browser/pull/24.patch","issue_url":"https://api.github.com/repos/cozy/cozy-keys-browser/issues/24","number":24,"state":"open","locked":false,"title":"[WIP] Add Konnector suggestion","user":{"login":"Gara64","id":7010087,"node_id":"MDQ6VXNlcjcwMTAwODc=","avatar_url":"https://avatars2.githubusercontent.com/u/7010087?v=4","gravatar_id":"","url":"https://api.github.com/users/Gara64","html_url":"https://github.com/Gara64","followers_url":"https://api.github.com/users/Gara64/followers","following_url":"https://api.github.com/users/Gara64/following{/other_user}","gists_url":"https://api.github.com/users/Gara64/gists{/gist_id}","starred_url":"https://api.github.com/users/Gara64/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gara64/subscriptions","organizations_url":"https://api.github.com/users/Gara64/orgs","repos_url":"https://api.github.com/users/Gara64/repos","events_url":"https://api.github.com/users/Gara64/events{/privacy}","received_events_url":"https://api.github.com/users/Gara64/received_events","type":"User","site_admin":false},"body":"This PR:\r\n* Add cozy-client into the extension\r\n* Add the capacity to create konnectors' suggestions based on the ciphers\r\n* Add some unit tests\r\n\r\nMy main interrogation is about the location of the suggestion check: here, it is called after a cipher is added, from the popup notification, and when the user clicks on the \"current-tab\", i.e. open the extension.\r\nThe later is aimed to be opportunistic and greedily check whenever a suggestion could be made. This is done asynchronously, but already takes ~300ms on my local tests with few ciphers.\r\nI'm not sure about the performances/efficiency compromise here, so I'm open to suggestions.","created_at":"2019-12-05T16:29:07Z","updated_at":"2019-12-05T17:13:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"399e6ad55cd70101f6c2887b81b06ddfca5e45e7","assignee":null,"assignees":[],"requested_reviewers":[{"login":"y-lohse","id":2261445,"node_id":"MDQ6VXNlcjIyNjE0NDU=","avatar_url":"https://avatars2.githubusercontent.com/u/2261445?v=4","gravatar_id":"","url":"https://api.github.com/users/y-lohse","html_url":"https://github.com/y-lohse","followers_url":"https://api.github.com/users/y-lohse/followers","following_url":"https://api.github.com/users/y-lohse/following{/other_user}","gists_url":"https://api.github.com/users/y-lohse/gists{/gist_id}","starred_url":"https://api.github.com/users/y-lohse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/y-lohse/subscriptions","organizations_url":"https://api.github.com/users/y-lohse/orgs","repos_url":"https://api.github.com/users/y-lohse/repos","events_url":"https://api.github.com/users/y-lohse/events{/privacy}","received_events_url":"https://api.github.com/users/y-lohse/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/cozy/cozy-keys-browser/pulls/24/commits","review_comments_url":"https://api.github.com/repos/cozy/cozy-keys-browser/pulls/24/comments","review_comment_url":"https://api.github.com/repos/cozy/cozy-keys-browser/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cozy/cozy-keys-browser/issues/24/comments","statuses_url":"https://api.github.com/repos/cozy/cozy-keys-browser/statuses/7df70610da101e09021b897de1250727238a7d1d","head":{"label":"Gara64:konnector-suggestion","ref":"konnector-suggestion","sha":"7df70610da101e09021b897de1250727238a7d1d","user":{"login":"Gara64","id":7010087,"node_id":"MDQ6VXNlcjcwMTAwODc=","avatar_url":"https://avatars2.githubusercontent.com/u/7010087?v=4","gravatar_id":"","url":"https://api.github.com/users/Gara64","html_url":"https://github.com/Gara64","followers_url":"https://api.github.com/users/Gara64/followers","following_url":"https://api.github.com/users/Gara64/following{/other_user}","gists_url":"https://api.github.com/users/Gara64/gists{/gist_id}","starred_url":"https://api.github.com/users/Gara64/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gara64/subscriptions","organizations_url":"https://api.github.com/users/Gara64/orgs","repos_url":"https://api.github.com/users/Gara64/repos","events_url":"https://api.github.com/users/Gara64/events{/privacy}","received_events_url":"https://api.github.com/users/Gara64/received_events","type":"User","site_admin":false},"repo":{"id":219746829,"node_id":"MDEwOlJlcG9zaXRvcnkyMTk3NDY4Mjk=","name":"cozy-keys-browser","full_name":"Gara64/cozy-keys-browser","private":false,"owner":{"login":"Gara64","id":7010087,"node_id":"MDQ6VXNlcjcwMTAwODc=","avatar_url":"https://avatars2.githubusercontent.com/u/7010087?v=4","gravatar_id":"","url":"https://api.github.com/users/Gara64","html_url":"https://github.com/Gara64","followers_url":"https://api.github.com/users/Gara64/followers","following_url":"https://api.github.com/users/Gara64/following{/other_user}","gists_url":"https://api.github.com/users/Gara64/gists{/gist_id}","starred_url":"https://api.github.com/users/Gara64/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gara64/subscriptions","organizations_url":"https://api.github.com/users/Gara64/orgs","repos_url":"https://api.github.com/users/Gara64/repos","events_url":"https://api.github.com/users/Gara64/events{/privacy}","received_events_url":"https://api.github.com/users/Gara64/received_events","type":"User","site_admin":false},"html_url":"https://github.com/Gara64/cozy-keys-browser","description":"The cozy-keys extension vault (Chrome, Firefox, Opera, Edge, Safari, & more), based on Bitwarden","fork":true,"url":"https://api.github.com/repos/Gara64/cozy-keys-browser","forks_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/forks","keys_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/teams","hooks_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/hooks","issue_events_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/issues/events{/number}","events_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/events","assignees_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/assignees{/user}","branches_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/branches{/branch}","tags_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/tags","blobs_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/git/refs{/sha}","trees_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/statuses/{sha}","languages_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/languages","stargazers_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/stargazers","contributors_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/contributors","subscribers_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/subscribers","subscription_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/subscription","commits_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/commits{/sha}","git_commits_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/git/commits{/sha}","comments_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/comments{/number}","issue_comment_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/issues/comments{/number}","contents_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/contents/{+path}","compare_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/merges","archive_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/downloads","issues_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/issues{/number}","pulls_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/pulls{/number}","milestones_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/milestones{/number}","notifications_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/labels{/name}","releases_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/releases{/id}","deployments_url":"https://api.github.com/repos/Gara64/cozy-keys-browser/deployments","created_at":"2019-11-05T13:04:47Z","updated_at":"2019-11-05T13:04:51Z","pushed_at":"2019-12-05T16:51:24Z","git_url":"git://github.com/Gara64/cozy-keys-browser.git","ssh_url":"git@github.com:Gara64/cozy-keys-browser.git","clone_url":"https://github.com/Gara64/cozy-keys-browser.git","svn_url":"https://github.com/Gara64/cozy-keys-browser","homepage":"","size":12744,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"cozy:master","ref":"master","sha":"0b5973694cbab14215b3c72a99448314446407f6","user":{"login":"cozy","id":7690525,"node_id":"MDEyOk9yZ2FuaXphdGlvbjc2OTA1MjU=","avatar_url":"https://avatars0.githubusercontent.com/u/7690525?v=4","gravatar_id":"","url":"https://api.github.com/users/cozy","html_url":"https://github.com/cozy","followers_url":"https://api.github.com/users/cozy/followers","following_url":"https://api.github.com/users/cozy/following{/other_user}","gists_url":"https://api.github.com/users/cozy/gists{/gist_id}","starred_url":"https://api.github.com/users/cozy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cozy/subscriptions","organizations_url":"https://api.github.com/users/cozy/orgs","repos_url":"https://api.github.com/users/cozy/repos","events_url":"https://api.github.com/users/cozy/events{/privacy}","received_events_url":"https://api.github.com/users/cozy/received_events","type":"Organization","site_admin":false},"repo":{"id":219518988,"node_id":"MDEwOlJlcG9zaXRvcnkyMTk1MTg5ODg=","name":"cozy-keys-browser","full_name":"cozy/cozy-keys-browser","private":false,"owner":{"login":"cozy","id":7690525,"node_id":"MDEyOk9yZ2FuaXphdGlvbjc2OTA1MjU=","avatar_url":"https://avatars0.githubusercontent.com/u/7690525?v=4","gravatar_id":"","url":"https://api.github.com/users/cozy","html_url":"https://github.com/cozy","followers_url":"https://api.github.com/users/cozy/followers","following_url":"https://api.github.com/users/cozy/following{/other_user}","gists_url":"https://api.github.com/users/cozy/gists{/gist_id}","starred_url":"https://api.github.com/users/cozy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cozy/subscriptions","organizations_url":"https://api.github.com/users/cozy/orgs","repos_url":"https://api.github.com/users/cozy/repos","events_url":"https://api.github.com/users/cozy/events{/privacy}","received_events_url":"https://api.github.com/users/cozy/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/cozy/cozy-keys-browser","description":"The cozy-keys extension vault (Chrome, Firefox, Opera, Edge, Safari, & more), based on Bitwarden","fork":true,"url":"https://api.github.com/repos/cozy/cozy-keys-browser","forks_url":"https://api.github.com/repos/cozy/cozy-keys-browser/forks","keys_url":"https://api.github.com/repos/cozy/cozy-keys-browser/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cozy/cozy-keys-browser/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cozy/cozy-keys-browser/teams","hooks_url":"https://api.github.com/repos/cozy/cozy-keys-browser/hooks","issue_events_url":"https://api.github.com/repos/cozy/cozy-keys-browser/issues/events{/number}","events_url":"https://api.github.com/repos/cozy/cozy-keys-browser/events","assignees_url":"https://api.github.com/repos/cozy/cozy-keys-browser/assignees{/user}","branches_url":"https://api.github.com/repos/cozy/cozy-keys-browser/branches{/branch}","tags_url":"https://api.github.com/repos/cozy/cozy-keys-browser/tags","blobs_url":"https://api.github.com/repos/cozy/cozy-keys-browser/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cozy/cozy-keys-browser/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cozy/cozy-keys-browser/git/refs{/sha}","trees_url":"https://api.github.com/repos/cozy/cozy-keys-browser/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cozy/cozy-keys-browser/statuses/{sha}","languages_url":"https://api.github.com/repos/cozy/cozy-keys-browser/languages","stargazers_url":"https://api.github.com/repos/cozy/cozy-keys-browser/stargazers","contributors_url":"https://api.github.com/repos/cozy/cozy-keys-browser/contributors","subscribers_url":"https://api.github.com/repos/cozy/cozy-keys-browser/subscribers","subscription_url":"https://api.github.com/repos/cozy/cozy-keys-browser/subscription","commits_url":"https://api.github.com/repos/cozy/cozy-keys-browser/commits{/sha}","git_commits_url":"https://api.github.com/repos/cozy/cozy-keys-browser/git/commits{/sha}","comments_url":"https://api.github.com/repos/cozy/cozy-keys-browser/comments{/number}","issue_comment_url":"https://api.github.com/repos/cozy/cozy-keys-browser/issues/comments{/number}","contents_url":"https://api.github.com/repos/cozy/cozy-keys-browser/contents/{+path}","compare_url":"https://api.github.com/repos/cozy/cozy-keys-browser/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cozy/cozy-keys-browser/merges","archive_url":"https://api.github.com/repos/cozy/cozy-keys-browser/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cozy/cozy-keys-browser/downloads","issues_url":"https://api.github.com/repos/cozy/cozy-keys-browser/issues{/number}","pulls_url":"https://api.github.com/repos/cozy/cozy-keys-browser/pulls{/number}","milestones_url":"https://api.github.com/repos/cozy/cozy-keys-browser/milestones{/number}","notifications_url":"https://api.github.com/repos/cozy/cozy-keys-browser/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cozy/cozy-keys-browser/labels{/name}","releases_url":"https://api.github.com/repos/cozy/cozy-keys-browser/releases{/id}","deployments_url":"https://api.github.com/repos/cozy/cozy-keys-browser/deployments","created_at":"2019-11-04T14:20:22Z","updated_at":"2019-12-05T16:48:26Z","pushed_at":"2019-12-05T16:51:26Z","git_url":"git://github.com/cozy/cozy-keys-browser.git","ssh_url":"git@github.com:cozy/cozy-keys-browser.git","clone_url":"https://github.com/cozy/cozy-keys-browser.git","svn_url":"https://github.com/cozy/cozy-keys-browser","homepage":"","size":12709,"stargazers_count":0,"watchers_count":0,"language":"TypeScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cozy/cozy-keys-browser/pulls/24"},"html":{"href":"https://github.com/cozy/cozy-keys-browser/pull/24"},"issue":{"href":"https://api.github.com/repos/cozy/cozy-keys-browser/issues/24"},"comments":{"href":"https://api.github.com/repos/cozy/cozy-keys-browser/issues/24/comments"},"review_comments":{"href":"https://api.github.com/repos/cozy/cozy-keys-browser/pulls/24/comments"},"review_comment":{"href":"https://api.github.com/repos/cozy/cozy-keys-browser/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cozy/cozy-keys-browser/pulls/24/commits"},"statuses":{"href":"https://api.github.com/repos/cozy/cozy-keys-browser/statuses/7df70610da101e09021b897de1250727238a7d1d"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"edas"}}