Skip to content

Commit

Permalink
Merge pull request #1 from Ravnur-Inc/feature/add-connect-to-rms
Browse files Browse the repository at this point in the history
Add support for Ravnur Media Services
  • Loading branch information
vstratovych committed Feb 26, 2024
2 parents 2d17c64 + e1caada commit 6f373e8
Show file tree
Hide file tree
Showing 40 changed files with 12,246 additions and 9,401 deletions.
43 changes: 36 additions & 7 deletions AMSExplorer/AMSClient/AMSClientV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
//---------------------------------------------------------------------------------------------

using AMSClient;
using AMSExplorer.Ravnur;
using Azure.ResourceManager;
using Azure.ResourceManager.Media;
using Azure.ResourceManager.Media.Models;
using Microsoft.Identity.Client;
using Microsoft.Rest;
using System;
Expand Down Expand Up @@ -47,6 +49,8 @@ public class AMSClientV3
private readonly System.Timers.Timer TimerAutoRefreshAuthToken;
public bool useMKIOConnection = false;

public bool IsRavnurClient => credentialsEntry.RavnurApiEndpoint != null;
public string RavnurAccessToken;

public AMSClientV3(AzureEnvironment myEnvironment, string azureSubscriptionId, CredentialsEntryV4 myCredentialsEntry, Form form)
{
Expand Down Expand Up @@ -148,7 +152,6 @@ public async Task<MediaServicesAccountResource> ConnectAndGetNewClientV3Async(Fo
Debug.Print("MSAL silent authentication exception !" + maslException.Message);
}
}

else // Service Principal
{
if (firstTimeAuth)
Expand Down Expand Up @@ -178,7 +181,7 @@ public async Task<MediaServicesAccountResource> ConnectAndGetNewClientV3Async(Fo

}

if (firstTimeAuth && connectToMKIO)
if (firstTimeAuth && connectToMKIO && !IsRavnurClient)
{
// form for MK/IO
MKIOConnection mkioConnectionForm = new(credentialsEntry.MKIOSubscriptionName, credentialsEntry.MKIOClearToken);
Expand All @@ -194,20 +197,31 @@ public async Task<MediaServicesAccountResource> ConnectAndGetNewClientV3Async(Fo
credentials = new TokenCredentials(authResult.AccessToken, "Bearer");
credentialForArmClient = new BearerTokenCredential(authResult.AccessToken);

//var credential = new DefaultAzureCredential(includeInteractiveCredentials: true);
ArmClient armClient = null;

if (IsRavnurClient)
{
// When the credentials are configured for Ravnur Media Services,
// we need to instantiate ARM client configured to connect to Ravnur endpoints
armClient = RavnurClientFactory.GetRavnurArmClient(credentialsEntry);
RavnurAccessToken = await RavnurClientFactory.GetRavnurAccessToken(credentialsEntry);
}
else
{
armClient = new ArmClient(credentialForArmClient);
}

// new code
var MediaServiceAccount = MediaServicesAccountResource.CreateResourceIdentifier(
subscriptionId: _azureSubscriptionId,
resourceGroupName: credentialsEntry.ResourceGroupName,
accountName: credentialsEntry.AccountName
);
//var credential = new DefaultAzureCredential(includeInteractiveCredentials: true);
var armClient = new ArmClient(credentialForArmClient);
accountName: credentialsEntry.AccountName);

var amsClient = armClient.GetMediaServicesAccountResource(MediaServiceAccount);

AMSclient = await amsClient.GetAsync();


/*
// Getting Media Services account...
AMSclient = new AzureMediaServicesClient(environment.ArmEndpoint, credentials)
Expand Down Expand Up @@ -278,5 +292,20 @@ public async Task<StreamingEndpointResource> GetStreamingEndpointAsync(string se
{
return await AMSclient.GetStreamingEndpointAsync(seName).ConfigureAwait(false);
}

public StreamingPolicyStreamingProtocol GetDefaultStreamingProtocol()
{
if (IsRavnurClient)
{
return StreamingPolicyStreamingProtocol.Hls;
}

return StreamingPolicyStreamingProtocol.SmoothStreaming;
}

public PlayerType GetPlayerType()
{
return IsRavnurClient ? PlayerType.RavnurMediaPlayer : PlayerType.AzureMediaPlayer;
}
}
}
16 changes: 13 additions & 3 deletions AMSExplorer/AMSClient/CredentialsEntryV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ namespace AMSExplorer
public class CredentialsEntryV4 : IEquatable<CredentialsEntryV4>
{
public string ADSPClientId;

// A contract is used to ignore this property when exporting the entry
public string EncryptedADSPClientSecret;

public string MKIOSubscriptionName;
// A contract is used to ignore this property when exporting the entry
public string MKIOEncryptedToken;

public Uri RavnurApiEndpoint;
// A contract is used to ignore this property when exporting the entry
public string RavnurEncryptedApiKey;

public string AadTenantId;
public AzureEnvironment Environment;
public bool PromptUser;
Expand Down Expand Up @@ -58,20 +61,27 @@ public CredentialsEntryV4(string accountName, string subscriptionId, string reso
}
}

// A contract is used to ignore this property when saveing settings to disk
// A contract is used to ignore this property when saving settings to disk
public string ClearADSPClientSecret
{
get => EncryptedADSPClientSecret != null ? DecryptSecret(EncryptedADSPClientSecret) : null;
set => EncryptedADSPClientSecret = (value != null) ? EncryptSecret(value) : null;
}

// A contract is used to ignore this property when saveing settings to disk
// A contract is used to ignore this property when saving settings to disk
public string MKIOClearToken
{
get => MKIOEncryptedToken != null ? DecryptSecret(MKIOEncryptedToken) : null;
set => MKIOEncryptedToken = (value != null) ? EncryptSecret(value) : null;
}

// A contract is used to ignore this property when saving settings to disk
public string RavnurClearApiKey
{
get => RavnurEncryptedApiKey != null ? DecryptSecret(RavnurEncryptedApiKey) : null;
set => RavnurEncryptedApiKey = (value != null) ? EncryptSecret(value) : null;
}

public bool Equals(CredentialsEntryV4 other)
{
return false;
Expand Down
Loading

0 comments on commit 6f373e8

Please sign in to comment.