public async Task <AppConfigData> GetAppConfigData()
        {
            if (DateTime.UtcNow > AppConstants.TimeToLiveExpiration || String.IsNullOrEmpty(AppConstants.ClientConfigurationVersion))
            {
                // get Amazon.AppConfig.Model.GetConfigurationResponse from GetConfiguration API Call
                GetConfigurationResponse getConfigurationResponse = await _appConfigService.GetConfigurationResponse();

                AppConstants.ClientConfigurationVersion = getConfigurationResponse.ConfigurationVersion;

                string decodedResponseData = getConfigurationResponse.Content.Length > 0 ? getConfigurationResponse.Content.DecodeMemoryStreamToString() : String.Empty;

                // convert DecodedResponseData to our AppConfigData model which consists of:
                AppConfigData appConfigData = String.IsNullOrEmpty(decodedResponseData) ? AppConstants.AppConfigData : JsonConvert.DeserializeObject <AppConfigData>(decodedResponseData);

                //AppConfigData appConfigData = JsonConvert.DeserializeObject<AppConfigData>(decodedResponseData);

                if (!appConfigData.BoolEnableLimitResults && appConfigData.IntResultLimit == 0)
                {
                    throw new Exception();
                }

                // add AppConfigData to our cache in AppConstants
                AppConstants.AppConfigData = appConfigData;

                return(AppConstants.AppConfigData);
            }
            else
            {
                Console.WriteLine("DID NOT call GetConfigurationAPI to get data.  Return AppConfigData from cached value in AppConstants.AppConfigData instead. \n");
                return(AppConstants.AppConfigData);
            }
        }
Пример #2
0
        public IActionResult GetConfiguration(GetConfigurationRequest input)
        {
            if (_logger.IsEnabled(LogLevel.Trace))
            {
                _logger.LogTrace($"{nameof(GetConfiguration)}:  {GetConfigurationRequest.VERB}");
            }

            if (ModelState.IsValid)
            {
                _logger.LogDebug($"AgentId=[{input.AgentId}] Configuration=[{input.ConfigurationName}]");

                var configContent = _dscHandler.GetConfiguration(input.AgentId.Value,
                                                                 // TODO:
                                                                 // Strictly speaking, this may not be how the DSCPM
                                                                 // protocol is supposed to resolve the config name
                                                                 input.ConfigurationName ?? input.ConfigurationNameHeader);
                if (configContent == null)
                {
                    return(NotFound());
                }

                var response = new GetConfigurationResponse
                {
                    ChecksumAlgorithmHeader = configContent.ChecksumAlgorithm,
                    ChecksumHeader          = configContent.Checksum,
                    Configuration           = configContent.Content,
                };

                return(this.Model(response));
            }

            return(BadRequest(ModelState));
        }
Пример #3
0
        // TODO:  I think returning a Stream would be better here, but coordinating that
        // with the disposable resources that are contained within could be tricky
        public async Task <FileResponse> GetConfiguration(string configName)
        {
            if (LOG.IsEnabled(LogLevel.Trace))
            {
                LOG.LogTrace(nameof(GetConfiguration));
            }

            AssertInit();

            var serverConfig = Configuration.ConfigurationRepositoryServer;

            AssertServerConfig(serverConfig);

            var dscRequ = new GetConfigurationRequest
            {
                AgentId           = Configuration.AgentId,
                ConfigurationName = configName,
                AcceptHeader      = DscContentTypes.OCTET_STREAM,
            };

            var dscResp = new GetConfigurationResponse();

            using (var bs = new MemoryStream())
                using (var disposable = await SendDscAsync(serverConfig, GetConfigurationRequest.VERB,
                                                           GetConfigurationRequest.ROUTE, dscRequ, dscResp))
                {
                    dscResp.Configuration.CopyTo(bs);
                    return(new FileResponse
                    {
                        ChecksumAlgorithm = dscResp.ChecksumAlgorithmHeader,
                        Checksum = dscResp.ChecksumHeader,
                        Content = bs.ToArray(),
                    });
                }
        }
Пример #4
0
        public override void GetConfiguration(IRpcController controller, GetConfigurationRequest request, Action <GetConfigurationResponse> done)
        {
            Logger.Trace("GetConfiguration()");
            var builder = GetConfigurationResponse.CreateBuilder();

            done(builder.Build());
        }
Пример #5
0
        public GetConfigurationResponse GetConfiguration()
        {
            ToastHelper.PopToast("Get configuration");

            var response = new GetConfigurationResponse();

            response.FirewallEnabled = FirewallHelper.IsEnabled();
            return(response);
        }
Пример #6
0
        public async Task <GetConfigurationResponse> GetConfiguration(GetConfigurationRequest o)
        {
            var result = new GetConfigurationResponse(o.RequestId);

            result.Key   = o.Key;
            result.Value = await Server.GetSettings(o.Application, o.Key);

            return(result);
        }
Пример #7
0
        public GetConfigurationResponse GetConfiguration(string platform)
        {
            var result = new GetConfigurationResponse {
            };

            try
            {
                var dataSource = _reportsDataSourceFactory.GetDataSource(platform);
                result.Data = dataSource.GetConfiguration();
            }
            catch (Exception ex)
            {
                result.Error = new ResponseError().Load(ex);
                _logger.LogException(ex);
            }
            return(result);
        }
Пример #8
0
        public GetConfigurationResponse GetConfiguration(string platform)
        {
            var result = new GetConfigurationResponse();

            try
            {
                // POST
                var apiRequest = CreateRequest(Method.GET, "{platform}/configuration");
                apiRequest.AddUrlSegment("platform", platform);
                var response = Execute <GetConfigurationResponse>(apiRequest);
                return(response);
            }
            catch (Exception ex)
            {
                result.Error = new ResponseError().Load(ex);
            }
            return(result);
        }
        public async Task <AppConfigData> GetAppConfigData()
        {
            // In general, we should limit the calls to GetConfiguration API call to at least once every 15 seconds
            // In AppConstants the TimeToLiveExpiration is set to the initial DateTime of Program.cs execution plus AppConstants.TimeToLiveInSeconds (15 seconds)
            // This if condition makes sure that we only call the GetConfiguration API call if we have not exceeded the TTL expiration, or
            // if the ClientConfigurationVersion is set in our local cache in AppConstants - ClientConfigurationVersion is returned from the initial call to the GetConfiguration API (see below for more info)
            if (DateTime.UtcNow > AppConstants.TimeToLiveExpiration || String.IsNullOrEmpty(AppConstants.ClientConfigurationVersion))
            {
                Console.WriteLine("CALLED GetConfigurationAPI to get AppConfigData  \n");
                IAppConfigService appConfigService = new AppConfigService(_clientId);

                // get Amazon.AppConfig.Model.GetConfigurationResponse from GetConfiguration API Call
                GetConfigurationResponse getConfigurationResponse = await appConfigService.GetConfigurationResponse();


                // add ConfigurationVersion to AppConstants to AppConstants to be used in subsequent calls to GetConfugration API to avopid excess charges
                // https://docs.aws.amazon.com/appconfig/2019-10-09/APIReference/API_GetConfiguration.html#API_GetConfiguration_RequestSyntax
                AppConstants.ClientConfigurationVersion = getConfigurationResponse.ConfigurationVersion;


                // The GetConfiguration response includes a Content section (i.e., our getConfigurationResponse.Content) that shows the configuration data.
                // The Content section only appears if the system finds new or updated configuration data.
                // If the system doesn't find new or updated configuration data, then the Content section is not returned (Null).
                // https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-retrieving-the-configuration.html
                string decodedResponseData = getConfigurationResponse.Content.Length > 0 ? MemoryStreamHelper.DecodeMemoryStreamToString(getConfigurationResponse.Content) : String.Empty;


                // convert DecodedResponseData to our AppConfigData model which consists of:
                // bool boolEnableLimitResults
                // int intResultLimit
                AppConfigData appConfigData = this.ConvertDecodedResponseToAppConfigData(decodedResponseData);

                // add AppConfigData to our cache in AppConstants
                AppConstants.AppConfigData = appConfigData;

                return(AppConstants.AppConfigData);
            }
            else
            {
                Console.WriteLine("DID NOT call GetConfigurationAPI to get data.  Return AppConfigData from cached value in AppConstants.AppConfigData instead. \n");
                return(AppConstants.AppConfigData);
            }
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetConfigurationResponse response = new GetConfigurationResponse();

            var ms = new MemoryStream();

            Amazon.Util.AWSSDKUtils.CopyStream(context.Stream, ms);
            ms.Seek(0, SeekOrigin.Begin);
            response.Content = ms;
            if (context.ResponseData.IsHeaderPresent("Configuration-Version"))
            {
                response.ConfigurationVersion = context.ResponseData.GetHeaderValue("Configuration-Version");
            }
            if (context.ResponseData.IsHeaderPresent("Content-Type"))
            {
                response.ContentType = context.ResponseData.GetHeaderValue("Content-Type");
            }

            return(response);
        }
Пример #11
0
        public static async Task Main()
        {
            logger.Info("Starting example");
            AuditClient client = null;

            try
            {
                // Assumption: the compartment id has been set in environment variable.
                var compartmentId = Environment.GetEnvironmentVariable("OCI_COMPARTMENT_ID");
                logger.Info(compartmentId);

                // ListEvents
                var listEventsRequest = new ListEventsRequest
                {
                    CompartmentId = compartmentId,
                    StartTime     = DateTime.Now.AddDays(-1),
                    EndTime       = DateTime.Now
                };

                // Create AuditClient
                var provider = new ConfigFileAuthenticationDetailsProvider("DEFAULT");

                using (client = new AuditClient(provider, new ClientConfiguration()))
                {
                    logger.Info("AuditClient created.");

                    ListEventsResponse listEventsResp = await NoRetryExample(client, listEventsRequest);

                    logger.Info($"Received {listEventsResp?.Items.Count} items");

                    ListEventsResponse listEventsRespFromRetry = await RetryExample(client, listEventsRequest);

                    logger.Info($"Received {listEventsRespFromRetry?.Items.Count} items");

                    await CancellationTokenExample(client, listEventsRequest);

                    // GetConfiguration
                    var getConfigurationRequest = new GetConfigurationRequest
                    {
                        CompartmentId = compartmentId
                    };

                    logger.Info("GetConfigurationRequest created.");

                    GetConfigurationResponse getConfigurationResp = await client.GetConfiguration(getConfigurationRequest);

                    logger.Info($"Retention period days: {getConfigurationResp?.Configuration.RetentionPeriodDays}");

                    // UpdateConfiguration
                    var updateConfigurationRequest = new UpdateConfigurationRequest
                    {
                        CompartmentId = compartmentId,
                        UpdateConfigurationDetails = new UpdateConfigurationDetails
                        {
                            RetentionPeriodDays = 90
                        }
                    };

                    logger.Info("UpdateConfigurationRequest created.");

                    UpdateConfigurationResponse updateConfigurationResp = await client.UpdateConfiguration(updateConfigurationRequest);

                    logger.Info($"opc work request id: {updateConfigurationResp.OpcRequestId}");
                }
            }
            catch (Exception e)
            {
                logger.Error($"Failed Audit example: {e.Message}");
            }
        }