Exemplo n.º 1
0
        public List<string> descrbibeKeyPairs()
        {
            List<string> keyPairs = new List<string>();
            try
            {
                DescribeKeyPairsRequest request = new DescribeKeyPairsRequest();
                DescribeKeyPairsResponse response = _service.DescribeKeyPairs(request);

                if (response.IsSetDescribeKeyPairsResult())
                {
                    DescribeKeyPairsResult describeKeyPairsResult = response.DescribeKeyPairsResult;
                    List<KeyPair> keyPairList = describeKeyPairsResult.KeyPair;
                    foreach (KeyPair keyPair in keyPairList)
                    {
                        if (keyPair.IsSetKeyName())
                        {
                            keyPairs.Add(keyPair.KeyName);
                        }
                    }
                }
            }
            catch (AmazonEC2Exception ex)
            {
                throw new Exception("Caught Exception: " + ex.XML);
            }
            return keyPairs;
        }
Exemplo n.º 2
0
        /// <summary>
        /// The DescribeKeyPairs operation returns information about key pairs available to
        /// you. If you specify key pairs, information about those key pairs is returned.
        /// Otherwise, information for all registered key pairs is returned.
        /// 
        /// </summary>
        /// <param name="service">Instance of AmazonEC2 service</param>
        /// <param name="request">DescribeKeyPairsRequest request</param>
        public static void InvokeDescribeKeyPairs(AmazonEC2 service, DescribeKeyPairsRequest request)
        {
            try 
            {
                DescribeKeyPairsResponse response = service.DescribeKeyPairs(request);
                
                
                Console.WriteLine ("Service Response");
                Console.WriteLine ("=============================================================================");
                Console.WriteLine ();

                Console.WriteLine("        DescribeKeyPairsResponse");
                if (response.IsSetResponseMetadata())
                {
                    Console.WriteLine("            ResponseMetadata");
                    ResponseMetadata  responseMetadata = response.ResponseMetadata;
                    if (responseMetadata.IsSetRequestId())
                    {
                        Console.WriteLine("                RequestId");
                        Console.WriteLine("                    {0}", responseMetadata.RequestId);
                    }
                }
                if (response.IsSetDescribeKeyPairsResult())
                {
                    Console.WriteLine("            DescribeKeyPairsResult");
                    DescribeKeyPairsResult  describeKeyPairsResult = response.DescribeKeyPairsResult;
                    List<KeyPair> keyPairList = describeKeyPairsResult.KeyPair;
                    foreach (KeyPair keyPair in keyPairList)
                    {
                        Console.WriteLine("                KeyPair");
                        if (keyPair.IsSetKeyName())
                        {
                            Console.WriteLine("                    KeyName");
                            Console.WriteLine("                        {0}", keyPair.KeyName);
                        }
                        if (keyPair.IsSetKeyFingerprint())
                        {
                            Console.WriteLine("                    KeyFingerprint");
                            Console.WriteLine("                        {0}", keyPair.KeyFingerprint);
                        }
                        if (keyPair.IsSetKeyMaterial())
                        {
                            Console.WriteLine("                    KeyMaterial");
                            Console.WriteLine("                        {0}", keyPair.KeyMaterial);
                        }
                    }
                }

            } 
            catch (AmazonEC2Exception ex) 
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
                Console.WriteLine("XML: " + ex.XML);
            }
        }
 protected override void ProcessRecord()
 {
     AmazonEC2 client = base.GetClient();
     Amazon.EC2.Model.DescribeKeyPairsRequest request = new Amazon.EC2.Model.DescribeKeyPairsRequest();
     if (string.IsNullOrEmpty(this._KeyName))
     {
         request.KeyName.Add(this._KeyName);
     }
     Amazon.EC2.Model.DescribeKeyPairsResponse response = client.DescribeKeyPairs(request);
     base.WriteObject(response.DescribeKeyPairsResult.KeyPair, true);
 }
Exemplo n.º 4
0
        public object Execute(ExecutorContext context)
        {
            var cmdletContext = context as CmdletContext;
            // create request
            var request = new Amazon.EC2.Model.DescribeKeyPairsRequest();

            if (cmdletContext.Filter != null)
            {
                request.Filters = cmdletContext.Filter;
            }
            if (cmdletContext.KeyName != null)
            {
                request.KeyNames = cmdletContext.KeyName;
            }
            if (cmdletContext.KeyPairId != null)
            {
                request.KeyPairIds = cmdletContext.KeyPairId;
            }

            CmdletOutput output;

            // issue call
            var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);

            try
            {
                var    response       = CallAWSServiceOperation(client, request);
                object pipelineOutput = null;
                pipelineOutput = cmdletContext.Select(response, this);
                output         = new CmdletOutput
                {
                    PipelineOutput  = pipelineOutput,
                    ServiceResponse = response
                };
            }
            catch (Exception e)
            {
                output = new CmdletOutput {
                    ErrorResponse = e
                };
            }

            return(output);
        }
        /// <summary>
        /// Initiates the asynchronous execution of the DescribeKeyPairs operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DescribeKeyPairs operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task<DescribeKeyPairsResponse> DescribeKeyPairsAsync(DescribeKeyPairsRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new DescribeKeyPairsRequestMarshaller();
            var unmarshaller = DescribeKeyPairsResponseUnmarshaller.Instance;

            return InvokeAsync<DescribeKeyPairsRequest,DescribeKeyPairsResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }
        /// <summary>
        /// Describes one or more of your key pairs.
        /// 
        ///  
        /// <para>
        /// For more information about key pairs, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html">Key
        /// Pairs</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>.
        /// </para>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the DescribeKeyPairs service method.</param>
        /// 
        /// <returns>The response from the DescribeKeyPairs service method, as returned by EC2.</returns>
        public DescribeKeyPairsResponse DescribeKeyPairs(DescribeKeyPairsRequest request)
        {
            var marshaller = new DescribeKeyPairsRequestMarshaller();
            var unmarshaller = DescribeKeyPairsResponseUnmarshaller.Instance;

            return Invoke<DescribeKeyPairsRequest,DescribeKeyPairsResponse>(request, marshaller, unmarshaller);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initiates the asynchronous execution of the DescribeKeyPairs operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DescribeKeyPairs operation on AmazonEC2Client.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        /// 
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndDescribeKeyPairs
        ///         operation.</returns>
        public IAsyncResult BeginDescribeKeyPairs(DescribeKeyPairsRequest request, AsyncCallback callback, object state)
        {
            var marshaller = new DescribeKeyPairsRequestMarshaller();
            var unmarshaller = DescribeKeyPairsResponseUnmarshaller.Instance;

            return BeginInvoke<DescribeKeyPairsRequest>(request, marshaller, unmarshaller,
                callback, state);
        }
Exemplo n.º 8
0
 IAsyncResult invokeDescribeKeyPairs(DescribeKeyPairsRequest describeKeyPairsRequest, AsyncCallback callback, object state, bool synchronized)
 {
     IRequest irequest = new DescribeKeyPairsRequestMarshaller().Marshall(describeKeyPairsRequest);
     var unmarshaller = DescribeKeyPairsResponseUnmarshaller.GetInstance();
     AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller);
     Invoke(result);
     return result;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initiates the asynchronous execution of the DescribeKeyPairs operation.
 /// <seealso cref="Amazon.EC2.IAmazonEC2.DescribeKeyPairs"/>
 /// </summary>
 /// 
 /// <param name="describeKeyPairsRequest">Container for the necessary parameters to execute the DescribeKeyPairs operation on AmazonEC2.</param>
 /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
 /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 /// 
 /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndDescribeKeyPairs
 ///         operation.</returns>
 public IAsyncResult BeginDescribeKeyPairs(DescribeKeyPairsRequest describeKeyPairsRequest, AsyncCallback callback, object state)
 {
     return invokeDescribeKeyPairs(describeKeyPairsRequest, callback, state, false);
 }
Exemplo n.º 10
0
 /// <summary>
 /// <para>Describes one or more of your key pairs.</para> <para>For more information about key pairs, see <a
 /// href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html" >Key Pairs</a> in the <i>Amazon Elastic Compute Cloud User
 /// Guide</i> .</para>
 /// </summary>
 /// 
 /// <param name="describeKeyPairsRequest">Container for the necessary parameters to execute the DescribeKeyPairs service method on
 ///          AmazonEC2.</param>
 /// 
 /// <returns>The response from the DescribeKeyPairs service method, as returned by AmazonEC2.</returns>
 /// 
 public DescribeKeyPairsResponse DescribeKeyPairs(DescribeKeyPairsRequest describeKeyPairsRequest)
 {
     IAsyncResult asyncResult = invokeDescribeKeyPairs(describeKeyPairsRequest, null, null, true);
     return EndDescribeKeyPairs(asyncResult);
 }
Exemplo n.º 11
0
 private Amazon.EC2.Model.DescribeKeyPairsResponse CallAWSServiceOperation(IAmazonEC2 client, Amazon.EC2.Model.DescribeKeyPairsRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Elastic Compute Cloud (EC2)", "DescribeKeyPairs");
     try
     {
         #if DESKTOP
         return(client.DescribeKeyPairs(request));
         #elif CORECLR
         return(client.DescribeKeyPairsAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// <para>Describes one or more of your key pairs.</para> <para>For more information about key pairs, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html">Key Pairs</a> in the <i>Amazon Elastic Compute Cloud User
        /// Guide</i> .</para>
        /// </summary>
        /// 
        /// <param name="describeKeyPairsRequest">Container for the necessary parameters to execute the DescribeKeyPairs service method on
        /// AmazonEC2.</param>
        /// 
        /// <returns>The response from the DescribeKeyPairs service method, as returned by AmazonEC2.</returns>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
		public Task<DescribeKeyPairsResponse> DescribeKeyPairsAsync(DescribeKeyPairsRequest describeKeyPairsRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new DescribeKeyPairsRequestMarshaller();
            var unmarshaller = DescribeKeyPairsResponseUnmarshaller.GetInstance();
            return Invoke<IRequest, DescribeKeyPairsRequest, DescribeKeyPairsResponse>(describeKeyPairsRequest, marshaller, unmarshaller, signer, cancellationToken);
        }
Exemplo n.º 13
0
		internal DescribeKeyPairsResponse DescribeKeyPairs(DescribeKeyPairsRequest request)
        {
            var task = DescribeKeyPairsAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return null;
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Initiates the asynchronous execution of the DescribeKeyPairs operation.
        /// <seealso cref="Amazon.EC2.IAmazonEC2.DescribeKeyPairs"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DescribeKeyPairs operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
		public async Task<DescribeKeyPairsResponse> DescribeKeyPairsAsync(DescribeKeyPairsRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new DescribeKeyPairsRequestMarshaller();
            var unmarshaller = DescribeKeyPairsResponseUnmarshaller.GetInstance();
            var response = await Invoke<IRequest, DescribeKeyPairsRequest, DescribeKeyPairsResponse>(request, marshaller, unmarshaller, signer, cancellationToken)
                .ConfigureAwait(continueOnCapturedContext: false);
            return response;
        }
Exemplo n.º 15
0
        /// <summary>
        /// <para> The DescribeKeyPairs operation returns information about key pairs available to you. If you specify key pairs, information about
        /// those key pairs is returned. Otherwise, information for all registered key pairs is returned. </para>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DescribeKeyPairs service method on
        /// AmazonEC2.</param>
        /// 
        /// <returns>The response from the DescribeKeyPairs service method, as returned by AmazonEC2.</returns>
		public DescribeKeyPairsResponse DescribeKeyPairs(DescribeKeyPairsRequest request)
        {
            var task = DescribeKeyPairsAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                throw e.InnerException;
            }
        }
 /// <summary>
 /// Load key pairs to view model with AWS data based on region selected and EC2 classic/vpc
 /// </summary>
 private void LoadKeyPairs(AmazonEC2Client ec2Client)
 {
     try
     {
         DescribeKeyPairsRequest keyreq = new DescribeKeyPairsRequest();
         DescribeKeyPairsResponse keyresp = ec2Client.DescribeKeyPairs(keyreq);
         Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
         {
             vm.KeyPairs.Clear();
         }));
         foreach (KeyPair kp in keyresp.DescribeKeyPairsResult.KeyPair)
         {
             Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
             {
                 vm.KeyPairs.Add(kp.KeyName);
             }));
         }
     }
     catch (Exception ex)
     {
         LogManager.LogEntry(ex.Message);
         LogManager.LogEntry(ex.StackTrace);
         throw new DataLoadingException("Error occurred loading key pairs for region and environment type");
     }
 }