public async Task WriteAuditRecord(string resourceType, CloudStorageAccount storageAccount) { var entry = new AuditEntry( this, await AuditActor.GetCurrentMachineActor()); // Write the blob to the storage account var client = storageAccount.CreateCloudBlobClient(); var container = client.GetContainerReference("auditing"); await container.CreateIfNotExistsAsync(); var blob = container.GetBlockBlobReference( resourceType + "/" + this.GetPath() + "/" + DateTime.UtcNow.ToString("s") + "-" + this.GetAction().ToLowerInvariant() + ".audit.v1.json"); if (await blob.ExistsAsync()) { throw new InvalidOperationException(String.Format( CultureInfo.CurrentCulture, Strings.Package_DeleteCommand_AuditBlobExists, blob.Uri.AbsoluteUri)); } byte[] data = Encoding.UTF8.GetBytes( JsonFormat.Serialize(entry)); await blob.UploadFromByteArrayAsync(data, 0, data.Length); }
public static async Task <CloudBlockBlob> UploadJsonBlob(this CloudBlobContainer self, string path, object content) { CloudBlockBlob blob = null; try { blob = self.GetBlockBlobReference(path); blob.Properties.ContentType = "application/json"; await blob.UploadTextAsync(JsonFormat.Serialize(content)); } catch (StorageException stex) { if (stex.RequestInformation != null && stex.RequestInformation.ExtendedErrorInformation != null && (stex.RequestInformation.ExtendedErrorInformation.ErrorCode == BlobErrorCodeStrings.ContainerNotFound || stex.RequestInformation.ExtendedErrorInformation.ErrorCode == BlobErrorCodeStrings.BlobNotFound)) { // Ignore the error } else { throw; } } return(blob); }
public override async Task <SecretStore> Create(string store, IEnumerable <string> allowedUsers) { // Create the root folder if it does not exist if (!Directory.Exists(_rootFolder)) { Directory.CreateDirectory(_rootFolder); } // Check if there is already a secret store here string storeDirectory = Path.Combine(_rootFolder, store); if (Directory.Exists(storeDirectory)) { throw new InvalidOperationException(String.Format( CultureInfo.CurrentCulture, Strings.DpapiSecretStoreProvider_StoreExists, store)); } Directory.CreateDirectory(storeDirectory); // Create the directory and the metadata file string metadataFile = Path.Combine(storeDirectory, "metadata.v1.pjson"); var metadata = new SecretStoreMetadata() { AllowedUsers = allowedUsers, Datacenter = store }; // Encrypt and Save it! var protector = CreateProtector(allowedUsers, MetadataPurpose); await WriteSecretFile(metadataFile, JsonFormat.Serialize(metadata), protector); return(new DpapiSecretStore(storeDirectory, metadata)); }
private Task UnauditedWriteSecret(Secret secret) { // Generate the name of the file string secretFile = GetFileName(secret.Name); // Write the file var protector = CreateProtector(secret.Name); return(DpapiSecretStoreProvider.WriteSecretFile(secretFile, JsonFormat.Serialize(secret), protector)); }
public async Task StoreToken(AzureToken token) { string dir = Path.Combine(_root, "Subscriptions"); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string path = Path.Combine(dir, token.SubscriptionId + ".dat"); string content = JsonFormat.Serialize(token); var protectedData = Convert.ToBase64String( ProtectedData.Protect( Encoding.UTF8.GetBytes(content), null, DataProtectionScope.CurrentUser)); using (var writer = new StreamWriter(path)) { await writer.WriteAsync(protectedData); } }
private static async Task WriteJson(IOwinContext context, object value) { context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.ContentType = "application/json"; await context.Response.WriteAsync(JsonFormat.Serialize(value)); }
protected override async Task OnExecute(SubscriptionCloudCredentials credentials) { if (!String.IsNullOrEmpty(EncodedPayload)) { Payload = Encoding.UTF8.GetString(Convert.FromBase64String(EncodedPayload)); } if (ServiceUri == null) { await Console.WriteErrorLine(Strings.ParameterRequired, "SerivceUri"); } else { Dictionary <string, string> payload = null; if (!String.IsNullOrEmpty(Payload)) { payload = InvocationPayloadSerializer.Deserialize(Payload); } var bodyValue = new InvocationRequest( Job, "Scheduler", payload) { JobInstanceName = InstanceName, UnlessAlreadyRunning = Singleton }; var body = JsonFormat.Serialize(bodyValue); var request = new JobCreateOrUpdateParameters() { StartTime = StartTime, Action = new JobAction() { Type = JobActionType.Https, Request = new JobHttpRequest() { Uri = new Uri(ServiceUri, "work/invocations"), Method = "PUT", Body = body, Headers = new Dictionary <string, string>() { { "Content-Type", "application/json" }, { "Authorization", GenerateAuthHeader(Password) } } } // TODO: Retry Policy }, Recurrence = new JobRecurrence() { Count = Count, EndTime = EndTime, Frequency = Frequency, Interval = Interval // TODO: Schedule field? } }; using (var client = CloudContext.Clients.CreateSchedulerClient(credentials, CloudService, Collection)) { await Console.WriteInfoLine(Strings.Scheduler_NewJobCommand_CreatingJob, Job, CloudService, Collection); if (WhatIf) { await Console.WriteInfoLine(Strings.Scheduler_NewJobCommand_WouldCreateJob, JsonConvert.SerializeObject(request, new JsonSerializerSettings() { Formatting = Formatting.Indented, ContractResolver = new CamelCasePropertyNamesContractResolver() })); } else { var response = await client.Jobs.CreateOrUpdateAsync(InstanceName, request, CancellationToken.None); await Console.WriteObject(response.Job); } await Console.WriteInfoLine(Strings.Scheduler_NewJobCommand_CreatedJob, Job, CloudService, Collection); } } }