{"action":"created","comment":{"url":"https://api.github.com/repos/lookout/borderpatrol/pulls/comments/42809469","id":42809469,"diff_hunk":"@@ -46,5 +58,197 @@ object SecretStores {\n       else if (f(previous)) Some(previous)\n       else None\n   }\n+  /**\n+  *A store to access the current and previous [[com.lookout.borderpatrol.sessionx.Secret]] stored in the consul server.\n+  * It will use a in memory cache before making a request to the server\n+  *\n+  *@param consul An instance of [[com.lookout.borderpatrol.sessionx.ConsulConnection]] to make requests to the\n+  *consul server\n+  *@param poll How often in seconds to check for updated Secrets on the consul server\n+  **/\n+  case class ConsulSecretStore(consul: ConsulConnection ,poll: Int) extends SecretStoreApi {\n+    val cache = ConsulSecretCache(poll,consul)\n+    new Thread( cache ).start\n+    /**\n+    *Get the current secret from the cache layer\n+    **/\n+     def current: Secret = {\n+      cache.secrets.current\n+    }\n+    /**\n+    *Get the previous secret from the cache layer\n+    **/\n+    def previous: Secret = {\n+      cache.secrets.previous\n+    }\n+    /**\n+    *Look for the Secret being checked in the function. Checks if this exists in the cache layer\n+    *If it is found only existing in consul and not in current or previous a cache rotation will be triggered\n+    *Returning None suggests the servers are extremely out of sync with each other or the connection to consul has\n+    *failed\n+    **/\n+    def find(f: Secret => Boolean): Option[Secret] = {\n+      cache.find(f)\n+    }\n+  }\n+  /**\n+  *Stores the secrets stored on the consul server.\n+  *Polls the consul server and keeps an inmemory cache of Secrets\n+  *\n+  *@param poll How often in seconds to check for updates\n+  *@param consul An instance on ConsulConnection to make connections with the consul server\n+  **/\n+  case class ConsulSecretCache(poll: Int, consul: ConsulConnection) extends Runnable  {\n+    val cacheBuffer= collection.mutable.ArrayBuffer[Secrets]( Secrets(Secret(),Secret()) )\n+    var newBuffer = collection.mutable.ArrayBuffer[Secret]()\n+    /**\n+    *Checks if the current secret is expired and if there is a new secret available and rotates the secrets.\n+    *Then returns the latest secret\n+    **/\n+    def secrets: Secrets ={\n+      val s = cacheBuffer.last\n+      if(s.current.expired && newBuffer.last != s.current) {rotateSecret; cacheBuffer.last}\n+      else s\n+    }\n+    /**\n+    *Checks if the secret is knows. Rotates if the secret is the new secret.\n+    **/\n+    def find(f: Secret=>Boolean): Option[Secret] = {","path":"core/src/main/scala/com/lookout/borderpatrol/sessionx/SecretStores.scala","position":85,"original_position":77,"commit_id":"be2d3a3bfffb10684a40146b1acdcc3fa68f5436","original_commit_id":"04465a8e3841bdd81186f41b50b46a804b16d0e6","user":{"login":"tejom","id":7831521,"avatar_url":"https://avatars.githubusercontent.com/u/7831521?v=3","gravatar_id":"","url":"https://api.github.com/users/tejom","html_url":"https://github.com/tejom","followers_url":"https://api.github.com/users/tejom/followers","following_url":"https://api.github.com/users/tejom/following{/other_user}","gists_url":"https://api.github.com/users/tejom/gists{/gist_id}","starred_url":"https://api.github.com/users/tejom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tejom/subscriptions","organizations_url":"https://api.github.com/users/tejom/orgs","repos_url":"https://api.github.com/users/tejom/repos","events_url":"https://api.github.com/users/tejom/events{/privacy}","received_events_url":"https://api.github.com/users/tejom/received_events","type":"User","site_admin":false},"body":"These should be taken care of with the `this.synchronized` . Some of the alternatives for concurrency seem like overkill like bringing in akka actors. Rotate is the only method that will write to the array so the block should prevent anything else from writing to it. ","created_at":"2015-10-22T21:35:00Z","updated_at":"2015-10-22T21:35:00Z","html_url":"https://github.com/lookout/borderpatrol/pull/76#discussion_r42809469","pull_request_url":"https://api.github.com/repos/lookout/borderpatrol/pulls/76","_links":{"self":{"href":"https://api.github.com/repos/lookout/borderpatrol/pulls/comments/42809469"},"html":{"href":"https://github.com/lookout/borderpatrol/pull/76#discussion_r42809469"},"pull_request":{"href":"https://api.github.com/repos/lookout/borderpatrol/pulls/76"}}},"pull_request":{"url":"https://api.github.com/repos/lookout/borderpatrol/pulls/76","id":47328727,"html_url":"https://github.com/lookout/borderpatrol/pull/76","diff_url":"https://github.com/lookout/borderpatrol/pull/76.diff","patch_url":"https://github.com/lookout/borderpatrol/pull/76.patch","issue_url":"https://api.github.com/repos/lookout/borderpatrol/issues/76","number":76,"state":"open","locked":false,"title":"Consul secretapi","user":{"login":"tejom","id":7831521,"avatar_url":"https://avatars.githubusercontent.com/u/7831521?v=3","gravatar_id":"","url":"https://api.github.com/users/tejom","html_url":"https://github.com/tejom","followers_url":"https://api.github.com/users/tejom/followers","following_url":"https://api.github.com/users/tejom/following{/other_user}","gists_url":"https://api.github.com/users/tejom/gists{/gist_id}","starred_url":"https://api.github.com/users/tejom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tejom/subscriptions","organizations_url":"https://api.github.com/users/tejom/orgs","repos_url":"https://api.github.com/users/tejom/repos","events_url":"https://api.github.com/users/tejom/events{/privacy}","received_events_url":"https://api.github.com/users/tejom/received_events","type":"User","site_admin":false},"body":"For issue #40 ","created_at":"2015-10-09T22:59:54Z","updated_at":"2015-10-22T21:35:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4db8d325a3d21b04a8780c0df309cfc18d62fb4d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/lookout/borderpatrol/pulls/76/commits","review_comments_url":"https://api.github.com/repos/lookout/borderpatrol/pulls/76/comments","review_comment_url":"https://api.github.com/repos/lookout/borderpatrol/pulls/comments{/number}","comments_url":"https://api.github.com/repos/lookout/borderpatrol/issues/76/comments","statuses_url":"https://api.github.com/repos/lookout/borderpatrol/statuses/be2d3a3bfffb10684a40146b1acdcc3fa68f5436","head":{"label":"tejom:consul-secretapi","ref":"consul-secretapi","sha":"be2d3a3bfffb10684a40146b1acdcc3fa68f5436","user":{"login":"tejom","id":7831521,"avatar_url":"https://avatars.githubusercontent.com/u/7831521?v=3","gravatar_id":"","url":"https://api.github.com/users/tejom","html_url":"https://github.com/tejom","followers_url":"https://api.github.com/users/tejom/followers","following_url":"https://api.github.com/users/tejom/following{/other_user}","gists_url":"https://api.github.com/users/tejom/gists{/gist_id}","starred_url":"https://api.github.com/users/tejom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tejom/subscriptions","organizations_url":"https://api.github.com/users/tejom/orgs","repos_url":"https://api.github.com/users/tejom/repos","events_url":"https://api.github.com/users/tejom/events{/privacy}","received_events_url":"https://api.github.com/users/tejom/received_events","type":"User","site_admin":false},"repo":{"id":43192165,"name":"borderpatrol","full_name":"tejom/borderpatrol","owner":{"login":"tejom","id":7831521,"avatar_url":"https://avatars.githubusercontent.com/u/7831521?v=3","gravatar_id":"","url":"https://api.github.com/users/tejom","html_url":"https://github.com/tejom","followers_url":"https://api.github.com/users/tejom/followers","following_url":"https://api.github.com/users/tejom/following{/other_user}","gists_url":"https://api.github.com/users/tejom/gists{/gist_id}","starred_url":"https://api.github.com/users/tejom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tejom/subscriptions","organizations_url":"https://api.github.com/users/tejom/orgs","repos_url":"https://api.github.com/users/tejom/repos","events_url":"https://api.github.com/users/tejom/events{/privacy}","received_events_url":"https://api.github.com/users/tejom/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tejom/borderpatrol","description":"Functional library for web sessions and authentication in an SOA","fork":true,"url":"https://api.github.com/repos/tejom/borderpatrol","forks_url":"https://api.github.com/repos/tejom/borderpatrol/forks","keys_url":"https://api.github.com/repos/tejom/borderpatrol/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tejom/borderpatrol/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tejom/borderpatrol/teams","hooks_url":"https://api.github.com/repos/tejom/borderpatrol/hooks","issue_events_url":"https://api.github.com/repos/tejom/borderpatrol/issues/events{/number}","events_url":"https://api.github.com/repos/tejom/borderpatrol/events","assignees_url":"https://api.github.com/repos/tejom/borderpatrol/assignees{/user}","branches_url":"https://api.github.com/repos/tejom/borderpatrol/branches{/branch}","tags_url":"https://api.github.com/repos/tejom/borderpatrol/tags","blobs_url":"https://api.github.com/repos/tejom/borderpatrol/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tejom/borderpatrol/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tejom/borderpatrol/git/refs{/sha}","trees_url":"https://api.github.com/repos/tejom/borderpatrol/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tejom/borderpatrol/statuses/{sha}","languages_url":"https://api.github.com/repos/tejom/borderpatrol/languages","stargazers_url":"https://api.github.com/repos/tejom/borderpatrol/stargazers","contributors_url":"https://api.github.com/repos/tejom/borderpatrol/contributors","subscribers_url":"https://api.github.com/repos/tejom/borderpatrol/subscribers","subscription_url":"https://api.github.com/repos/tejom/borderpatrol/subscription","commits_url":"https://api.github.com/repos/tejom/borderpatrol/commits{/sha}","git_commits_url":"https://api.github.com/repos/tejom/borderpatrol/git/commits{/sha}","comments_url":"https://api.github.com/repos/tejom/borderpatrol/comments{/number}","issue_comment_url":"https://api.github.com/repos/tejom/borderpatrol/issues/comments{/number}","contents_url":"https://api.github.com/repos/tejom/borderpatrol/contents/{+path}","compare_url":"https://api.github.com/repos/tejom/borderpatrol/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tejom/borderpatrol/merges","archive_url":"https://api.github.com/repos/tejom/borderpatrol/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tejom/borderpatrol/downloads","issues_url":"https://api.github.com/repos/tejom/borderpatrol/issues{/number}","pulls_url":"https://api.github.com/repos/tejom/borderpatrol/pulls{/number}","milestones_url":"https://api.github.com/repos/tejom/borderpatrol/milestones{/number}","notifications_url":"https://api.github.com/repos/tejom/borderpatrol/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tejom/borderpatrol/labels{/name}","releases_url":"https://api.github.com/repos/tejom/borderpatrol/releases{/id}","created_at":"2015-09-26T04:38:24Z","updated_at":"2015-09-26T04:38:25Z","pushed_at":"2015-10-22T18:48:11Z","git_url":"git://github.com/tejom/borderpatrol.git","ssh_url":"git@github.com:tejom/borderpatrol.git","clone_url":"https://github.com/tejom/borderpatrol.git","svn_url":"https://github.com/tejom/borderpatrol","homepage":"http://hackers.lookout.com/2014/06/introducing-borderpatrol/","size":1078,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"lookout:master","ref":"master","sha":"1889f765fb160245483ecd1b313b1cc6e0cdb1c2","user":{"login":"lookout","id":47237,"avatar_url":"https://avatars.githubusercontent.com/u/47237?v=3","gravatar_id":"","url":"https://api.github.com/users/lookout","html_url":"https://github.com/lookout","followers_url":"https://api.github.com/users/lookout/followers","following_url":"https://api.github.com/users/lookout/following{/other_user}","gists_url":"https://api.github.com/users/lookout/gists{/gist_id}","starred_url":"https://api.github.com/users/lookout/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lookout/subscriptions","organizations_url":"https://api.github.com/users/lookout/orgs","repos_url":"https://api.github.com/users/lookout/repos","events_url":"https://api.github.com/users/lookout/events{/privacy}","received_events_url":"https://api.github.com/users/lookout/received_events","type":"Organization","site_admin":false},"repo":{"id":20500575,"name":"borderpatrol","full_name":"lookout/borderpatrol","owner":{"login":"lookout","id":47237,"avatar_url":"https://avatars.githubusercontent.com/u/47237?v=3","gravatar_id":"","url":"https://api.github.com/users/lookout","html_url":"https://github.com/lookout","followers_url":"https://api.github.com/users/lookout/followers","following_url":"https://api.github.com/users/lookout/following{/other_user}","gists_url":"https://api.github.com/users/lookout/gists{/gist_id}","starred_url":"https://api.github.com/users/lookout/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lookout/subscriptions","organizations_url":"https://api.github.com/users/lookout/orgs","repos_url":"https://api.github.com/users/lookout/repos","events_url":"https://api.github.com/users/lookout/events{/privacy}","received_events_url":"https://api.github.com/users/lookout/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lookout/borderpatrol","description":"Functional library for web sessions and authentication in an SOA","fork":false,"url":"https://api.github.com/repos/lookout/borderpatrol","forks_url":"https://api.github.com/repos/lookout/borderpatrol/forks","keys_url":"https://api.github.com/repos/lookout/borderpatrol/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lookout/borderpatrol/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lookout/borderpatrol/teams","hooks_url":"https://api.github.com/repos/lookout/borderpatrol/hooks","issue_events_url":"https://api.github.com/repos/lookout/borderpatrol/issues/events{/number}","events_url":"https://api.github.com/repos/lookout/borderpatrol/events","assignees_url":"https://api.github.com/repos/lookout/borderpatrol/assignees{/user}","branches_url":"https://api.github.com/repos/lookout/borderpatrol/branches{/branch}","tags_url":"https://api.github.com/repos/lookout/borderpatrol/tags","blobs_url":"https://api.github.com/repos/lookout/borderpatrol/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lookout/borderpatrol/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lookout/borderpatrol/git/refs{/sha}","trees_url":"https://api.github.com/repos/lookout/borderpatrol/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lookout/borderpatrol/statuses/{sha}","languages_url":"https://api.github.com/repos/lookout/borderpatrol/languages","stargazers_url":"https://api.github.com/repos/lookout/borderpatrol/stargazers","contributors_url":"https://api.github.com/repos/lookout/borderpatrol/contributors","subscribers_url":"https://api.github.com/repos/lookout/borderpatrol/subscribers","subscription_url":"https://api.github.com/repos/lookout/borderpatrol/subscription","commits_url":"https://api.github.com/repos/lookout/borderpatrol/commits{/sha}","git_commits_url":"https://api.github.com/repos/lookout/borderpatrol/git/commits{/sha}","comments_url":"https://api.github.com/repos/lookout/borderpatrol/comments{/number}","issue_comment_url":"https://api.github.com/repos/lookout/borderpatrol/issues/comments{/number}","contents_url":"https://api.github.com/repos/lookout/borderpatrol/contents/{+path}","compare_url":"https://api.github.com/repos/lookout/borderpatrol/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lookout/borderpatrol/merges","archive_url":"https://api.github.com/repos/lookout/borderpatrol/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lookout/borderpatrol/downloads","issues_url":"https://api.github.com/repos/lookout/borderpatrol/issues{/number}","pulls_url":"https://api.github.com/repos/lookout/borderpatrol/pulls{/number}","milestones_url":"https://api.github.com/repos/lookout/borderpatrol/milestones{/number}","notifications_url":"https://api.github.com/repos/lookout/borderpatrol/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lookout/borderpatrol/labels{/name}","releases_url":"https://api.github.com/repos/lookout/borderpatrol/releases{/id}","created_at":"2014-06-04T21:00:49Z","updated_at":"2015-10-01T14:12:52Z","pushed_at":"2015-10-22T18:48:11Z","git_url":"git://github.com/lookout/borderpatrol.git","ssh_url":"git@github.com:lookout/borderpatrol.git","clone_url":"https://github.com/lookout/borderpatrol.git","svn_url":"https://github.com/lookout/borderpatrol","homepage":"http://hackers.lookout.com/2014/06/introducing-borderpatrol/","size":1659,"stargazers_count":15,"watchers_count":15,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":11,"mirror_url":null,"open_issues_count":27,"forks":11,"open_issues":27,"watchers":15,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/lookout/borderpatrol/pulls/76"},"html":{"href":"https://github.com/lookout/borderpatrol/pull/76"},"issue":{"href":"https://api.github.com/repos/lookout/borderpatrol/issues/76"},"comments":{"href":"https://api.github.com/repos/lookout/borderpatrol/issues/76/comments"},"review_comments":{"href":"https://api.github.com/repos/lookout/borderpatrol/pulls/76/comments"},"review_comment":{"href":"https://api.github.com/repos/lookout/borderpatrol/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/lookout/borderpatrol/pulls/76/commits"},"statuses":{"href":"https://api.github.com/repos/lookout/borderpatrol/statuses/be2d3a3bfffb10684a40146b1acdcc3fa68f5436"}}}}