Exemplo n.º 1
0
        public async Task <MessageResponse> SaveCertificatesInServerAndScheduleRenewalAsync()
        {
            MessageResponse messageResponse = new MessageResponse
            {
                message = string.Empty
            };

            List <CertificateResponse> certificatesList =
                await GetCertificateListAsync();

            if (certificatesList?.Count > 0)
            {
                foreach (var cert in certificatesList)
                {
                    if (!string.IsNullOrEmpty(cert?.remoteCreate))
                    {
                        string[] flaggedServers = TextHelper.GetStringArray(cert.remoteCreate, ',');

                        if (!flaggedServers.Contains(_certificateBotOptions.Value.serverIdentifier))
                        {
                            await SaveCertificateFileAndFlagServer(cert);
                        }
                    }
                    else
                    {
                        await SaveCertificateFileAndFlagServer(cert);
                    }
                }

                if (lstCertNames?.Count > 0)
                {
                    messageResponse.message = $"Saved the following certificate(s): {String.Join(",", lstCertNames)} in the server in the folder : {_certificateBotOptions.Value.saveCertificatePath}.";
                }
                else
                {
                    messageResponse.message = $"Did not find any certificates to save in the server.";
                }

                List <CertificateResponse> scheduledCertificateRenewals =
                    await RenewCertificatesAsync();

                if (scheduledCertificateRenewals?.Count > 0)
                {
                    List <string> lstCertToRenew = new List <string>();

                    foreach (var certToRenew in scheduledCertificateRenewals)
                    {
                        lstCertToRenew.Add(certToRenew.name);
                    }

                    messageResponse.message = $"{messageResponse.message} The following certificate(s) were scheduled for renewal : {String.Join(",", lstCertToRenew)}.";
                }
                else
                {
                    messageResponse.message = $"{messageResponse.message} There were no certificates found to be renewed.";
                }
            }
            else
            {
                messageResponse.message = $"There were no certificates found to save to the server.";
            }

            messageResponse.certificateResponses = certificateResponses;
            return(messageResponse);
        }