Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load Wizards from AWS Shell data path #151

Open
wants to merge 8 commits into
base: wizard-feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion awsshell/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import logging
import sys

import botocore.session

from prompt_toolkit.document import Document
from prompt_toolkit.shortcuts import create_eventloop
from prompt_toolkit.buffer import Buffer
Expand Down Expand Up @@ -158,7 +160,17 @@ def __init__(self, output=sys.stdout, err=sys.stderr, loader=None):
self._err = err
self._wizard_loader = loader
if self._wizard_loader is None:
self._wizard_loader = WizardLoader()
session = self._initalize_session()
self._wizard_loader = WizardLoader(session=session)

def _initalize_session(self):
"""Get a session and append the data directory to search paths."""
session = botocore.session.get_session()
data_loader = session.get_component('data_loader')
shell_root_dir = os.path.dirname(os.path.abspath(__file__))
data_path = os.path.join(shell_root_dir, 'data')
data_loader.search_paths.append(data_path)
return session

def run(self, command, application):
"""Run the specified wizard.
Expand Down
101 changes: 101 additions & 0 deletions awsshell/data/wizards/2016-01-01/apigateway.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"StartStage": "ApiSourceSwitch",
"Stages": [
{
"Name": "ApiSourceSwitch",
"Prompt": "What is the source for the new Api?",
"Retrieval": {
"Type": "Static",
"Resource": [
{ "Option": "Create new Api", "Stage": "CreateApi"},
{ "Option": "Generate new Api from swagger spec file", "Stage": "NewSwaggerApi"}
]
},
"Interaction": { "ScreenType": "SimpleSelect", "Path": "[].Option" },
"Resolution": {
"Path": "Stage",
"Key": "CreationType"
},
"NextStage": { "Type": "Variable", "Name": "CreationType" }
},
{
"Name": "NewSwaggerApi",
"Prompt": "Enter the path to the JSON swagger spec file",
"Interaction": { "ScreenType": "FilePrompt" },
"Resolution": { "Key": "SwaggerBlob" },
"NextStage": { "Type": "Name", "Name": "ImportApiRequest" }
},
{
"Name": "ImportApiRequest",
"Prompt": "Importing Api from swagger spec...",

"Retrieval": {
"Type": "Request",
"Resource": {
"Service": "apigateway",
"Operation": "ImportRestApi",
"Parameters": { "failOnWarnings": true },
"EnvParameters": { "body": "SwaggerBlob" }
}
}
},
{
"Name": "CreateApi",
"Prompt": "Api Name and Description",
"Retrieval": {
"Type": "Static",
"Resource": { "name": "", "description": "" }
},
"Interaction": { "ScreenType": "SimplePrompt" },
"Resolution": { "Key": "Details" },
"NextStage": { "Type": "Name", "Name": "CloneSwitch" }
},
{
"Name": "CloneSwitch",
"Prompt": "Create new empty Api or clone from existing?",
"Retrieval": {
"Type": "Static",
"Resource": [
{ "Option": "Create new Api", "Stage": "CreateApiRequest" },
{ "Option": "Clone existing Api", "Stage": "GetApiList" }
]
},
"Interaction": { "ScreenType": "SimpleSelect", "Path": "[].Option" },
"Resolution": { "Path": "Stage", "Key": "CloneType" },
"NextStage": { "Type": "Variable", "Name": "CloneType" }
},
{
"Name": "GetApiList",
"Prompt": "Select an Api to clone",

"Retrieval": {
"Type": "Request",
"Resource": {
"Service": "apigateway",
"Operation": "GetRestApis"
},
"Path": "items"
},
"Interaction": { "ScreenType": "InfoSelect", "Path": "[].name" },
"Resolution": { "Path": "id", "Key": "ApiId" },
"NextStage": { "Type": "Name", "Name": "CreateApiRequest" }
},
{
"Name": "CreateApiRequest",
"Prompt": "Creating new Api...",

"Retrieval": {
"Type": "Request",
"Resource": {
"Service": "apigateway",
"Operation": "CreateRestApi",
"EnvParameters": {
"cloneFrom": "ApiId",
"name": "Details.name",
"description": "Details.description"
}
}
}
}
]
}
95 changes: 95 additions & 0 deletions awsshell/data/wizards/2016-01-01/create-instance-profile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"StartStage": "NamePrompt",
"Stages": [
{
"Name": "NamePrompt",
"Prompt": "Enter the Instance Profile name",

"Retrieval": {
"Type": "Static",
"Resource": {"Name": ""}
},

"Interaction": { "ScreenType": "SimplePrompt" },
"Resolution": { "Path": "Name", "Key": "ProfileName" },
"NextStage": { "Type": "Name", "Name": "CreateProfile" }
},
{
"Name": "CreateProfile",
"Prompt": "Creating Profile...",

"Retrieval": {
"Type": "Request",
"Resource": {
"Service": "iam",
"Operation": "CreateInstanceProfile",
"EnvParameters": {
"InstanceProfileName": "ProfileName"
}
},
"Path": "InstanceProfile"
},
"Resolution": { "Key": "Profile" },
"NextStage": { "Type": "Name", "Name": "AddRoleSwitch" }
},
{
"Name": "AddRoleSwitch",
"Prompt": "Add a role to this profile?",
"Retrieval": {
"Type": "Static",
"Resource": [
{ "Option": "Yes", "Stage": "SelectRole"},
{ "Option": "No", "Stage": "GetRole"}
]
},
"Interaction": { "ScreenType": "SimpleSelect", "Path": "[].Option" },
"Resolution": { "Path": "Stage", "Key": "RoleSwitch" },
"NextStage": { "Type": "Variable", "Name": "RoleSwitch" }
},
{
"Name": "SelectRole",
"Prompt": "Select Role to add:",
"Retrieval": {
"Type": "Request",
"Resource": {
"Service": "iam",
"Operation": "ListRoles"
},
"Path": "Roles[].RoleName"
},
"Interaction": { "ScreenType": "SimpleSelect" },
"Resolution": { "Key": "RoleName" },
"NextStage": { "Type": "Name", "Name": "AddRole" }
},
{
"Name": "AddRole",
"Prompt": "Adding role...",
"Retrieval": {
"Type": "Request",
"Resource": {
"Service": "iam",
"Operation": "AddRoleToInstanceProfile",
"EnvParameters": {
"RoleName": "RoleName",
"InstanceProfileName": "Profile.InstanceProfileName"
}
}
},
"NextStage": { "Type": "Name", "Name": "GetRole" }
},
{
"Name": "GetRole",
"Prompt": "Getting role...",
"Retrieval": {
"Type": "Request",
"Resource": {
"Service": "iam",
"Operation": "GetInstanceProfile",
"EnvParameters": {
"InstanceProfileName": "Profile.InstanceProfileName"
}
}
}
}
]
}
74 changes: 74 additions & 0 deletions awsshell/data/wizards/2016-01-01/create-security-group.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"StartStage": "GroupDetails",
"Stages": [
{
"Name": "GroupDetails",
"Prompt": "Please enter the details for this group: ",

"Retrieval": {
"Type": "Static",
"Resource": {"Name": "", "Description": ""}
},

"Interaction": { "ScreenType": "SimplePrompt" },
"Resolution": { "Key": "Details" },
"NextStage": { "Type": "Name", "Name": "SelectVPCSwitch" }
},
{
"Name": "SelectVPCSwitch",
"Prompt": "Would you like to specify a VPC? ",
"Retrieval": {
"Type": "Static",
"Resource": [
{ "Option": "Use Default", "Stage": "CreateGroupRequest" },
{ "Option": "Select a VPC", "Stage": "GetVPC" }
]
},
"Interaction": { "ScreenType": "SimpleSelect", "Path": "[].Option" },
"Resolution": { "Path": "Stage", "Key": "VPCSwitch" },
"NextStage": { "Type": "Variable", "Name": "VPCSwitch" }
},
{
"Name": "GetVPC",
"Prompt": "Getting VPC to use...",

"Retrieval": { "Type": "Wizard", "Resource": "get-vpc" },
"Resolution": { "Path": "VpcId", "Key": "VpcId" },
"NextStage": { "Type": "Name", "Name": "CreateGroupRequest" }
},
{
"Name": "CreateGroupRequest",
"Prompt": "Creating Security Group...",

"Retrieval": {
"Type": "Request",
"Resource": {
"Service": "ec2",
"Operation": "CreateSecurityGroup",
"Parameters": { "DryRun": false },
"EnvParameters": {
"VpcId": "VpcId",
"GroupName": "Details.Name",
"Description": "Details.Description"
}
}
},
"Resolution": { "Path": "GroupId", "Key": "GroupId" },
"NextStage": { "Type": "Name", "Name": "GetGroup" }
},
{
"Name": "GetGroup",
"Prompt": "Getting Security Group...",

"Retrieval": {
"Type": "Request",
"Resource": {
"Service": "ec2",
"Operation": "DescribeSecurityGroups",
"EnvParameters": { "GroupIds": "GroupId | [@]" }
}
},
"Resolution": { "Path": "SecurityGroups[0]", "Key": "Group" }
}
]
}
73 changes: 73 additions & 0 deletions awsshell/data/wizards/2016-01-01/create-subnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"StartStage": "CIDRPrompt",
"Stages": [
{
"Name": "CIDRPrompt",
"Prompt": "Enter subnet IP address block (e.g., 10.0.0.0/24)",

"Retrieval": {
"Type": "Static",
"Resource": {"CIDR": ""}
},

"Interaction": { "ScreenType": "SimplePrompt" },
"Resolution": { "Path": "CIDR", "Key": "CIDR" },
"NextStage": { "Type": "Name", "Name": "ZoneSwitch" }
},
{
"Name": "ZoneSwitch",
"Prompt": "Would you like to specify an availability zone?",
"Retrieval": {
"Type": "Static",
"Resource": [
{ "Option": "No Preference", "Stage": "GetVPC"},
{ "Option": "Select availability zone", "Stage": "SelectZone"}
]
},
"Interaction": { "ScreenType": "SimpleSelect", "Path": "[].Option" },
"Resolution": { "Path": "Stage", "Key": "ZoneSwitch" },
"NextStage": { "Type": "Variable", "Name": "ZoneSwitch" }
},
{
"Name": "SelectZone",
"Prompt": "Select the desired zone: ",
"Retrieval": {
"Type": "Request",
"Resource": {
"Service": "ec2",
"Operation": "DescribeAvailabilityZones"
},
"Path": "AvailabilityZones"
},
"Interaction": { "ScreenType": "SimpleSelect", "Path": "[].ZoneName" },
"Resolution": { "Path": "ZoneName", "Key": "ZoneName" },
"NextStage": { "Type": "Name", "Name": "GetVPC" }
},
{
"Name": "GetVPC",
"Prompt": "Getting VPC to use...",

"Retrieval": { "Type": "Wizard", "Resource": "get-vpc" },
"Resolution": { "Path": "VpcId", "Key": "VpcId" },
"NextStage": { "Type": "Name", "Name": "CreateSubnet" }
},
{
"Name": "CreateSubnet",
"Prompt": "Creating Subnet...",

"Retrieval": {
"Type": "Request",
"Resource": {
"Service": "ec2",
"Operation": "CreateSubnet",
"Parameters": { "DryRun": false },
"EnvParameters": {
"VpcId": "VpcId",
"CidrBlock": "CIDR",
"AvailabilityZone": "ZoneName"
}
}
}
}
]
}
Loading