Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #39 from xpouyat/dev
Browse files Browse the repository at this point in the history
Release of v1.2 of the SDK
  • Loading branch information
xpouyat authored Mar 6, 2024
2 parents 1d5065e + 32878da commit e37a14a
Show file tree
Hide file tree
Showing 73 changed files with 1,368 additions and 567 deletions.
9 changes: 5 additions & 4 deletions MK.IO/Asset/AssetsOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ public async Task<AssetSchema> GetAsync(string assetName)
}

/// <inheritdoc/>
public AssetSchema CreateOrUpdate(string assetName, string containerName, string storageName, string? description = null)
public AssetSchema CreateOrUpdate(string assetName, string containerName, string storageName, string? description = null, AssetContainerDeletionPolicyType containerDeletionPolicy = AssetContainerDeletionPolicyType.Retain)
{
Task<AssetSchema> task = Task.Run(async () => await CreateOrUpdateAsync(assetName, containerName, storageName, description));
Task<AssetSchema> task = Task.Run(async () => await CreateOrUpdateAsync(assetName, containerName, storageName, description, containerDeletionPolicy));
return task.GetAwaiter().GetResult();
}

/// <inheritdoc/>
public async Task<AssetSchema> CreateOrUpdateAsync(string assetName, string containerName, string storageName, string? description = null)
public async Task<AssetSchema> CreateOrUpdateAsync(string assetName, string containerName, string storageName, string? description = null, AssetContainerDeletionPolicyType containerDeletionPolicy = AssetContainerDeletionPolicyType.Retain)
{
Argument.AssertNotNullOrEmpty(assetName, nameof(assetName));
Argument.AssertNotNullOrEmpty(containerName, nameof(containerName));
Expand All @@ -156,7 +156,8 @@ public async Task<AssetSchema> CreateOrUpdateAsync(string assetName, string cont
{
Container = containerName,
Description = description!,
StorageAccountName = storageName
StorageAccountName = storageName,
ContainerDeletionPolicy = containerDeletionPolicy
}
};

Expand Down
4 changes: 2 additions & 2 deletions MK.IO/Asset/IAssetsOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public interface IAssetsOperations
/// <param name="storageName"></param>
/// <param name="description"></param>
/// <returns></returns>
AssetSchema CreateOrUpdate(string assetName, string containerName, string storageName, string? description = null);
AssetSchema CreateOrUpdate(string assetName, string containerName, string storageName, string? description = null, AssetContainerDeletionPolicyType containerDeletionPolicy = AssetContainerDeletionPolicyType.Retain);

/// <summary>
/// Create or Update Asset.
Expand All @@ -107,7 +107,7 @@ public interface IAssetsOperations
/// <param name="storageName"></param>
/// <param name="description"></param>
/// <returns></returns>
Task<AssetSchema> CreateOrUpdateAsync(string assetName, string containerName, string storageName, string? description = null);
Task<AssetSchema> CreateOrUpdateAsync(string assetName, string containerName, string storageName, string? description = null, AssetContainerDeletionPolicyType containerDeletionPolicy = AssetContainerDeletionPolicyType.Retain);

/// <summary>
/// List Streaming Locators for Asset. This API call is a convenience method to retrieve
Expand Down
29 changes: 29 additions & 0 deletions MK.IO/Asset/Models/AssetContainerDeletionPolicyType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Runtime.Serialization;

namespace MK.IO
{
/// <summary>
/// Deletion Policy type.
/// </summary>
/// <value>Deletion Policy type.</value>
[JsonConverter(typeof(StringEnumConverter))]
public enum AssetContainerDeletionPolicyType
{
/// <summary>
/// A deletion policy of 'Retain' will leave the content in-place in your storage account.
/// </summary>
[EnumMember(Value = "Retain")]
Retain,

/// <summary>
/// A deletion policy of 'Delete' will result in the associated storage container and all its contents being removed from storage.
/// </summary>
[EnumMember(Value = "Delete")]
Delete
}
}
188 changes: 0 additions & 188 deletions MK.IO/Asset/Models/AssetTracksAndDir.cs

This file was deleted.

34 changes: 20 additions & 14 deletions MK.IO/ContentKeyPolicy/ContentKeyPoliciesOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#if NET462
using System.Net.Http;
#endif
using MK.IO.Models;
using Newtonsoft.Json;

namespace MK.IO
{
/// <summary>
Expand Down Expand Up @@ -39,35 +42,36 @@ internal ContentKeyPoliciesOperations(MKIOClient client)
}

/// <inheritdoc/>
public List<ContentKeyPolicy> List()
public List<ContentKeyPolicySchema> List()
{
Task<List<ContentKeyPolicy>> task = Task.Run(async () => await ListAsync());
Task<List<ContentKeyPolicySchema>> task = Task.Run(async () => await ListAsync());
return task.GetAwaiter().GetResult();
}

/// <inheritdoc/>
public async Task<List<ContentKeyPolicy>> ListAsync()
public async Task<List<ContentKeyPolicySchema>> ListAsync()
{
var url = Client.GenerateApiUrl(_contentKeyPoliciesApiUrl);
string responseContent = await Client.GetObjectContentAsync(url);
return Models.ListContentKeyPolicies.FromJson(responseContent).Value;
var objectToReturn = JsonConvert.DeserializeObject<ContentKeyPolicyListResponseSchema>(responseContent, ConverterLE.Settings);
return objectToReturn != null ? objectToReturn.Value : throw new Exception($"Error with content key list deserialization");
}

/// <inheritdoc/>
public ContentKeyPolicy Get(string contentKeyPolicyName)
public ContentKeyPolicySchema Get(string contentKeyPolicyName)
{
Task<ContentKeyPolicy> task = Task.Run(async () => await GetAsync(contentKeyPolicyName));
Task<ContentKeyPolicySchema> task = Task.Run(async () => await GetAsync(contentKeyPolicyName));
return task.GetAwaiter().GetResult();
}

/// <inheritdoc/>
public async Task<ContentKeyPolicy> GetAsync(string contentKeyPolicyName)
public async Task<ContentKeyPolicySchema> GetAsync(string contentKeyPolicyName)
{
Argument.AssertNotNullOrEmpty(contentKeyPolicyName, nameof(contentKeyPolicyName));

var url = Client.GenerateApiUrl(_contentKeyPolicyApiUrl, contentKeyPolicyName);
string responseContent = await Client.GetObjectContentAsync(url);
return ContentKeyPolicy.FromJson(responseContent);
return JsonConvert.DeserializeObject<ContentKeyPolicySchema>(responseContent, ConverterLE.Settings) ?? throw new Exception("Error with content key policy deserialization");
}

/// <inheritdoc/>
Expand All @@ -86,21 +90,22 @@ public async Task DeleteAsync(string contentKeyPolicyName)
}

/// <inheritdoc/>
public ContentKeyPolicy Create(string contentKeyPolicyName, ContentKeyPolicy content)
public ContentKeyPolicySchema Create(string contentKeyPolicyName, ContentKeyPolicyProperties properties)
{
Task<ContentKeyPolicy> task = Task.Run(async () => await CreateAsync(contentKeyPolicyName, content));
Task<ContentKeyPolicySchema> task = Task.Run(async () => await CreateAsync(contentKeyPolicyName, properties));
return task.GetAwaiter().GetResult();
}

/// <inheritdoc/>
public async Task<ContentKeyPolicy> CreateAsync(string contentKeyPolicyName, ContentKeyPolicy content)
public async Task<ContentKeyPolicySchema> CreateAsync(string contentKeyPolicyName, ContentKeyPolicyProperties properties)
{
Argument.AssertNotNullOrEmpty(contentKeyPolicyName, nameof(contentKeyPolicyName));
Argument.AssertNotNull(content, nameof(content));
Argument.AssertNotNull(properties, nameof(properties));

var url = Client.GenerateApiUrl(_contentKeyPolicyApiUrl, contentKeyPolicyName);
var content = new ContentKeyPolicySchema { Properties = properties };
string responseContent = await Client.CreateObjectPutAsync(url, content.ToJson());
return ContentKeyPolicy.FromJson(responseContent);
return JsonConvert.DeserializeObject<ContentKeyPolicySchema>(responseContent, ConverterLE.Settings) ?? throw new Exception("Error with content key policy deserialization");
}

/// <inheritdoc/>
Expand All @@ -117,7 +122,8 @@ public async Task<ContentKeyPolicyProperties> GetPolicyPropertiesWithSecretsAsyn

var url = Client.GenerateApiUrl(_contentKeyPolicyApiUrl + "/getPolicyPropertiesWithSecrets", contentKeyPolicyName);
string responseContent = await Client.GetObjectPostContentAsync(url);
return ContentKeyPolicy.FromJson(responseContent).Properties;
//return ContentKeyPolicy.FromJson(responseContent).Properties;
return JsonConvert.DeserializeObject<ContentKeyPolicySchema>(responseContent, ConverterLE.Settings).Properties ?? throw new Exception("Error with content key policy deserialization");
}
}
}
Loading

0 comments on commit e37a14a

Please sign in to comment.