示例#1
0
        public async Task RegisterDscAgent()
        {
            if (LOG.IsEnabled(LogLevel.Trace))
            {
                LOG.LogTrace(nameof(RegisterDscAgent));
            }

            AssertInit();

            var serverConfig = Configuration.ConfigurationRepositoryServer;

            AssertServerConfig(serverConfig);

            var dscRequ = new RegisterDscAgentRequest
            {
                AgentId           = Configuration.AgentId,
                ContentTypeHeader = DscContentTypes.JSON,
                MsDateHeader      = COMPUTE_MS_DATE_HEADER,
                Body = new RegisterDscAgentRequestBody
                {
                    ConfigurationNames      = Configuration.ConfigurationNames.ToArray(),
                    AgentInformation        = Configuration.AgentInformation,
                    RegistrationInformation = new RegistrationInformation
                    {
                        RegistrationMessageType = REGISTRATION_MESSAGE_TYPE_CONFIGURATION_REPOSITORY,
                        CertificateInformation  = Configuration.CertificateInformation
                    }
                }
            };

            await SendDscAsync(serverConfig, RegisterDscAgentRequest.VERB,
                               RegisterDscAgentRequest.ROUTE, dscRequ);
        }
示例#2
0
        public IActionResult RegisterDscAgent(RegisterDscAgentRequest input)
        {
            if (_logger.IsEnabled(LogLevel.Trace))
                _logger.LogTrace($"{nameof(RegisterDscAgent)}:  {RegisterDscAgentRequest.VERB}");

            if (ModelState.IsValid)
            {
                _logger.LogDebug($"AgentId=[{input.AgentId}]");
                _dscHandler.RegisterDscAgent(input.AgentId.Value, input.Body);

                return this.Model(RegisterDscAgentResponse.INSTANCE);
            }

            return base.BadRequest(ModelState);
        }
示例#3
0
        public async Task <IActionResult> RegisterDscAgent(RegisterDscAgentRequest input)
        {
            if (_logger.IsEnabled(LogLevel.Trace))
            {
                _logger.LogTrace($"{nameof(RegisterDscAgent)}:  {RegisterDscAgentRequest.VERB}");
            }

            if (!ModelState.IsValid)
            {
                return(base.BadRequest(ModelState));
            }

            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug($"AgentId=[{input.AgentId}]");
            }

            var regS3Key = $"{_settings.S3KeyPrefixRegistrations}/{input.AgentId}.json";

            var putRequ = new PutObjectRequest
            {
                BucketName   = _settings.S3Bucket,
                Key          = regS3Key,
                CannedACL    = S3CannedACL.Private,
                ContentBody  = JsonConvert.SerializeObject(input.Body),
                ContentType  = Model.DscContentTypes.JSON,
                StorageClass = S3StorageClass.ReducedRedundancy,
            };

            var putResp = await _s3.PutObjectAsync(putRequ);

            if (putResp.HttpStatusCode != HttpStatusCode.OK)
            {
                _logger.LogError($"failed to save registration; unexpected HTTP status code [{putResp.HttpStatusCode}]");
                return(base.StatusCode((int)HttpStatusCode.InternalServerError,
                                       "unexpected error trying to persist node registration"));
            }

            return(this.Model(RegisterDscAgentResponse.INSTANCE));
        }