Skip to content

Commit

Permalink
configuration resolver improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriktsarpalis committed Jun 1, 2016
1 parent e3a3254 commit 59a89d0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 33 deletions.
4 changes: 2 additions & 2 deletions paket.dependencies
Expand Up @@ -4,8 +4,8 @@ source https://nuget.org/api/v2

nuget NUnit ~> 2.0
nuget NUnit.Runners ~> 2.0
nuget MBrace.Core ~> 1.2.0
nuget MBrace.Runtime ~> 1.2.0
nuget MBrace.Core ~> 1.2.6
nuget MBrace.Runtime ~> 1.2.6
nuget MBrace.Tests
nuget FSharp.Compiler.Service
nuget MathNet.Numerics ~> 3.7.0
Expand Down
22 changes: 11 additions & 11 deletions paket.lock
Expand Up @@ -28,30 +28,30 @@ NUGET
MathNet.Numerics (3.7.1)
MathNet.Numerics.MKL.Win-x64 (1.8)
MathNet.Numerics (>= 2.4)
MBrace.Core (1.2.4)
MBrace.Flow (1.2.4)
MBrace.Core (1.2.6)
MBrace.Flow (1.2.6)
FSharp.Core (>= 3.0)
MBrace.Core (1.2.4)
MBrace.Core (1.2.6)
Streams (>= 0.4 < 0.5)
MBrace.Runtime (1.2.4)
MBrace.Runtime (1.2.6)
FsPickler (>= 2.1 < 2.2)
FsPickler.Json (>= 2.1 < 2.2)
MBrace.Core (1.2.4)
MBrace.Core (1.2.6)
Vagabond (>= 0.13 < 0.14)
MBrace.Tests (1.2.4)
MBrace.Tests (1.2.6)
FsCheck (>= 2.0.1)
MBrace.Core (1.2.4)
MBrace.Flow (1.2.4)
MBrace.Core (1.2.6)
MBrace.Flow (1.2.6)
NUnit (>= 2.6 < 3.0)
Microsoft.Owin (3.0.1) - version_in_path: true
Owin (>= 1.0)
Microsoft.Owin.Host.SystemWeb (3.0.1)
Microsoft.Owin (>= 3.0.1)
Microsoft.Owin.Host.SystemWeb (3.0)
Microsoft.Owin (>= 3.0)
Owin (>= 1.0)
Mono.Cecil (0.9.6.1)
Newtonsoft.Json (8.0.3)
NUnit (2.6.4)
NUnit.Runners (2.6.4)
NUnit.Runners (2.6.3)
Owin (1.0) - version_in_path: true
Streams (0.4.1)
Unquote (3.1.1)
Expand Down
5 changes: 5 additions & 0 deletions src/MBrace.AWS.WebWorker/Web.config
Expand Up @@ -22,4 +22,9 @@
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-999.999.999.999" newVersion="4.4.0.0" />
</dependentAssembly>
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-999.999.999.999" newVersion="3.0.1.0" />
</dependentAssembly>
</assemblyBinding></runtime></configuration>
18 changes: 7 additions & 11 deletions src/MBrace.AWS/Configuration/Configuration.fs
Expand Up @@ -72,6 +72,11 @@ type MBraceAWSCredentials (accessKey : string, secretKey : string) =
let [<DataMember(Name = "AccessKey")>] accessKey = accessKey
let [<DataMember(Name = "SecretKey")>] secretKey = secretKey

// simple recognizer for aws credentials file syntax
// c.f. http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
static let profileRegex =
Regex("\[(\S+)\]\s+aws_access_key_id\s*=\s*(\S+)\s+aws_secret_access_key\s*=\s*(\S+)", RegexOptions.Compiled)

member __.AccessKey = accessKey
member __.SecretKey = secretKey

Expand Down Expand Up @@ -100,7 +105,7 @@ type MBraceAWSCredentials (accessKey : string, secretKey : string) =
let text = File.ReadAllText credsFile

let matchingProfile =
Regex.Matches(text, "\[(\S+)\]\s+aws_access_key_id\s*=\s*(\S+)\s+aws_secret_access_key\s*=\s*(\S+)")
profileRegex.Matches text
|> Seq.cast<Match>
|> Seq.map (fun m -> m.Groups.[1].Value, m.Groups.[2].Value, m.Groups.[3].Value)
|> Seq.tryFind (fun (pf,_,_) -> pf = profileName)
Expand All @@ -116,16 +121,7 @@ type MBraceAWSCredentials (accessKey : string, secretKey : string) =
static member FromEnvironmentVariables() =
let accessKeyName = "AWS_ACCESS_KEY_ID"
let secretKeyName = "AWS_SECRET_ACCESS_KEY"

let getEnv (envName:string) =
let aux found target =
if String.IsNullOrWhiteSpace found then Environment.GetEnvironmentVariable(envName, target)
else found

Array.fold aux null [|
EnvironmentVariableTarget.Process;
EnvironmentVariableTarget.User;
EnvironmentVariableTarget.Machine |]
let getEnv x = Environment.ResolveEnvironmentVariable x

match getEnv accessKeyName, getEnv secretKeyName with
| null, null -> sprintf "Undefined environment variables '%s' and '%s'" accessKeyName secretKeyName |> invalidOp
Expand Down
12 changes: 3 additions & 9 deletions tests/MBrace.AWS.Tests/Utils.fs
Expand Up @@ -13,6 +13,7 @@ open MBrace.Core.Internals
open MBrace.Core.Tests

open MBrace.Runtime
open MBrace.Runtime.Utils
open MBrace.Runtime.Components
open MBrace.ThreadPool

Expand All @@ -27,21 +28,14 @@ open MBrace.AWS.Store
module Utils =

let init() = ProcessConfiguration.InitAsClient()

let getEnvironmentVariable (envName:string) =
let aux found target =
if String.IsNullOrWhiteSpace found then Environment.GetEnvironmentVariable(envName, target)
else found

Array.fold aux null [|EnvironmentVariableTarget.Process; EnvironmentVariableTarget.User; EnvironmentVariableTarget.Machine|]

let getEnvironmentVariableOrDefault envName defaultValue =
match getEnvironmentVariable envName with
match Environment.ResolveEnvironmentVariable envName with
| null | "" -> defaultValue
| ev -> ev

let getAWSRegion () =
match getEnvironmentVariable "AWS_REGION" with
match Environment.ResolveEnvironmentVariable "AWS_REGION" with
| null | "" -> AWSRegion.EUCentral1
| region -> AWSRegion.Parse region

Expand Down

0 comments on commit 59a89d0

Please sign in to comment.