public S3Access() { S3Config = new AmazonS3Config(); RegionEndpoint bucketRegion = RegionEndpoint.GetBySystemName(EnvironmentHandler.GetEnvironmentHandler().GetVariable("BucketRegion")); S3Config.RegionEndpoint = bucketRegion; S3Client = new MyAmazonS3Client(S3Config); }
/// <summary> /// Entry point for the BlogPost Handler. /// </summary> /// <param name="blogPost">The Incoming BlogPost</param> /// <param name="context">The Lambda event context</param> /// <returns></returns> public BlogPost FunctionHandler(BlogPost blogPost, ILambdaContext context) { // not using a separate logic layer because this _is_ the logic layer LambdaLogger.Log("BlogPostHandler Lambda Started"); // Config/Initialization EnvironmentHandler env = EnvironmentHandler.GetEnvironmentHandler(); string bucketName = env.GetVariable("BucketName"); string bucketRegionString = env.GetVariable("BucketRegion"); string postsDirectory = env.GetVariable("PostsDirectory"); string imagesDirectory = env.GetVariable("ImagesDirectory"); string metaDirectory = env.GetVariable("MetaDirectory"); // get blog post BlogPostS3Access blogPostAccess = new BlogPostS3Access(bucketName, bucketRegionString); blogPostAccess.Logger = context.Logger; var blogPostResponse = blogPostAccess.GetBlogPost(blogPost); blogPostResponse.Wait(); blogPost = blogPostResponse.Result; if (blogPost.Metadata != null) { // get related posts TagFileS3Access tagFileAccess = new TagFileS3Access(); tagFileAccess.Logger = context.Logger; var relatedPostsResponse = tagFileAccess.GetBlogPostIdsFromTags(blogPost.Metadata.Tags); relatedPostsResponse.Wait(); blogPost.RelatedPosts = relatedPostsResponse.Result; // remove all related posts which are the current post blogPost.RelatedPosts.RemoveAll(b => b.Id == blogPost.Id); // populate related posts objects for (int i = 0; i < blogPost.RelatedPosts.Count; i++) { var relatedPostResponse = blogPostAccess.GetBlogPost(blogPost.RelatedPosts[i]); relatedPostResponse.Wait(); blogPost.RelatedPosts[i] = relatedPostResponse.Result; // remove Markdown identifiers in the teaser content text, as it shows up // as a related post blogPost.RelatedPosts[i].Content = StringHelper.StripMarkdownIdentifiers(blogPost.RelatedPosts[i].Content); } } else { return(null); } return(blogPost); }
public void SanityTest_IdOfOne_ReturnsTrue() { // Invoke the lambda function and confirm the string was upper cased. var function = new Function(); var context = new TestLambdaContext(); EnvironmentHandler.GetEnvironmentHandler().SetVariable("bucketRegion", "test"); EnvironmentHandler.GetEnvironmentHandler().SetVariable("BucketName", "test"); EnvironmentHandler.GetEnvironmentHandler().SetVariable("BucketRegion", "test"); EnvironmentHandler.GetEnvironmentHandler().SetVariable("PostsDirectory", "test"); EnvironmentHandler.GetEnvironmentHandler().SetVariable("ImagesDirectory", "test"); EnvironmentHandler.GetEnvironmentHandler().SetVariable("MetaDirectory", "test"); var idOfOne = function.FunctionHandler(new BlogPost(1), context); Assert.AreEqual(idOfOne, new BlogPost(1)); }
public async Task <BlogPost> GetBlogPost(BlogPost blogPost) { var environmentHandler = EnvironmentHandler.GetEnvironmentHandler(); // get post contents string keyName = blogPost.Id.ToString(); var content = await GetBlogPostContent(blogPost, environmentHandler.GetVariable("PostsDirectory"), keyName); //TODO remove keyName since its the id of the blogpost blogPost.Content = content; // get post metadata var metadata = await GetBlogPostMetadata(blogPost, environmentHandler.GetVariable("MetaDirectory"), keyName); blogPost.Metadata = metadata; return(blogPost); }
// what is the wisdom of my base object retrieval class getting things as strings? public virtual async Task <TagFile> GetTagFile() { // use GetObject to retrieve the TagFile string tagFileContents = await GetObject(new GetObjectRequest { BucketName = EnvironmentHandler.GetEnvironmentHandler().GetVariable("BucketName"), Key = TagFileS3Access.TagFileName }); // parse string into TagFile // each line is one entry string[] lines = tagFileContents.Split("\n", StringSplitOptions.RemoveEmptyEntries); if (tagFileContents == string.Empty) { throw new TagFileException("Exception - Empty TagFile."); } TagFile tagFile = new TagFile(); for (int i = 0; i < lines.Length; i++) { var line = lines[i]; // parse each line - split on '-'; LHS is tag, RHS is array of ids string[] lineContents = line.Split('-'); if (lineContents.Length != 2) { throw new TagFileException($"there is an issue with tagfile format on line {i}."); } List <string> ids = lineContents[1].Split(',').ToList(); tagFile.AddEntry(lineContents[0], new SortedSet <string>(ids)); } return(tagFile); }