예제 #1
0
        public bool TryGetValue(string ParameterPath, out string ParameterValue)
        {
            try
            {
                var ssmParamResult = simpleSystemsManagementClient.GetParameterAsync(new Amazon.SimpleSystemsManagement.Model.GetParameterRequest
                {
                    Name = ParameterPath
                }).GetAwaiter().GetResult();

                if (ssmParamResult.HttpStatusCode == System.Net.HttpStatusCode.OK)
                {
                    ParameterValue = ssmParamResult.Parameter.Value;
                    return(true);
                }
                else
                {
                    ParameterValue = null;
                    return(false);
                }
            }catch (AmazonSimpleSystemsManagementException ex)
            {
                Console.WriteLine($"WARN: Error trying to retrieve SSM parameter {ParameterPath}: {ex.Message}");
                ParameterValue = null;
                return(false);
            }
        }
예제 #2
0
        public string GetParamValue(string paramKey)
        {
            lock (_ResolveCache) {
                string paramKeyWithoutPhs = paramKey;
                foreach (var phName in this.ParameterKeyPlaceholderResolvers.Keys)
                {
                    string pt = "{" + phName + "}";
                    if (paramKeyWithoutPhs.Contains(pt))
                    {
                        string pv = this.ParameterKeyPlaceholderResolvers[phName].Invoke();
                        paramKeyWithoutPhs = paramKeyWithoutPhs.Replace(pt, pv);
                    }
                }

                if (_ResolveCache.ContainsKey(paramKeyWithoutPhs))
                {
                    return(_ResolveCache[paramKeyWithoutPhs]);
                }

                string pValue = null;
                using (var client = new AmazonSimpleSystemsManagementClient(this.AwsCredentials, this.AwsRegion)) {
                    var request = new GetParameterRequest()
                    {
                        Name = paramKeyWithoutPhs
                    };
                    var t = client.GetParameterAsync(request);
                    t.Wait();
                    if (t.IsCompleted && t.Result is object && t.Result.Parameter is object)
                    {
                        _ResolveCache.Add(paramKeyWithoutPhs, t.Result.Parameter.Value);
                        pValue = t.Result.Parameter.Value;
                    }
                }

                if (pValue is object)
                {
                    lock (_BoundObjects) {
                        foreach (var adapter in _BoundObjects.Values)
                        {
                            adapter.InjectValue(paramKey, pValue);
                            if (!((paramKeyWithoutPhs ?? "") == (paramKey ?? "")))
                            {
                                adapter.InjectValue(paramKeyWithoutPhs, pValue);
                            }
                        }
                    }
                }

                return(pValue);
            }
        }