{"action":"created","issue":{"url":"https://api.github.com/repos/hexpm/hex_web/issues/441","repository_url":"https://api.github.com/repos/hexpm/hex_web","labels_url":"https://api.github.com/repos/hexpm/hex_web/issues/441/labels{/name}","comments_url":"https://api.github.com/repos/hexpm/hex_web/issues/441/comments","events_url":"https://api.github.com/repos/hexpm/hex_web/issues/441/events","html_url":"https://github.com/hexpm/hex_web/pull/441","id":190010385,"number":441,"title":"Use PlugAttack","user":{"login":"michalmuskala","id":477062,"avatar_url":"https://avatars.githubusercontent.com/u/477062?v=3","gravatar_id":"","url":"https://api.github.com/users/michalmuskala","html_url":"https://github.com/michalmuskala","followers_url":"https://api.github.com/users/michalmuskala/followers","following_url":"https://api.github.com/users/michalmuskala/following{/other_user}","gists_url":"https://api.github.com/users/michalmuskala/gists{/gist_id}","starred_url":"https://api.github.com/users/michalmuskala/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michalmuskala/subscriptions","organizations_url":"https://api.github.com/users/michalmuskala/orgs","repos_url":"https://api.github.com/users/michalmuskala/repos","events_url":"https://api.github.com/users/michalmuskala/events{/privacy}","received_events_url":"https://api.github.com/users/michalmuskala/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-11-17T10:49:03Z","updated_at":"2016-11-17T22:17:14Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/hexpm/hex_web/pulls/441","html_url":"https://github.com/hexpm/hex_web/pull/441","diff_url":"https://github.com/hexpm/hex_web/pull/441.diff","patch_url":"https://github.com/hexpm/hex_web/pull/441.patch"},"body":"This is a PoC for replacing custom components for rate limiting and ip blocking with `plug_attack` package, I recently released.\r\n\r\nIt has couple advantages:\r\n* increasing rate limit for authenticated users is trivial - just change the `limit` option based on some connection params,\r\n* skipping rate limiting of conditional requests should be easier to do with a plug-like interface (although we know about that only after the controller processes the request, so it might require some additional work)\r\n* there is a clean storage interface, so implementing something with redis should be easier\r\n* I'm considering adding a loadable blocklist - this should simplify the `BlockAddress` thing even more."},"comment":{"url":"https://api.github.com/repos/hexpm/hex_web/issues/comments/261387521","html_url":"https://github.com/hexpm/hex_web/pull/441#issuecomment-261387521","issue_url":"https://api.github.com/repos/hexpm/hex_web/issues/441","id":261387521,"user":{"login":"michalmuskala","id":477062,"avatar_url":"https://avatars.githubusercontent.com/u/477062?v=3","gravatar_id":"","url":"https://api.github.com/users/michalmuskala","html_url":"https://github.com/michalmuskala","followers_url":"https://api.github.com/users/michalmuskala/followers","following_url":"https://api.github.com/users/michalmuskala/following{/other_user}","gists_url":"https://api.github.com/users/michalmuskala/gists{/gist_id}","starred_url":"https://api.github.com/users/michalmuskala/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michalmuskala/subscriptions","organizations_url":"https://api.github.com/users/michalmuskala/orgs","repos_url":"https://api.github.com/users/michalmuskala/repos","events_url":"https://api.github.com/users/michalmuskala/events{/privacy}","received_events_url":"https://api.github.com/users/michalmuskala/received_events","type":"User","site_admin":false},"created_at":"2016-11-17T22:17:14Z","updated_at":"2016-11-17T22:17:14Z","body":"The `rule` macro defines a function with the same name and registers the function to be called in `call` callback of the plug.\r\n\r\nSomething like:\r\n```elixir\r\nrule \"foo\", conn, do: ...\r\nrule \"bar\", conn, do: ...\r\n```\r\nTranslates to:\r\n```elixir\r\ndef foo(conn), do: ...\r\ndef bar(conn), do: ...\r\n\r\ndef call(conn, opts) do\r\n  case foo(conn) do\r\n    {:allow, data} -> allow_action(conn, data, opts)\r\n    {:block, data} -> block_action(conn, data, opts)\r\n    nil ->\r\n      case bar(conn) do\r\n        {:allow, data} -> allow_action(conn, data, opts)\r\n        {:block, data} -> block_action(conn, data, opts)\r\n        nil -> conn\r\n  end\r\nend\r\n```"}}
{"actor":{"display_login":"michalmuskala"}}