public WebsiteStack() { // Create an AWS resource (S3 Bucket) var bucket = new Bucket("my-bucket", new BucketArgs { Website = new BucketWebsiteArgs { IndexDocument = "index.html" } }); // For each file in wwwroot ... var files = Directory.GetFiles("wwwroot"); foreach (var file in files) { var name = file.Substring(8); var contentType = MimeTypes.GetMimeType(file); // ... create a bucket object var bucketObject = new BucketObject(name, new BucketObjectArgs { Acl = "public-read", Bucket = bucket.BucketName, ContentType = contentType, Source = new FileAsset(file) }, new CustomResourceOptions { Parent = bucket }); } this.Endpoint = Output.Format($"http://{bucket.WebsiteEndpoint}"); }
public async Task <BucketObject> GetBucketObject(string bucketKey, string objectKey) { BucketObject obj = null; client.BaseUrl = new Uri( $"https://developer.api.autodesk.com/oss/v2/buckets/{bucketKey}/objects/{objectKey}/details"); request = new RestRequest(Method.GET); request.AddHeader("Authorization", $"{this.token.TokenType} {this.token.AccessToken}"). AddHeader("Content-Type", "application/json"); IRestResponse response = await client.ExecuteTaskAsync(request); Dictionary <string, dynamic> data = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(response.Content); if (data.Count != 0) { try { obj = new BucketObject(data["bucketKey"], data["objectId"], data["objectKey"], (long)data["size"], data["location"]); } catch { obj = null; } } return(obj); }
static Task <int> Main() => Deployment.RunAsync(() => { var config = new Config("hello-dotnet"); var name = config.Require("name"); // Create the bucket, and make it public. var bucket = new Bucket(name, new BucketArgs { Acl = "public-read" }); // Add some content. var content = new BucketObject($"{name}-content", new BucketObjectArgs { Acl = "public-read", Bucket = bucket.Id, ContentType = "text/plain; charset=utf8", Key = "hello.txt", Source = new StringAsset("Made with ❤, Pulumi, and .NET"), }); // Return some values that will become the Outputs of the stack. return(new Dictionary <string, object> { { "hello", "world" }, { "bucket-id", bucket.Id }, { "content-id", content.Id }, { "object-url", Output.Format($"http://{bucket.BucketDomainName}/{content.Key}") }, }); });
static Task <int> Main() { return(Deployment.RunAsync(() => { var bucket = new Bucket("bucket"); var bucketObject = new BucketObject("python-zip", new BucketObjectArgs { Bucket = bucket.Name, Source = new FileArchive("./pythonfunc") }); var function = new Function("python-func", new FunctionArgs { SourceArchiveBucket = bucket.Name, Runtime = "python37", SourceArchiveObject = bucketObject.Name, EntryPoint = "handler", TriggerHttp = true, AvailableMemoryMb = 128 }); // Export the URL of the function return new Dictionary <string, object> { { "pythonEndpoint", function.HttpsTriggerUrl }, }; })); }
public FunctionsStack() { var bucket = new Bucket("bucket"); var bucketObject = new BucketObject("python-zip", new BucketObjectArgs { Bucket = bucket.Name, Source = new FileArchive("./pythonfunc") }); var function = new Function("python-func", new FunctionArgs { SourceArchiveBucket = bucket.Name, Runtime = "python37", SourceArchiveObject = bucketObject.Name, EntryPoint = "handler", TriggerHttp = true, AvailableMemoryMb = 128 }); var invoker = new FunctionIamMember("invoker", new FunctionIamMemberArgs { Project = function.Project, Region = function.Region, CloudFunction = function.Name, Role = "roles/cloudfunctions.invoker", Member = "allUsers" }); // Export the URL of the function this.PythonEndpoint = function.HttpsTriggerUrl; }
public async Task <List <BucketObject> > GetAllObjects(string bucketKey) { List <BucketObject> objects = new List <BucketObject>(); client.BaseUrl = new Uri($"https://developer.api.autodesk.com/oss/v2/buckets/{bucketKey}/objects"); request = new RestRequest(Method.GET); request.AddHeader("Authorization", $"{this.token.TokenType} {this.token.AccessToken}"). AddHeader("Content-Type", "application/json"); IRestResponse response = await client.ExecuteTaskAsync(request); if (response.StatusCode != HttpStatusCode.OK) { string error = ""; switch (response.StatusCode) { case HttpStatusCode.BadRequest: error = "The request could not be understood by the server due to malformed syntax or missing request headers. The client SHOULD NOT repeat the request without modifications. The response body may give an indication of what is wrong with the request."; break; case HttpStatusCode.Unauthorized: error = "The supplied Authorization header was not valid or the supplied token scope was not acceptable. Verify Authentication and try again."; break; case HttpStatusCode.Forbidden: error = "The Authorization was successfully validated but permission is not granted. Don’t try again unless you solve permissions first."; break; case HttpStatusCode.NotFound: error = "The bucket does not exist."; break; case HttpStatusCode.InternalServerError: error = "Internal failure while processing the request, reason depends on error."; break; default: error = "Unknown error occurred."; break; } ErrorOccurred?.Invoke(error); return(null); } JObject items = JObject.Parse(response.Content); Dictionary <string, dynamic> data; foreach (dynamic key in items["items"]) { data = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(key.ToString()); BucketObject bucketObject = await this.GetBucketObject(data["bucketKey"], data["objectKey"]); objects.Add(bucketObject); data = null; } return(objects); }
public static async Task <bool> CreateBucket(BucketObject bucketObject) { #if MOCK return(await Task.FromResult(true)); #else var bucketManager = new BucketManager(_currentMac, _config); var queryResult = await Task.Factory.StartNew(() => bucketManager.Create(bucketObject.Name, bucketObject.Region)); return(queryResult.Code == 200); #endif }
static Task <int> Main() { return(Deployment.RunAsync(() => { var pubsub = new Topic("test-topic"); // A Cloud Scheduler job cannot be created without an App Engine instance. Not sure why, // but the error message is very explicit var appEngine = new Application("dummy-app", new ApplicationArgs { LocationId = "europe-west" }); // Pubsub topic message must contain data otherwise you get the following error: // "Pubsub message must contain either non-empty data, or at least one attribute." var scheduler = new Job("function-trigger", new JobArgs { PubsubTarget = new JobPubsubTargetArgs { TopicName = pubsub.Id, Data = "MQ==" // This is "1" encoded in base64 }, TimeZone = "UTC", Schedule = "0 9 * * *" }); var bucket = new Bucket("bucket"); var bucketObject = new BucketObject("python-zip", new BucketObjectArgs { Bucket = bucket.Name, Source = new FileArchive("./pythonfunc") }); var function = new Function("python-func", new FunctionArgs { SourceArchiveBucket = bucket.Name, Runtime = "python37", SourceArchiveObject = bucketObject.Name, EntryPoint = "handler", EventTrigger = new FunctionEventTriggerArgs { EventType = "providers/cloud.pubsub/eventTypes/topic.publish", Resource = pubsub.Name }, AvailableMemoryMb = 128 }); // Export the URL of the function return new Dictionary <string, object> { { "pythonEndpoint", function.HttpsTriggerUrl }, }; })); }
static Task <int> Main() { return(Deployment.RunAsync(() => { var bucket = new Bucket("bucket"); var bucketObject = new BucketObject("python-zip", new BucketObjectArgs { Bucket = bucket.Name, Source = new FileArchive("./pythonfunc") }); var function = new Function("python-func", new FunctionArgs { SourceArchiveBucket = bucket.Name, Runtime = "python37", SourceArchiveObject = bucketObject.Name, EntryPoint = "handler", TriggerHttp = true, AvailableMemoryMb = 128 }); var invoker = new FunctionIamMember("invoker", new FunctionIamMemberArgs { Project = function.Project, Region = function.Region, CloudFunction = function.Name, Role = "roles/cloudfunctions.invoker", Member = "allUsers", }); // Export the URL of the function return new Dictionary <string, object> { { "url", function.HttpsTriggerUrl }, }; })); }
public FunctionsStack() { var bucket = new Bucket("bucket"); var bucketObject = new BucketObject("python-zip", new BucketObjectArgs { Bucket = bucket.Name, Source = new FileArchive("./pythonfunc") }); var function = new Function("python-func", new FunctionArgs { SourceArchiveBucket = bucket.Name, Runtime = "python37", SourceArchiveObject = bucketObject.Name, EntryPoint = "handler", TriggerHttp = true, AvailableMemoryMb = 128 }); // Export the URL of the function this.PythonEndpoint = function.HttpsTriggerUrl; }
public async Task ImportObjectInternalAsync(StockMarket sourceBucketType, string objectKey, char csvSeperator, CancellationToken cancellationToken) { var objectID = this.encryptionService.GetBucketObjectHash(sourceBucketType, objectKey); var bucketName = this.GetBucketName(sourceBucketType); var bucketObject = await this.repository.GetItemAsync <BucketObject>(objectID, cancellationToken); if (bucketObject == null) { var objectMetaData = await amazonS3.GetObjectMetadataAsync(bucketName, objectKey, cancellationToken); bucketObject = new BucketObject { ObjectID = objectID, ObjectKey = objectKey, SourceBucketType = (int)sourceBucketType, Status = (int)BucketObjectStatus.Detected, ObjectSize = objectMetaData.Headers.ContentLength, CurrentStatusErrorCount = 0, CurrentStatusLastError = null, VersionNumber = null }; } if (bucketObject.Status > (int)BucketObjectStatus.Queued) { return; } bucketObject.Status = (int)BucketObjectStatus.Processing; await this.repository.SaveItemAsync(bucketObject, cancellationToken); try { var objectStream = await amazonS3.GetObjectStreamAsync(bucketName, objectKey, null, cancellationToken); var enumerable = csvConverter.Convert <TradeActivity>(objectStream, csvSeperator); using (var bae = new BufferedAsyncEnumerable <TradeActivity>(enumerable, CumulusConstants.DynamoDbBatchWriteSize)) { while (await bae.MoveNextAsync()) { await productService.SaveTraceActivityCollectionAsync(bae.Current, cancellationToken); } } bucketObject.Status = (int)BucketObjectStatus.Processed; } catch (Exception exception) { bucketObject.CurrentStatusLastError = exception.Message; bucketObject.CurrentStatusErrorCount++; throw; } finally { await this.repository.SaveItemAsync(bucketObject, cancellationToken); } }
public CreateBucketPageViewModel() { BucketObject = new BucketObject(); CreateCommand = new RelayCommand(async() => await CreateCommandExecute()); CancelCommand = new RelayCommand(CancelCommandExecute); }