示例#1
0
 public HomeController(IConfiguration configuration)
 {
     _configuration = configuration;
     AWSSDKHandler.RegisterXRayForAllServices();
 }
 /// <summary>
 /// Default Constructor
 /// </summary>
 public Function()
 {
     AWSSDKHandler.RegisterXRayForAllServices();
     _incidentRepository = new IncidentRepository(Environment.GetEnvironmentVariable("TABLE_NAME"));
 }
 /// <summary>
 /// Constructor used for testing purposes
 /// </summary>
 /// <param name="ddbClient">Instance of DynamoDB client</param>
 /// <param name="tablename">DynamoDB table name</param>
 public Function(IAmazonDynamoDB ddbClient, string tablename)
 {
     AWSSDKHandler.RegisterXRayForAllServices();
     _incidentRepository = new IncidentRepository(ddbClient, tablename);
 }
示例#4
0
 public Function()
 {
     AWSSDKHandler.RegisterXRayForAllServices();
     _logger = CreateLogger();
     _config = BuildConfiguration();
 }
 public Function(IIncidentRepository incidentRepository)
 {
     _incidentRepository = incidentRepository;
     AWSSDKHandler.RegisterXRayForAllServices();
 }
示例#6
0
        public static BudgetDetail GetApiBudget(string accessToken, string userId)
        {
            AWSSDKHandler.RegisterXRayForAllServices();
            AWSXRayRecorder.Instance.BeginSubsegment("MyBudgetExplorer.Models.Cache.GetApiBudget()");
            try
            {
                var binaryFormatter = new BinaryFormatter();
                var aesKey          = SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(userId));
                var aesIV           = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(userId));
                var hash            = BitConverter.ToString(aesKey).Replace("-", "").ToLower();
                var fileName        = $"budget.{hash}";
                var tempFilePath    = Path.Combine(Path.GetTempPath(), fileName);

                BudgetDetail budget    = null;
                byte[]       encrypted = null;

                var api        = new YnabApi(accessToken);
                var tempBudget = api.GetBudget();
                budget = tempBudget.Data.Budget;
                budget.LastModifiedOn = DateTime.UtcNow;

                using (var ms = new MemoryStream())
                {
                    binaryFormatter.Serialize(ms, budget);
                    encrypted = EncryptAES(ms.ToArray(), aesKey, aesIV);
                }

                // Store S3 File
                if (!string.IsNullOrWhiteSpace(awsAccessKey) && !string.IsNullOrWhiteSpace(awsSecretKey))
                {
                    using (IAmazonS3 client = new AmazonS3Client(awsAccessKey, awsSecretKey, RegionEndpoint.USEast2))
                    {
                        using (var ms = new MemoryStream(encrypted))
                        {
                            var putrequest = new PutObjectRequest
                            {
                                BucketName  = bucketName,
                                Key         = fileName,
                                InputStream = ms
                            };

                            client.PutObjectAsync(putrequest).Wait();
                        }
                    }
                }

                // Store Local File
                if (encrypted != null && encrypted.Length > 0)
                {
                    File.WriteAllBytes(tempFilePath, encrypted);
                    File.SetCreationTimeUtc(tempFilePath, budget.LastModifiedOn);
                    File.SetLastWriteTimeUtc(tempFilePath, budget.LastModifiedOn);
                }

                return(budget);
            }
            finally
            {
                AWSXRayRecorder.Instance.EndSubsegment();
            }
        }
示例#7
0
 public Function()
 {
     AWSSDKHandler.RegisterXRayForAllServices();
 }
示例#8
0
 public Function()
 {
     AWSSDKHandler.RegisterXRayForAllServices();
     _client     = new AmazonDynamoDBClient(RegionEndpoint.APSoutheast2);
     _table_name = Environment.GetEnvironmentVariable("TABLE_NAME");
 }
示例#9
0
 public Function()
 {
     AWSSDKHandler.RegisterXRayForAllServices();
     _client   = new AmazonSimpleNotificationServiceClient(RegionEndpoint.APSoutheast2);
     _topicArn = Environment.GetEnvironmentVariable("TOPIC_ARN");
 }
示例#10
0
 static WorkerEntryPoint()
 {
     AWSSDKHandler.RegisterXRayForAllServices();
 }
示例#11
0
 public Startup(IConfiguration configuration)
 {
     AWSXRayRecorder.InitializeInstance(configuration: Configuration); // Inititalizing Configuration object with X-Ray recorder
     AWSSDKHandler.RegisterXRayForAllServices();                       // All AWS SDK requests will be traced
 }
示例#12
0
 // Lambda constructor
 public LambdaFunctionBase() : this(GetRegionEndpoint(), GetEnvironment())
 {
     AWSSDKHandler.RegisterXRayForAllServices();
 }
 public Startup(IConfiguration configuration)
 {
     Configuration = configuration;
     AWSXRayRecorder.InitializeInstance(configuration);
     AWSSDKHandler.RegisterXRayForAllServices();
 }
示例#14
0
 public Function()
 {
     AWSSDKHandler.RegisterXRayForAllServices();
     _simpleNotificationService = new AmazonSimpleNotificationServiceClient();
     _topicArn = Environment.GetEnvironmentVariable("TOPIC_ARN");
 }
示例#15
0
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;

            AWSSDKHandler.RegisterXRayForAllServices();
        }
 /// <summary>
 /// This function sets up the logging/tracing
 /// </summary>
 private void initFunction()
 {
     AWSSDKHandler.RegisterXRayForAllServices();
 }
示例#17
0
        public static BudgetDetail GetS3Budget(string userId)
        {
            AWSSDKHandler.RegisterXRayForAllServices();
            AWSXRayRecorder.Instance.BeginSubsegment("MyBudgetExplorer.Models.Cache.GetS3Budget()");
            try
            {
                if (string.IsNullOrWhiteSpace(awsAccessKey) || string.IsNullOrWhiteSpace(awsSecretKey))
                {
                    return(null);
                }

                var binaryFormatter = new BinaryFormatter();
                var aesKey          = SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(userId));
                var aesIV           = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(userId));
                var hash            = BitConverter.ToString(aesKey).Replace("-", "").ToLower();
                var fileName        = $"budget.{hash}";
                var tempFilePath    = Path.Combine(Path.GetTempPath(), fileName);

                BudgetDetail budget = null;
                using (IAmazonS3 client = new AmazonS3Client(awsAccessKey, awsSecretKey, RegionEndpoint.USEast2))
                {
                    byte[]           encrypted = null;
                    GetObjectRequest request   = new GetObjectRequest
                    {
                        BucketName = bucketName,
                        Key        = fileName
                    };
                    try
                    {
                        using (GetObjectResponse response = client.GetObjectAsync(request).Result)
                        {
                            byte[] buffer = new byte[128 * 1024];
                            using (MemoryStream ms = new MemoryStream())
                            {
                                int read;
                                while ((read = response.ResponseStream.Read(buffer, 0, buffer.Length)) > 0)
                                {
                                    ms.Write(buffer, 0, read);
                                }
                                encrypted = ms.ToArray();
                            }
                        }

                        var decrypted = DecryptAES(encrypted, aesKey, aesIV);
                        using (var ms = new MemoryStream(decrypted))
                        {
                            budget = (BudgetDetail)binaryFormatter.Deserialize(ms);
                        }

                        if (encrypted != null && encrypted.Length > 0)
                        {
                            File.WriteAllBytes(tempFilePath, encrypted);
                            File.SetCreationTimeUtc(tempFilePath, budget.LastModifiedOn);
                            File.SetLastWriteTimeUtc(tempFilePath, budget.LastModifiedOn);
                        }
                    }
                    catch
                    {
                    }

                    return(budget);
                }
            }
            finally
            {
                AWSXRayRecorder.Instance.EndSubsegment();
            }
        }
示例#18
0
 public Function()
 {
     AWSXRayRecorder.InitializeInstance();
     AWSSDKHandler.RegisterXRayForAllServices();
 }
示例#19
0
 public ChatFunctions()
 {
     AWSSDKHandler.RegisterXRayForAllServices();
     _serviceProvider = ChatDependencyContainerBuilder.Build();
 }
 public ScoringWorker() : this(lambdaLogger => new LambdaLogWriterFactory(lambdaLogger), new ScoringDependencies())
 {
     AWSSDKHandler.RegisterXRayForAllServices();
 }
示例#21
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy("AllowAllOrigins", builder => {
                    builder.AllowAnyOrigin();
                    builder.AllowAnyHeader();
                    builder.AllowAnyMethod();
                    builder.AllowCredentials();
                });
            });

            // Add cognito group authorization requirements for SiteAdmin and RegisteredUser
            services.AddAuthorization(
                options =>
            {
                options.AddPolicy("IsSiteAdmin", policy => policy.Requirements.Add(new CognitoGroupAuthorizationRequirement("SiteAdmin")));
                options.AddPolicy("IsRegisteredUser", policy => policy.Requirements.Add(new CognitoGroupAuthorizationRequirement("RegisteredUser")));
            }
                );

            services.AddSingleton <IXmlRepository, DdbXmlRepository>();

            services.AddDistributedDynamoDbCache(o => {
                o.TableName   = "TechSummitSessionState";
                o.IdleTimeout = TimeSpan.FromMinutes(30);
            });

            services.AddSession(o => {
                o.IdleTimeout     = TimeSpan.FromMinutes(30);
                o.Cookie.HttpOnly = true;
            });

            services.AddAuthentication(options => options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.Audience             = "288seubnkumcdnj3odpftsvbjl";
                options.Authority            = "https://cognito-idp.us-west-2.amazonaws.com/us-west-2_megh2msxd";
                options.RequireHttpsMetadata = false;       //set this to true for prod environments!
                options.SaveToken            = true;
            });

            // Add a single instance (singleton) of the cognito authorization handler
            services.AddSingleton <IAuthorizationHandler, CognitoGroupAuthorizationHandler>();

            //configure XRay, and register all AWS service calls to be traced
            AWSXRayRecorder.InitializeInstance(Configuration); // pass IConfiguration object that reads appsettings.json file
            AWSSDKHandler.RegisterXRayForAllServices();

            //add DynamoDB and SSM to DI
            services.AddAWSService <IAmazonDynamoDB>();
            //services.AddAWSService<IAmazonSimpleSystemsManagement>(); // only required if using ParameterStore to store keys (PsXmlRepository)

            services.AddMvc();
            services.AddDefaultAWSOptions(Configuration.GetAWSOptions());

            //Explicitly set the DataProtection middleware to store cookie encryption keys in DynamoDB
            var sp = services.BuildServiceProvider();

            services.AddDataProtection().AddKeyManagementOptions(o => o.XmlRepository = sp.GetService <IXmlRepository>());

            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("docs", new Info {
                    Title = "re:Invent WIN401 Cart API", Version = "v1"
                });
            });
        }
        protected BaseFunction()
        {
            AWSSDKHandler.RegisterXRayForAllServices();

            _handler = CreateHandler(LambdaConfig.CreateSender());
        }