-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParameterStore.fs
76 lines (61 loc) · 2.59 KB
/
ParameterStore.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// In order for this module to work, the following dlls should be included in the main script:
// #r "AWSSDK.Core.dll"
// #r "AWSSDK.SimpleSystemsManagement.dll"
namespace Albelli
open Fake
open Amazon.SimpleSystemsManagement
module ParameterStore =
let private getParametersStoreParameters() =
let parameterStorePrefix = "/build/variables"
let parameterStorePrefixTrailingSlash = parameterStorePrefix + "/"
use client = new AmazonSimpleSystemsManagementClient()
let createRequest nextToken =
Model.GetParametersByPathRequest(
WithDecryption = true,
Path = parameterStorePrefix,
MaxResults = 10,
Recursive = true,
NextToken = nextToken)
let getNextResponse token =
let response =
createRequest token
|> client.GetParametersByPath
let parameters =
response
|> fun x-> x.Parameters
|> List.ofSeq
response.NextToken, parameters
let parameterStoreParams =
let rec recursiveParams nextToken acc =
let newToken, newParamsList = getNextResponse nextToken
if System.String.IsNullOrEmpty(nextToken) then
acc @ newParamsList
else
recursiveParams newToken (acc @ newParamsList)
let newToken, newParamsList = getNextResponse null
if System.String.IsNullOrEmpty(newToken) then
newParamsList
else
recursiveParams newToken newParamsList
parameterStoreParams
|> Seq.map (fun p -> p.Name.Substring(parameterStorePrefixTrailingSlash.Length), p.Value)
|> Map.ofSeq
let private parameterStoreParameters() = lazy (
try
getParametersStoreParameters()
with
| ex ->
tracefn "Failed to get parameter store parameters %s" ex.Message
Map.empty
)
let parameterStoreVarOrNone var =
parameterStoreParameters().Value
|> Map.tryFind var
let anyVarOrNone var =
match environVarOrNone var with
| None _ -> parameterStoreVarOrNone var
| x -> x
let anyVarOrFail var =
match anyVarOrNone var with
| None _ -> failwithf "Can't find %s variable anywhere" var
| Some x -> x