From b26f691aecb896ae7320d0ba54d418755fd81635 Mon Sep 17 00:00:00 2001 From: Matt Warren Date: Thu, 20 Dec 2018 13:52:20 -0500 Subject: [PATCH] fix reversed logic on is_windows ssh vs RDP connection type --- .../Amazon Web Services/EC2/AWS EC2 (Python).rdfe | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Dynamic Folder/Amazon Web Services/EC2/AWS EC2 (Python).rdfe b/Dynamic Folder/Amazon Web Services/EC2/AWS EC2 (Python).rdfe index 57c4862..d9787d6 100644 --- a/Dynamic Folder/Amazon Web Services/EC2/AWS EC2 (Python).rdfe +++ b/Dynamic Folder/Amazon Web Services/EC2/AWS EC2 (Python).rdfe @@ -1 +1,14 @@ -{"Name":"Dynamic Folder Export","Objects":[{"Type":"DynamicFolder","Name":"AWS EC2 (Python)","Notes":"

Dynamic Folder sample for Amazon Web Services (AWS) EC2

\n\n

Version: 1.0
\nAuthor: Royal Applications

\n\n

This Dynamic Folder sample for AWS EC2 supports grabbing all EC2 instances of a specified region.

\n\n

Prerequisites

\n\n\n\n

Setup

\n\n\n\n

Notes

\n\n\n","CustomProperties":[{"Name":"Region","Type":"Text","Value":"TODO"}],"ScriptInterpreter":"python","DynamicCredentialScriptInterpreter":"json","DynamicCredentialScript":"{\n\t\"Username\": \"user\",\n\t\"Password\": \"pass\"\n}","Script":"import subprocess\nimport json\n\ndef get_instances(region = \"\"):\n\tcmd = \"aws ec2 describe-instances\"\n\n\tif region != \"\":\n\t\tcmd += \" --region \" + region\n\n\taws = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)\n\t(response_json, err) = aws.communicate()\n\texit_code = aws.wait()\n\n\tresponse = json.loads(response_json)\n\n\tconnections = [ ]\n\n\tfor reservation in response.get(\"Reservations\", None):\n\t\tfor instance in reservation.get(\"Instances\", None):\n\t\t\tinstance_id = instance.get(\"InstanceId\", \"\")\n\t\t\tplatform = instance.get(\"Platform\", \"\")\n\n\t\t\tis_windows = platform.lower() == \"windows\"\n\t\t\tusername = \"Administrator\" if is_windows else \"ec2-user\"\n\n\t\t\tpublic_ip_address = instance.get(\"PublicIpAddress\", \"\")\n\t\t\tpublic_hostname = instance.get(\"PublicDnsName\", \"\")\n\n\t\t\tprivate_ip_address = instance.get(\"PrivateIpAddress\", \"\")\n\t\t\tprivate_hostname = instance.get(\"PrivateDnsName\", \"\")\n\n\t\t\ttags = instance.get(\"Tags\")\n\t\t\tname = instance_id\n\n\t\t\tif tags is not None:\n\t\t\t\tfor tag in tags:\n\t\t\t\t\tif tag.get(\"Key\", \"\").lower() == \"name\":\n\t\t\t\t\t\ttagValue = tag.get(\"Value\", \"\")\n\n\t\t\t\t\t\tif tagValue.lower() != \"\":\n\t\t\t\t\t\t\tname = tagValue\n\t\t\t\t\t\t\n\t\t\t\t\t\tbreak\n\n\t\t\tcomputer_name = public_hostname\n\n\t\t\tif computer_name == \"\":\n\t\t\t\tcomputer_name = public_ip_address\n\n\t\t\tif computer_name == \"\":\n\t\t\t\tcomputer_name = private_hostname\n\n\t\t\tif computer_name == \"\":\n\t\t\t\tcomputer_name = private_ip_address\n\n\t\t\tconnection = { }\n\n\t\t\tif is_windows:\n\t\t\t\tconnection[\"Type\"] = \"TerminalConnection\"\n\t\t\t\tconnection[\"TerminalConnectionType\"] = \"SSH\"\n\t\t\telse:\n\t\t\t\tconnection[\"Type\"] = \"RemoteDesktopConnection\"\n\n\t\t\tconnection[\"ID\"] = instance_id\n\t\t\tconnection[\"Name\"] = name\n\t\t\tconnection[\"ComputerName\"] = computer_name\n\t\t\tconnection[\"Username\"] = username\n\n\t\t\tconnections.append(connection)\n\n\tstore = {\n\t\t\"Objects\": connections\n\t}\n\n\tstore_json = json.dumps(store)\n\n\treturn store_json\n\nprint(get_instances(\"$CustomProperty.Region$\"))"}]} \ No newline at end of file +{ + "Name": "Dynamic Folder Export", + "Objects": [ + { + "Type": "DynamicFolder", + "Name": "AWS EC2 (Python)", + "Notes": "

Dynamic Folder sample for Amazon Web Services (AWS) EC2

\n\n

Version: 1.0
\nAuthor: Royal Applications

\n\n

This Dynamic Folder sample for AWS EC2 supports grabbing all EC2 instances of a specified region.

\n\n

Prerequisites

\n\n\n\n

Setup

\n\n\n\n

Notes

\n\n\n", + "ScriptInterpreter": "python", + "DynamicCredentialScriptInterpreter": "json", + "DynamicCredentialScript": "{\n\t\"Username\": \"user\",\n\t\"Password\": \"pass\"\n}", + "Script": "import subprocess\nimport json\n\ndef get_instances(region = \"\"):\n\tcmd = \"aws ec2 describe-instances\"\n\n\tif region != \"\":\n\t\tcmd += \" --region \" + region\n\n\taws = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)\n\t(response_json, err) = aws.communicate()\n\texit_code = aws.wait()\n\n\tresponse = json.loads(response_json)\n\n\tconnections = [ ]\n\n\tfor reservation in response.get(\"Reservations\", None):\n\t\tfor instance in reservation.get(\"Instances\", None):\n\t\t\tinstance_id = instance.get(\"InstanceId\", \"\")\n\t\t\tplatform = instance.get(\"Platform\", \"\")\n\n\t\t\tis_windows = platform.lower() == \"windows\"\n\t\t\tusername = \"Administrator\" if is_windows else \"ec2-user\"\n\n\t\t\tpublic_ip_address = instance.get(\"PublicIpAddress\", \"\")\n\t\t\tpublic_hostname = instance.get(\"PublicDnsName\", \"\")\n\n\t\t\tprivate_ip_address = instance.get(\"PrivateIpAddress\", \"\")\n\t\t\tprivate_hostname = instance.get(\"PrivateDnsName\", \"\")\n\n\t\t\ttags = instance.get(\"Tags\")\n\t\t\tname = instance_id\n\n\t\t\tif tags is not None:\n\t\t\t\tfor tag in tags:\n\t\t\t\t\tif tag.get(\"Key\", \"\").lower() == \"name\":\n\t\t\t\t\t\ttagValue = tag.get(\"Value\", \"\")\n\n\t\t\t\t\t\tif tagValue.lower() != \"\":\n\t\t\t\t\t\t\tname = tagValue\n\t\t\t\t\t\t\n\t\t\t\t\t\tbreak\n\n\t\t\tcomputer_name = public_hostname\n\n\t\t\tif computer_name == \"\":\n\t\t\t\tcomputer_name = public_ip_address\n\n\t\t\tif computer_name == \"\":\n\t\t\t\tcomputer_name = private_hostname\n\n\t\t\tif computer_name == \"\":\n\t\t\t\tcomputer_name = private_ip_address\n\n\t\t\tconnection = { }\n\n\t\t\tif not is_windows:\n\t\t\t\tconnection[\"Type\"] = \"TerminalConnection\"\n\t\t\t\tconnection[\"TerminalConnectionType\"] = \"SSH\"\n\t\t\telse:\n\t\t\t\tconnection[\"Type\"] = \"RemoteDesktopConnection\"\n\n\t\t\tconnection[\"ID\"] = instance_id\n\t\t\tconnection[\"Name\"] = name\n\t\t\tconnection[\"ComputerName\"] = computer_name\n\t\t\tconnection[\"Username\"] = username\n\n\t\t\tconnections.append(connection)\n\n\tstore = {\n\t\t\"Objects\": connections\n\t}\n\n\tstore_json = json.dumps(store)\n\n\treturn store_json\n\nprint(get_instances(\"$CustomProperty.Region$\"))" + } + ] +} \ No newline at end of file