public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { CreateKeyPairResponse response = new CreateKeyPairResponse(); int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth = 2; } while (context.ReadAtDepth(originalDepth)) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression(".", targetDepth)) { response.KeyPair = KeyPairUnmarshaller.Instance.Unmarshall(context); continue; } } } return(response); }
public static CreateKeyPairResponse Unmarshall(UnmarshallerContext context) { CreateKeyPairResponse createKeyPairResponse = new CreateKeyPairResponse(); createKeyPairResponse.HttpResponse = context.HttpResponse; createKeyPairResponse.RequestId = context.StringValue("CreateKeyPair.RequestId"); createKeyPairResponse.KeyPairName = context.StringValue("CreateKeyPair.KeyPairName"); createKeyPairResponse.KeyPairFingerPrint = context.StringValue("CreateKeyPair.KeyPairFingerPrint"); createKeyPairResponse.PrivateKeyBody = context.StringValue("CreateKeyPair.PrivateKeyBody"); return(createKeyPairResponse); }
public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { CreateKeyPairResponse response = new CreateKeyPairResponse(); int targetDepth = 2; while (context.Read()) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression(".", targetDepth)) { response.KeyPair = KeyPairUnmarshaller.GetInstance().Unmarshall(context); continue; } } } return(response); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { CreateKeyPairResponse response = new CreateKeyPairResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("keyPair", targetDepth)) { var unmarshaller = KeyPairUnmarshaller.Instance; response.KeyPair = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("operation", targetDepth)) { var unmarshaller = OperationUnmarshaller.Instance; response.Operation = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("privateKeyBase64", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.PrivateKeyBase64 = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("publicKeyBase64", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.PublicKeyBase64 = unmarshaller.Unmarshall(context); continue; } } return(response); }
public void CreateKeyPair(string keyName, string fileName, string filePath) { AmazonEC2Client ec2 = new AmazonEC2Client(); CreateKeyPairRequest keyReq = new CreateKeyPairRequest(); keyReq.KeyName = "DevKey"; CreateKeyPairResponse keyResp = ec2.CreateKeyPair(keyReq); var keyvalue1 = keyResp.KeyPair.KeyFingerprint; var k2 = keyResp.KeyPair.KeyMaterial; var k3 = keyResp.KeyPair.KeyName; string str = keyvalue1 + k2 + k3; using (FileStream fs = new FileStream(filePath + @"\" + fileName, FileMode.Append, FileAccess.Write)) using (StreamWriter sw = new StreamWriter(fs)) { sw.WriteLine(str); } }
//once we get here we know the key file doesn't exist private void createKayPair() { try { string keyFileDir = CAwsConfig.getEc2BootstrapperDirectory(); if (Directory.Exists(keyFileDir) == false) { Directory.CreateDirectory(keyFileDir); } string keyFilePath = null; FolderBrowserDialog folder = new FolderBrowserDialog(); folder.ShowNewFolderButton = true; folder.SelectedPath = keyFileDir; folder.Description = "Please select directory where you want to save key file"; DialogResult result = DialogResult.No; while (result == DialogResult.No) { if (folder.ShowDialog() == System.Windows.Forms.DialogResult.OK) { keyFilePath = folder.SelectedPath + "\\" + _keyPairName + ".pem"; if (File.Exists(keyFilePath)) { result = MessageBox.Show(null, "Key file " + keyFilePath + " exists. Do you want to overwrite it?", "Key File", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); } else { break; } } } CreateKeyPairRequest request = new CreateKeyPairRequest(); request.KeyName = _keyPairName; CreateKeyPairResponse response = _service.CreateKeyPair(request); if (response.IsSetCreateKeyPairResult()) { CreateKeyPairResult createKeyPairResult = response.CreateKeyPairResult; if (createKeyPairResult.IsSetKeyPair()) { using (FileStream stream = new FileStream( keyFilePath, FileMode.Create, FileAccess.Write)) { KeyPair keyPair = createKeyPairResult.KeyPair; if (keyPair.IsSetKeyMaterial()) { byte[] fileData = new UTF8Encoding(true).GetBytes(keyPair.KeyMaterial); stream.Write(fileData, 0, fileData.Length); CAwsConfig.Instance.setKeyFilePath(_keyPairName, keyFilePath); CAwsConfig.Instance.commit(); } } } } } catch (AmazonEC2Exception ex) { throw new Exception("Caught Exception: " + ex.XML); } }