{"action":"created","comment":{"url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/pulls/comments/27776977","id":27776977,"diff_hunk":"@@ -107,41 +105,78 @@ def delete(**_):\n         .format(group_id))\n \n \n-def _delete_security_group(group_id, ec2_client):\n+def _delete_security_group(group_id):\n     \"\"\"Tries to delete a Security group\n     \"\"\"\n \n+    group_to_delete = _get_security_group_from_id(group_id)\n+\n+    if not group_to_delete:\n+        raise NonRecoverableError(\n+            'Unable to delete security group {0}, because the group '\n+            'does not exist in the account'.format(group_id))\n+\n     try:\n-        ec2_client.delete_security_group(group_id=group_id)\n+        group_to_delete.delete()\n     except (boto.exception.EC2ResponseError,\n             boto.exception.BotoServerError) as e:\n         raise NonRecoverableError('{0}'.format(str(e)))\n \n \n-def _authorize_by_id(ec2_client, group_id, rules):\n-    \"\"\" For each rule listed in the blueprint,\n-        this will add the rule to the group with the given id.\n-\n-    :param ec2_client: The EC2 Client object.\n-    :param group: The group id that you want to add rules to.\n-    :param rules: A list of rules.\n-    :raises NonRecoverableError: if Boto or EC2 response is an error.\n+def _authorize_by_id(group_object):\n+    \"\"\"For each rule listed in the blueprint,\n+    this will add the rule to the group with the given id.\n+    :param group: The group object that you want to add rules to.\n+    :raises NonRecoverableError: src_group_id OR ip_protocol,\n+    from_port, to_port, and cidr_ip are not provided.\n     \"\"\"\n \n-    for r in rules:\n-        try:\n-            ec2_client.authorize_security_group(\n-                group_id=group_id,\n-                ip_protocol=r['ip_protocol'],\n-                from_port=r['from_port'],\n-                to_port=r['to_port'],\n-                cidr_ip=r['cidr_ip'])\n-        except (boto.exception.EC2ResponseError,\n-                boto.exception.BotoServerError) as e:\n-            raise NonRecoverableError('{0}'.format(str(e)))\n-        except Exception as e:\n-            _delete_security_group(group_id, ec2_client)\n-            raise\n+    for rule in ctx.node.properties['rules']:\n+        if 'src_group_id' in rule:\n+            _authorize_src_group(group_object, rule)\n+        elif 'ip_protocol' in rule \\\n+                and 'from_port' in rule \\\n+                and 'to_port' in rule \\\n+                and 'cidr_ip' in rule:\n+            _authorize_cidr_ip(group_object, rule)\n+        else:\n+            raise NonRecoverableError(\n+                'You need to pass in either src_group_id OR '\n+                'ip_protocol, from_port, to_port, and cidr_ip. '\n+                'In other words, either you are authorizing another '\n+                'group or you are authorizing some ip-based rule.'\n+            )\n+\n+\n+def _authorize_cidr_ip(group_object, rule):\n+\n+    try:\n+        group_object.authorize(\n+            ip_protocol=rule['ip_protocol'],\n+            from_port=rule['from_port'],\n+            to_port=rule['to_port'],\n+            cidr_ip=rule['cidr_ip']\n+        )\n+    except (boto.exception.EC2ResponseError,\n+            boto.exception.BotoServerError) as e:\n+        raise NonRecoverableError('{0}'.format(str(e)))\n+    except Exception as e:\n+        _delete_security_group(group_object.id)\n+        raise\n+\n+\n+def _authorize_src_group(group_object, rule):\n+\n+    src_group_object = _get_security_group_from_id(rule['src_group_id'])\n+\n+    try:\n+        group_object.authorize(src_group=src_group_object)","path":"ec2/securitygroup.py","position":120,"original_position":120,"commit_id":"1c1be19e80b4fbfb0b63d97a52b2cd5f335c0d57","original_commit_id":"1c1be19e80b4fbfb0b63d97a52b2cd5f335c0d57","user":{"login":"ran-z","id":5601186,"avatar_url":"https://avatars.githubusercontent.com/u/5601186?v=3","gravatar_id":"","url":"https://api.github.com/users/ran-z","html_url":"https://github.com/ran-z","followers_url":"https://api.github.com/users/ran-z/followers","following_url":"https://api.github.com/users/ran-z/following{/other_user}","gists_url":"https://api.github.com/users/ran-z/gists{/gist_id}","starred_url":"https://api.github.com/users/ran-z/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ran-z/subscriptions","organizations_url":"https://api.github.com/users/ran-z/orgs","repos_url":"https://api.github.com/users/ran-z/repos","events_url":"https://api.github.com/users/ran-z/events{/privacy}","received_events_url":"https://api.github.com/users/ran-z/received_events","type":"User","site_admin":false},"body":"need to pass the other params as well","created_at":"2015-04-05T12:34:11Z","updated_at":"2015-04-05T12:34:11Z","html_url":"https://github.com/cloudify-cosmo/cloudify-aws-plugin/pull/27#discussion_r27776977","pull_request_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/pulls/27","_links":{"self":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/pulls/comments/27776977"},"html":{"href":"https://github.com/cloudify-cosmo/cloudify-aws-plugin/pull/27#discussion_r27776977"},"pull_request":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/pulls/27"}}},"pull_request":{"url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/pulls/27","id":32646959,"html_url":"https://github.com/cloudify-cosmo/cloudify-aws-plugin/pull/27","diff_url":"https://github.com/cloudify-cosmo/cloudify-aws-plugin/pull/27.diff","patch_url":"https://github.com/cloudify-cosmo/cloudify-aws-plugin/pull/27.patch","issue_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/issues/27","number":27,"state":"open","locked":false,"title":"Add new authorize feature","user":{"login":"EarthmanT","id":9653571,"avatar_url":"https://avatars.githubusercontent.com/u/9653571?v=3","gravatar_id":"","url":"https://api.github.com/users/EarthmanT","html_url":"https://github.com/EarthmanT","followers_url":"https://api.github.com/users/EarthmanT/followers","following_url":"https://api.github.com/users/EarthmanT/following{/other_user}","gists_url":"https://api.github.com/users/EarthmanT/gists{/gist_id}","starred_url":"https://api.github.com/users/EarthmanT/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EarthmanT/subscriptions","organizations_url":"https://api.github.com/users/EarthmanT/orgs","repos_url":"https://api.github.com/users/EarthmanT/repos","events_url":"https://api.github.com/users/EarthmanT/events{/privacy}","received_events_url":"https://api.github.com/users/EarthmanT/received_events","type":"User","site_admin":false},"body":"* Adding the authorize another security group feature\r\n* updating the existing tests to not break when we add this feature","created_at":"2015-04-05T10:29:54Z","updated_at":"2015-04-05T12:34:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c51274c0c43c8ca543d35d90f216d4063aa59e8b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/pulls/27/commits","review_comments_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/pulls/27/comments","review_comment_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/issues/27/comments","statuses_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/statuses/1c1be19e80b4fbfb0b63d97a52b2cd5f335c0d57","head":{"label":"cloudify-cosmo:add_new_authorize_feature","ref":"add_new_authorize_feature","sha":"1c1be19e80b4fbfb0b63d97a52b2cd5f335c0d57","user":{"login":"cloudify-cosmo","id":6260555,"avatar_url":"https://avatars.githubusercontent.com/u/6260555?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudify-cosmo","html_url":"https://github.com/cloudify-cosmo","followers_url":"https://api.github.com/users/cloudify-cosmo/followers","following_url":"https://api.github.com/users/cloudify-cosmo/following{/other_user}","gists_url":"https://api.github.com/users/cloudify-cosmo/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudify-cosmo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudify-cosmo/subscriptions","organizations_url":"https://api.github.com/users/cloudify-cosmo/orgs","repos_url":"https://api.github.com/users/cloudify-cosmo/repos","events_url":"https://api.github.com/users/cloudify-cosmo/events{/privacy}","received_events_url":"https://api.github.com/users/cloudify-cosmo/received_events","type":"Organization","site_admin":false},"repo":{"id":28482346,"name":"cloudify-aws-plugin","full_name":"cloudify-cosmo/cloudify-aws-plugin","owner":{"login":"cloudify-cosmo","id":6260555,"avatar_url":"https://avatars.githubusercontent.com/u/6260555?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudify-cosmo","html_url":"https://github.com/cloudify-cosmo","followers_url":"https://api.github.com/users/cloudify-cosmo/followers","following_url":"https://api.github.com/users/cloudify-cosmo/following{/other_user}","gists_url":"https://api.github.com/users/cloudify-cosmo/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudify-cosmo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudify-cosmo/subscriptions","organizations_url":"https://api.github.com/users/cloudify-cosmo/orgs","repos_url":"https://api.github.com/users/cloudify-cosmo/repos","events_url":"https://api.github.com/users/cloudify-cosmo/events{/privacy}","received_events_url":"https://api.github.com/users/cloudify-cosmo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudify-cosmo/cloudify-aws-plugin","description":"A Cloudify Plugin that provisions resources in Amazon Web Services","fork":false,"url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin","forks_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/forks","keys_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/teams","hooks_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/hooks","issue_events_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/events","assignees_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/tags","blobs_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/languages","stargazers_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/stargazers","contributors_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/contributors","subscribers_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/subscribers","subscription_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/subscription","commits_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/merges","archive_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/downloads","issues_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/labels{/name}","releases_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/releases{/id}","created_at":"2014-12-25T13:32:30Z","updated_at":"2015-04-01T16:24:19Z","pushed_at":"2015-04-05T11:07:45Z","git_url":"git://github.com/cloudify-cosmo/cloudify-aws-plugin.git","ssh_url":"git@github.com:cloudify-cosmo/cloudify-aws-plugin.git","clone_url":"https://github.com/cloudify-cosmo/cloudify-aws-plugin.git","svn_url":"https://github.com/cloudify-cosmo/cloudify-aws-plugin","homepage":null,"size":1719,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"cloudify-cosmo:master","ref":"master","sha":"bd62c1f7445a2035b5945619a2c39b6080648b2b","user":{"login":"cloudify-cosmo","id":6260555,"avatar_url":"https://avatars.githubusercontent.com/u/6260555?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudify-cosmo","html_url":"https://github.com/cloudify-cosmo","followers_url":"https://api.github.com/users/cloudify-cosmo/followers","following_url":"https://api.github.com/users/cloudify-cosmo/following{/other_user}","gists_url":"https://api.github.com/users/cloudify-cosmo/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudify-cosmo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudify-cosmo/subscriptions","organizations_url":"https://api.github.com/users/cloudify-cosmo/orgs","repos_url":"https://api.github.com/users/cloudify-cosmo/repos","events_url":"https://api.github.com/users/cloudify-cosmo/events{/privacy}","received_events_url":"https://api.github.com/users/cloudify-cosmo/received_events","type":"Organization","site_admin":false},"repo":{"id":28482346,"name":"cloudify-aws-plugin","full_name":"cloudify-cosmo/cloudify-aws-plugin","owner":{"login":"cloudify-cosmo","id":6260555,"avatar_url":"https://avatars.githubusercontent.com/u/6260555?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudify-cosmo","html_url":"https://github.com/cloudify-cosmo","followers_url":"https://api.github.com/users/cloudify-cosmo/followers","following_url":"https://api.github.com/users/cloudify-cosmo/following{/other_user}","gists_url":"https://api.github.com/users/cloudify-cosmo/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudify-cosmo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudify-cosmo/subscriptions","organizations_url":"https://api.github.com/users/cloudify-cosmo/orgs","repos_url":"https://api.github.com/users/cloudify-cosmo/repos","events_url":"https://api.github.com/users/cloudify-cosmo/events{/privacy}","received_events_url":"https://api.github.com/users/cloudify-cosmo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudify-cosmo/cloudify-aws-plugin","description":"A Cloudify Plugin that provisions resources in Amazon Web Services","fork":false,"url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin","forks_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/forks","keys_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/teams","hooks_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/hooks","issue_events_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/events","assignees_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/tags","blobs_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/languages","stargazers_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/stargazers","contributors_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/contributors","subscribers_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/subscribers","subscription_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/subscription","commits_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/merges","archive_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/downloads","issues_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/labels{/name}","releases_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/releases{/id}","created_at":"2014-12-25T13:32:30Z","updated_at":"2015-04-01T16:24:19Z","pushed_at":"2015-04-05T11:07:45Z","git_url":"git://github.com/cloudify-cosmo/cloudify-aws-plugin.git","ssh_url":"git@github.com:cloudify-cosmo/cloudify-aws-plugin.git","clone_url":"https://github.com/cloudify-cosmo/cloudify-aws-plugin.git","svn_url":"https://github.com/cloudify-cosmo/cloudify-aws-plugin","homepage":null,"size":1719,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/pulls/27"},"html":{"href":"https://github.com/cloudify-cosmo/cloudify-aws-plugin/pull/27"},"issue":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/issues/27"},"comments":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/issues/27/comments"},"review_comments":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/pulls/27/comments"},"review_comment":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/pulls/27/commits"},"statuses":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-aws-plugin/statuses/1c1be19e80b4fbfb0b63d97a52b2cd5f335c0d57"}}}}