-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fde99f
commit 613be41
Showing
7 changed files
with
990 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
namespace smoothdev.Utils.Azure | ||
|
||
open FSharp.Data | ||
open FSharp.Management | ||
open Hopac | ||
type FS = FileSystem<const(__SOURCE_DIRECTORY__)> | ||
type AzureSettings = XmlProvider<FS.``dummy.azure.settings.config``> | ||
type AzurePublishSettings = XmlProvider<FS.``dummy.publishsettings``> | ||
|
||
module internal Internals = | ||
open System.Security.Cryptography.X509Certificates | ||
|
||
let certFromBase64String = System.Convert.FromBase64String >> X509Certificate2 | ||
|
||
open Internals | ||
|
||
type AzureCloudSettings = | ||
private { subscription: AzurePublishSettings.Subscription; azureSettings: AzureSettings.AzureSettings } | ||
with | ||
|
||
static member Make subscription azureSettings = { subscription = subscription; azureSettings = azureSettings } | ||
|
||
member x.SubscriptionId = string x.subscription.Id | ||
|
||
/// this is equal to https://management.core.windows.net/ | ||
member x.ServiceManagementUrl = | ||
if x.subscription.ServiceManagementUrl.EndsWith("/") | ||
then x.subscription.ServiceManagementUrl | ||
else x.subscription.ServiceManagementUrl + "/" | ||
member x.ActiveDirectoryLogin = x.azureSettings.ActiveDirectory.Login | ||
member x.ActiveDirectoryPassword = x.azureSettings.ActiveDirectory.Password | ||
member x.ActiveDirectoryAuthenticationUrl = sprintf "https://login.windows.net/%s" (string x.azureSettings.ActiveDirectory.TenantId) | ||
member x.ActiveDirectoryClientId = string x.azureSettings.ActiveDirectory.ClientId | ||
member x.ActiveDirectoryCertificate = | ||
x.azureSettings.ActiveDirectory.Certificate | ||
|> certFromBase64String | ||
|
||
member x.ManagementCertificate = | ||
x.subscription.ManagementCertificate | ||
|> certFromBase64String | ||
|
||
|
||
module ActiveDirectory = | ||
open Microsoft.IdentityModel.Clients.ActiveDirectory | ||
|
||
let authenticate (settings: AzureCloudSettings) = | ||
let authenticationContext = AuthenticationContext settings.ActiveDirectoryAuthenticationUrl | ||
let userCredential = UserPasswordCredential (settings.ActiveDirectoryLogin, settings.ActiveDirectoryPassword) | ||
authenticationContext.AcquireTokenAsync (settings.ServiceManagementUrl, settings.ActiveDirectoryClientId, userCredential) | ||
|
||
module SqlManagement = | ||
open Microsoft.Azure | ||
|
||
let authenticate settings = | ||
job { | ||
let! adToken = ActiveDirectory.authenticate settings | ||
return TokenCloudCredentials (settings.SubscriptionId, adToken.AccessToken) | ||
} | ||
|
||
let getClient settings = | ||
job { | ||
let! credentials = authenticate settings | ||
return new Microsoft.Azure.Management.Sql.SqlManagementClient(credentials) | ||
} | ||
|
||
type Class1() = | ||
member this.X = "F#" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
//#load "../../../paket-files/include-scripts/net45/include.microsoft.azure.management.sql.fsx" | ||
#load "Scripts/load-references-debug.fsx" | ||
// auto complete doesn't work | ||
|
||
open Microsoft.Azure |
4 changes: 4 additions & 0 deletions
4
smoothdev.Utils/src/smoothdev.Utils.Azure/Scripts/load-project-debug.fsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Warning: generated file; your changes could be lost when a new file is generated. | ||
#I __SOURCE_DIRECTORY__ | ||
#load "load-references-debug.fsx" | ||
#load "../Library1.fs" |
71 changes: 71 additions & 0 deletions
71
smoothdev.Utils/src/smoothdev.Utils.Azure/Scripts/load-references-debug.fsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Warning: generated file; your changes could be lost when a new file is generated. | ||
#I __SOURCE_DIRECTORY__ | ||
#r "../../../../packages/Argu/lib/net40/Argu.dll" | ||
#r "../../../../packages/FSharp.Data/lib/net40/FSharp.Data.dll" | ||
#r "../../../../packages/FSharp.Management/lib/net40/FSharp.Management.dll" | ||
#r "../../../../packages/FSharp.Management/lib/net40/FSharp.Management.PowerShell.dll" | ||
#r "../../../../packages/FSharp.Management/lib/net40/FSharp.Management.PowerShell.ExternalRuntime.exe" | ||
#r "../../../../packages/FSharp.Management/lib/net40/FSharp.Management.WMI.DesignTime.dll" | ||
#r "../../../../packages/FSharp.Management/lib/net40/FSharp.Management.WMI.dll" | ||
#r "../../../../packages/FsPickler/lib/net45/FsPickler.dll" | ||
#r "../../../../packages/FsPickler.Json/lib/net45/FsPickler.Json.dll" | ||
#r "../../../../packages/Hopac/lib/net45/Hopac.Core.dll" | ||
#r "../../../../packages/Hopac/lib/net45/Hopac.dll" | ||
#r "../../../../packages/Hopac/lib/net45/Hopac.Platform.dll" | ||
#r "../../../../packages/Hyak.Common/lib/net45/Hyak.Common.dll" | ||
#r "../../../../packages/MBrace.Azure/lib/net45/MBrace.Azure.dll" | ||
#r "../../../../packages/MBrace.Azure.Management/lib/net45/MBrace.Azure.Management.dll" | ||
#r "../../../../packages/MBrace.Core/lib/net45/MBrace.Core.dll" | ||
#r "../../../../packages/MBrace.Runtime/lib/net45/MBrace.Runtime.dll" | ||
#r "../../../../packages/Microsoft.Azure.Common/lib/net45/Microsoft.Azure.Common.dll" | ||
#r "../../../../packages/Microsoft.Azure.Common/lib/net45/Microsoft.Azure.Common.NetFramework.dll" | ||
#r "../../../../packages/Microsoft.Azure.Management.Compute/lib/net40/Microsoft.Azure.Management.Compute.dll" | ||
#r "../../../../packages/Microsoft.Azure.Management.ResourceManager/lib/net45/Microsoft.Azure.Management.ResourceManager.dll" | ||
#r "../../../../packages/Microsoft.Azure.Management.Sql/lib/net40/Microsoft.Azure.Management.Sql.dll" | ||
#r "../../../../packages/Microsoft.Data.Edm/lib/net40/Microsoft.Data.Edm.dll" | ||
#r "../../../../packages/Microsoft.Data.OData/lib/net40/Microsoft.Data.OData.dll" | ||
#r "../../../../packages/Microsoft.Data.Services.Client/lib/net40/Microsoft.Data.Services.Client.dll" | ||
#r "../../../../packages/Microsoft.IdentityModel.Clients.ActiveDirectory/lib/net45/Microsoft.IdentityModel.Clients.ActiveDirectory.dll" | ||
#r "../../../../packages/Microsoft.IdentityModel.Clients.ActiveDirectory/lib/net45/Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll" | ||
#r "../../../../packages/Microsoft.Rest.ClientRuntime.Azure/lib/net45/Microsoft.Rest.ClientRuntime.Azure.dll" | ||
#r "../../../../packages/Microsoft.Rest.ClientRuntime/lib/net45/Microsoft.Rest.ClientRuntime.dll" | ||
#r "../../../../packages/WindowsAzure.ServiceBus/lib/net40-full/Microsoft.ServiceBus.dll" | ||
#r "../../../../packages/Microsoft.Bcl.Async/lib/net40/Microsoft.Threading.Tasks.dll" | ||
#r "../../../../packages/Microsoft.Bcl.Async/lib/net40/Microsoft.Threading.Tasks.Extensions.Desktop.dll" | ||
#r "../../../../packages/Microsoft.Bcl.Async/lib/net40/Microsoft.Threading.Tasks.Extensions.dll" | ||
#r "../../../../packages/Microsoft.WindowsAzure.Common/lib/net45/Microsoft.WindowsAzure.Common.dll" | ||
#r "../../../../packages/Microsoft.WindowsAzure.Common/lib/net45/Microsoft.WindowsAzure.Common.NetFramework.dll" | ||
#r "../../../../packages/Microsoft.WindowsAzure.ConfigurationManager/lib/net40/Microsoft.WindowsAzure.Configuration.dll" | ||
#r "../../../../packages/Microsoft.WindowsAzure.Management.Compute/lib/net40/Microsoft.WindowsAzure.Management.Compute.dll" | ||
#r "../../../../packages/Microsoft.WindowsAzure.Management/lib/net40/Microsoft.WindowsAzure.Management.dll" | ||
#r "../../../../packages/Microsoft.WindowsAzure.Management.MediaServices/lib/net40/Microsoft.WindowsAzure.Management.MediaServices.dll" | ||
#r "../../../../packages/Microsoft.WindowsAzure.Management.Monitoring/lib/net40/Microsoft.WindowsAzure.Management.Monitoring.dll" | ||
#r "../../../../packages/Microsoft.WindowsAzure.Management.Network/lib/net40/Microsoft.WindowsAzure.Management.Network.dll" | ||
#r "../../../../packages/Microsoft.WindowsAzure.Management.Scheduler/lib/net40/Microsoft.WindowsAzure.Management.Scheduler.dll" | ||
#r "../../../../packages/Microsoft.WindowsAzure.Management.ServiceBus/lib/net40/Microsoft.WindowsAzure.Management.ServiceBus.dll" | ||
#r "../../../../packages/Microsoft.WindowsAzure.Management.Sql/lib/net40/Microsoft.WindowsAzure.Management.Sql.dll" | ||
#r "../../../../packages/Microsoft.WindowsAzure.Management.Storage/lib/net40/Microsoft.WindowsAzure.Management.Storage.dll" | ||
#r "../../../../packages/Microsoft.WindowsAzure.Management.WebSites/lib/net40/Microsoft.WindowsAzure.Management.WebSites.dll" | ||
#r "../../../../packages/WindowsAzure.Storage/lib/net40/Microsoft.WindowsAzure.Storage.dll" | ||
#r "../../../../packages/Mono.Cecil/lib/net45/Mono.Cecil.dll" | ||
#r "../../../../packages/Mono.Cecil/lib/net45/Mono.Cecil.Mdb.dll" | ||
#r "../../../../packages/Mono.Cecil/lib/net45/Mono.Cecil.Pdb.dll" | ||
#r "../../../../packages/Mono.Cecil/lib/net45/Mono.Cecil.Rocks.dll" | ||
#r "../../../../packages/Newtonsoft.Json/lib/net45/Newtonsoft.Json.dll" | ||
#r "System.Core.dll" | ||
#r "System.Data.dll" | ||
#r "System.dll" | ||
#r "../../../../packages/FSharp.Management/lib/net40/System.Management.Automation.dll" | ||
#r "System.Net.dll" | ||
#r "System.Net.Http.dll" | ||
#r "../../../../packages/Microsoft.Net.Http/lib/net45/System.Net.Http.Extensions.dll" | ||
#r "../../../../packages/Microsoft.Net.Http/lib/net45/System.Net.Http.Primitives.dll" | ||
#r "System.Net.Http.WebRequest.dll" | ||
#r "System.Numerics.dll" | ||
#r "System.Runtime.Serialization.dll" | ||
#r "System.ServiceModel.Discovery.dll" | ||
#r "System.ServiceModel.dll" | ||
#r "../../../../packages/System.Spatial/lib/net40/System.Spatial.dll" | ||
#r "System.Xml.dll" | ||
#r "System.Xml.Linq.dll" | ||
#r "../../../../packages/Vagabond/lib/net45/Vagabond.dll" |
23 changes: 23 additions & 0 deletions
23
smoothdev.Utils/src/smoothdev.Utils.Azure/dummy.azure.settings.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<AzureSettings> | ||
<Subscription> | ||
<File>c:\tmp\azure\my.publishsettings</File> | ||
<Name>subscriptionname</Name> | ||
</Subscription> | ||
<CloudService> | ||
<File>c:\tmp\azure\mbracepackages\mycustom\MBrace.Azure.CloudService.cspkg</File> | ||
<Name>mymbrace</Name> | ||
<Provisionning> | ||
<Region>Central US</Region> | ||
<VMSize>Medium</VMSize> | ||
<VMCount>4</VMCount> | ||
</Provisionning> | ||
</CloudService> | ||
<ActiveDirectory> | ||
<Login>login</Login> | ||
<Password>password</Password> | ||
<ClientID>0108-0108-0108-0108-010801080108</ClientID> | ||
<TenantID>1008-1008-1008-1008-100810081008</TenantID> | ||
<Certificate>BASE64CERTIFICATE</Certificate> | ||
</ActiveDirectory> | ||
</AzureSettings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FSharp.Core | ||
FSharp.Data | ||
FSharp.Management | ||
Hopac | ||
MBrace.Azure.Management | ||
Microsoft.IdentityModel.Clients.ActiveDirectory | ||
Microsoft.Azure.Management.Compute | ||
Microsoft.Azure.Management.ResourceManager | ||
Microsoft.Azure.Management.Sql |
Oops, something went wrong.