Exemple #1
0
        public static AwsClient InitAwsClient(AwsConfig aws)
        {
            AwsClient client = null;

            if (aws != null)
            {
                bool hasAccessKey = (!String.IsNullOrWhiteSpace(aws.AccessKey));
                bool hasSecretKey = (!String.IsNullOrWhiteSpace(aws.SecretKey));
                bool hasRegion    = (!String.IsNullOrWhiteSpace(aws.Region));

                if (hasAccessKey && hasSecretKey)
                {
                    if (hasRegion)
                    {
                        client = new AwsClient(aws.AccessKey, aws.SecretKey, aws.AwsRegion);
                    }
                    else
                    {
                        client = new AwsClient(aws.AccessKey, aws.SecretKey);
                    }
                }
                else if (hasRegion)
                {
                    client = new AwsClient(aws.AwsRegion);
                }
                else
                {
                    client = new AwsClient();     // Pull All Details From Environemnt Variables / Credentails Files
                }
            }
            return(client);
        }
Exemple #2
0
        /// <summary>
        /// Gets the signed URL.
        /// </summary>
        /// <param name="FileName">Name of the file.</param>
        /// <param name="AttachmentId">The attachment identifier.</param>
        /// <returns></returns>
        public string GetSignedURL(string FileName, int AttachmentId)
        {
            IAmazonS3 Client;
            AwsClient awsClientInstance = AwsClient.GetInstance;
            string    response          = string.Empty;

            try
            {
                using (var client = awsClientInstance.GetClient())
                {
                    var Request = new GetPreSignedUrlRequest()
                    {
                        BucketName = AwsClient.awsBucketName,
                        Key        = "Attachment_" + AttachmentId + "/" + FileName,
                        Expires    = DateTime.Now.AddYears(2)
                    };

                    response = client.GetPreSignedURL(Request);
                }
            }
            catch (AmazonS3Exception e)
            {
                response = "Error encountered ***. Message:'{0}' when getting URL" + e.Message;
            }
            return(response);
        }
        public AwsLaunchNewInstanceStep(AwsClient client, InstanceDeploy instance)
        {
            this.client = client;
            this.instance = instance;

            Name = "Launch new instance in Aws";
        }
Exemple #4
0
        /// <summary>
        /// Uploads the files.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="AccessKey">The access key.</param>
        /// <param name="SecretKey">The secret key.</param>
        /// <param name="BucketName">Name of the bucket.</param>
        /// <param name="FileName">Name of the file.</param>
        /// <returns></returns>
        public string Upload(Stream file, string FileName, int AttachmentId)
        {
            string    response = string.Empty;
            IAmazonS3 client;
            AwsClient awsClientInstance = AwsClient.GetInstance;

            try
            {
                using (client = awsClientInstance.GetClient())
                {
                    var request = new PutObjectRequest()
                    {
                        Key         = "Attachment_" + AttachmentId + "/" + FileName,
                        BucketName  = AwsClient.awsBucketName,
                        CannedACL   = S3CannedACL.PublicReadWrite,
                        InputStream = file,
                        //ContentType = "application/zip"
                    };
                    var result = client.PutObjectAsync(request).Result;
                    response = result.HttpStatusCode.ToString();
                };
            }
            catch (AmazonS3Exception ex)
            {
                response = ex.InnerException.Message;
            }
            return(response);
        }
Exemple #5
0
        public ActionResult ExtractFile()
        {
            var textExtractor = new TextExtractor();

            //var result = textExtractor.Extract(@"d:\Downloads\AusTender User Interface Guide V1.13.pdf");

            AwsClient.BucketName = ConfigurationManager.AppSettings["aws:s3:documents_bucket"];
            var fileList = new FileList()
            {
                Files = new List <S3File>()
            };

            var bucketFileList = AwsClient.List("*.*"); // List all files in the bucket

            foreach (var filename in bucketFileList)
            {
                var fileStream = AwsClient.ReadFile(filename);     // Read file stream from S3 file
                var fileBytes  = FormatHelper.convertStreamToByteArray(fileStream);
                var result     = textExtractor.Extract(fileBytes); // Extract file content
                fileList.Files.Add(new S3File()
                {
                    Filename    = filename,
                    ContentType = result.ContentType,
                    MetaData    = (Dictionary <string, string>)result.Metadata,
                    FileContent = result.Text
                });
            }

            return(View(fileList));
        }
 public AwsAssociateElasticIpStep(AwsClient client, Address ipAddress, InstanceDeploy instance)
 {
     this.client = client;
     this.ipAddress = ipAddress;
     this.instance = instance;
     Name = "Associating elastic ip.";
 }
Exemple #7
0
        /// <summary>
        /// Gets the attachment from s3.
        /// </summary>
        /// <param name="AttachmentId">The attachment identifier.</param>
        /// <param name="file">The file.</param>
        /// <returns></returns>
        public byte[] GetAttachmentFromS3(int AttachmentId, Files file)
        {
            byte[]    _byte = null;
            IAmazonS3 client;
            AwsClient awsClientInstance = AwsClient.GetInstance;

            using (client = awsClientInstance.GetClient())
            {
                using (var bytesMemotyStream = new MemoryStream())
                {
                    var request = new GetObjectRequest()
                    {
                        BucketName = AwsClient.awsBucketName,
                        Key        = "Attachment_" + AttachmentId + "/" + file.FileName,
                    };
                    using (GetObjectResponse responsefile = client.GetObjectAsync(request).Result)
                    {
                        using (Stream s = responsefile.ResponseStream)
                        {
                            s.CopyTo(bytesMemotyStream);
                        }

                        return(_byte = bytesMemotyStream.ToArray());
                    }
                }
            }
        }
        public ExportImportReply ExportDatabase(ExportImportRequest request, ILambdaContext ctx)
        {
            processor.Logger = new LambdaLogger(ctx.Logger);
            processor.Logger.Info($"Version : {Version}");
            processor.Logger.Info(JsonTools.Serialize(request));

            string filename = Utils.GetValue(request.FileName, "DefaultExportImportFile", null);

            List <ExportRecord> export = processor.ExportData(request.IncludeSignals);
            AwsClient           client = new AwsClient();
            ZephyrFile          file   = new AwsS3ZephyrFile(client, filename);

            file.Create(true, false);
            file.WriteAllText(JsonTools.Serialize(export, true));

            // Build Reply Message
            ExportImportReply reply = new ExportImportReply();

            reply.Action   = "Export";
            reply.FileName = filename;
            foreach (ExportRecord record in export)
            {
                ExportImportType type = new ExportImportType();
                type.Type  = record.type;
                type.Count = record.records.Count;
                reply.Records.Add(type);
            }

            return(reply);
        }
Exemple #9
0
        public void Logout()
        {
            AwsClient ac = App.Aws;

            if (ac != null && ac.Connected)
            {
                ac.Exit();
            }
        }
Exemple #10
0
        internal override async Task <string> Download(string secretId)
        {
            var request = new model.GetParameterRequest {
                Name = secretId
            };
            var response = await AwsClient.GetParameterAsync(request);

            return(response.Parameter.Value);
        }
Exemple #11
0
        internal override async Task <string> Download(string secretId)
        {
            var request = new GetSecretValueRequest {
                SecretId = secretId
            };
            var response = await AwsClient.GetSecretValueAsync(request);

            return(response.SecretString);
        }
        public override async Task <List <DnsRecordBase> > AwsResolveAsync(DnsQuestion dnsQuestion,
                                                                           List <string> ScanVpcIds, CancellationToken cancellationToken)
        {
            var logger = DnsContextAccessor.DnsContext.Logger;

            using (logger.BeginScope($"{StrategyName} =>"))
            {
                var vpc = await AwsClient.GetRestApisAsync(new GetRestApisRequest(), cancellationToken)
                          .ConfigureAwait(false);

                return(null);
            }
        }
Exemple #13
0
        internal override async Task <string> Download(string secretId)
        {
            if (secretId.IsEmpty())
            {
                throw new ArgumentNullException(nameof(secretId));
            }

            var request = new model.GetParameterRequest {
                Name = secretId
            };
            var response = await AwsClient.GetParameterAsync(request);

            return(response.Parameter.Value);
        }
Exemple #14
0
        /// <summary>
        /// Getfiles the information.
        /// </summary>
        /// <param name="AttachmentId">The attachment identifier.</param>
        public void GetfileInfo(int AttachmentId)
        {
            AwsClient awsClientInstance = AwsClient.GetInstance;
            IAmazonS3 client;

            using (client = awsClientInstance.GetClient())
            {
                var request = new ListObjectsRequest()
                {
                    BucketName = AwsClient.awsBucketName,
                    Prefix     = "Attachment_" + AttachmentId,
                };

                var response = client.ListObjectsAsync(request).Result;
            };
        }
Exemple #15
0
        public void Login(string uuid, string email, string pass)
        {
            WebClient wc = new WebClient("https://api.worxlandroid.com/api/v2/", "nCH3A0WvMYn66vGorjSrnGZ2YtjQWDiCvjg7jNxK");

            if (wc.Login(email, pass, uuid))
            {
                App.Web = wc;
                if (true && wc.States.Count > 0)
                {
                    OnRecv(this, new MyEventArgs(wc.States[0]));
                }
                if (wc.Broker != null && wc.Cert != null && wc.Products != null && wc.Products.Count > 0)
                {
                    LsProductItem pi = wc.Products[0];
                    AwsClient     ac = new AwsClient(wc.Broker, uuid, wc.Cert, pi.Topic.CmdIn, pi.Topic.CmdOut);

                    if (ac.Start())
                    {
                        XamarinApp.App.Aws = ac;
                        DependencyService.Get <IMqttService>().Start();

                        TabbedPage tp = MainPage as TabbedPage;

                        tp.CurrentPage = tp.Children[1];
                    }
                    else
                    {
                        MainPage.DisplayAlert("Alert", "Connect failed see Trace", ":-(");
                    }
                }
                else
                {
                    MainPage.DisplayAlert("Alert", "Login failed see Trace", ":-(");
                }
            }

            JsonConfig x = new JsonConfig {
                Uuid = uuid, Email = email, Password = pass
            };
            DataContractJsonSerializer dcjs = new DataContractJsonSerializer(typeof(JsonConfig));
            FileStream fs = new FileStream(CfgFile, FileMode.Create);

            dcjs.WriteObject(fs, x);
            fs.Close();
        }
        public ExportImportReply ImportDatabase(ExportImportRequest request, ILambdaContext ctx)
        {
            processor.Logger = new LambdaLogger(ctx.Logger);
            processor.Logger.Info($"Version : {Version}");
            processor.Logger.Info(JsonTools.Serialize(request));

            string filename = Utils.GetValue(request.FileName, "DefaultExportImportFile", null);

            AwsClient  client = new AwsClient();
            ZephyrFile file   = new AwsS3ZephyrFile(client, filename);

            file.Open(AccessType.Read, false);
            string importText           = file.ReadAllText();
            List <ExportRecord> records = JsonTools.Deserialize <List <ExportRecord> >(importText);

            processor.ImportData(records, request.IncludeSignals);

            // Build Reply Message
            ExportImportReply reply = new ExportImportReply();

            reply.Action   = "Import";
            reply.FileName = filename;
            foreach (ExportRecord record in records)
            {
                if (!request.IncludeSignals && record.type == "SignalDbRecord")
                {
                    continue;
                }
                ExportImportType type = new ExportImportType();
                type.Type  = record.type;
                type.Count = record.records.Count;
                reply.Records.Add(type);
            }

            return(reply);
        }
 public QueueApiController(ITraceSqsRecordsService traceSqsRecordsService)
 {
     _awsClient = AwsClient.Instance;
     _traceSqsRecordsService = traceSqsRecordsService;
 }
        public static void Main(string[] args)
        {
            /*** Export Database Records ***/
            DynamoDbEngine db        = new DynamoDbEngine();
            Processor      processor = new Processor(db);

            processor.Logger = new ConsoleLogger();

            /*** Export To S3 Bucket ***/
            //List<ExportRecord> export = processor.ExportData(false);
            //AwsClient client = new AwsClient();
            //ZephyrFile file = new AwsS3ZephyrFile(client, "s3://guywaguespack/export.json");
            //file.Create();
            //file.WriteAllText(JsonTools.Serialize(export, true));

            /*** Import From S3 Bucket ***/
            AwsClient  client = new AwsClient();
            ZephyrFile file   = new AwsS3ZephyrFile(client, "s3://guywaguespack/export.json");

            file.Open(AccessType.Read);
            string importText           = file.ReadAllText();
            List <ExportRecord> records = JsonTools.Deserialize <List <ExportRecord> >(importText);

            processor.ImportData(records, false);


            Console.WriteLine("Completed");


            /*** Send Signal Message ***/
            //int signalCount = 1;
            //TextReader reader = new StreamReader(new FileStream(@"/Users/guy/Documents/Source/syntinel.core.net/Syntinel.Tester/TestFiles/Signal-UsingTemplate.json", FileMode.Open));
            //string fileStr = reader.ReadToEnd();
            //Signal signal = JsonConvert.DeserializeObject<Signal>(fileStr);
            //Parallel.For(0, signalCount, index =>
            //{
            //    SignalReply reply = processor.ProcessSignal(signal);
            //    Console.WriteLine($"Status : {reply.StatusCode}");
            //    foreach (SignalStatus status in reply.Results)
            //        Console.WriteLine($"     {status.ChannelId} : {status.Code} - {status.Message}");
            //});


            /*** Send Teams Cue Response ***/
            //int cueCount = 1;
            //TextReader reader = new StreamReader(new FileStream(@"/Users/guy/Documents/Source/syntinel.core.net/Syntinel.Tester/TestFiles/Cue-Teams.json", FileMode.Open));
            //string fileStr = reader.ReadToEnd();
            //Dictionary<string, object> reply = JsonConvert.DeserializeObject<Dictionary<string, object>>(fileStr);
            //Cue cue = Teams.CreateCue(reply);
            //Parallel.For(0, cueCount, index =>
            // {
            //     string num = $"{index}".PadLeft(4, '0');
            //     CueReply cueReply = processor.ReceiveCue(cue);
            //     Console.WriteLine($"{num} - {JsonTools.Serialize(cueReply)}");
            // });


            /*** Stress Test Status Messages ***/
            //int statusCount = 1;
            //string signalId = "000000000";
            //string actionId = "0ZC6BJ28Z";

            //Parallel.For(1, statusCount, index =>
            //{
            //    Status status = new Status();
            //    status.Id = signalId;
            //    status.ActionId = actionId;
            //    status.NewStatus = StatusType.InProgress;
            //    string num = $"{index}".PadLeft(4, '0');
            //    status.Message = $"Message {num}";
            //    StatusReply reply = processor.ProcessStatus(status);
            //    Console.WriteLine($"{num} - {reply.StatusCode}");
            //});

            //Status status = new Status();
            //status.Id = signalId;
            //status.ActionId = actionId;
            //status.Message = "Last Message";
            //status.NewStatus = StatusType.Completed;
            //status.SendToChannels = false;
            //processor.ProcessStatus(status);


            /*** Test Syntinel.Version ***/
            //string[] vArgs = { "/Users/guy/Documents/Source/syntinel.core.net/Syntinel.Aws" };
            //Syntinel.Version.Program.Main(vArgs);
        }
 public AwsCheckTheStateStep(AwsClient awsClient, InstanceDeploy instance)
 {
     this.awsClient = awsClient;
     this.instance = instance;
     Name = "Checking instance state.";
 }
 public AwsTerminateInstanceStep(AwsClient awsClient, InstanceDeploy instance)
 {
     this.awsClient = awsClient;
     this.instance = instance;
     Name = "Stopping aws instance.";
 }