feat: Enhance CMS Microservice with SystemConstants and SmsTemplates
- Added SystemConstants class to centralize hardcoded values for club configuration, commission configuration, and package amounts. - Introduced SmsTemplates class to manage SMS message templates for various user notifications. - Implemented automatic SMS sending for Daya Loan approval notifications. - Updated BackOffice UI to include App Version management features. - Fixed mapping issues in Mapster profiles for improved data handling. - Updated changelog and documentation to reflect recent changes and configurations.
This commit is contained in:
@@ -0,0 +1,199 @@
|
||||
# Environment-specific Configuration Guide
|
||||
|
||||
## 📁 فایلهای appsettings
|
||||
|
||||
این پروژه از فایلهای زیر برای مدیریت تنظیمات محیطهای مختلف استفاده میکند:
|
||||
|
||||
### فایلهای موجود:
|
||||
|
||||
| فایل | محیط | Git | توضیحات |
|
||||
|------|------|-----|---------|
|
||||
| `appsettings.json` | Base/Default | ✅ Commit | تنظیمات پایه و مقادیر پیشفرض |
|
||||
| `appsettings.Development.json` | Local/Test | ✅ Commit | محیط توسعه محلی (Mock APIs) |
|
||||
| `appsettings.Staging.json` | Staging | ⚠️ Template | محیط Stage (نیاز به تنظیمات واقعی) |
|
||||
| `appsettings.Production.json` | Production | ⚠️ Template | محیط Production (نیاز به تنظیمات واقعی) |
|
||||
|
||||
---
|
||||
|
||||
## 🔐 امنیت
|
||||
|
||||
### ⚠️ فایلهایی که نباید commit شوند:
|
||||
|
||||
```gitignore
|
||||
# Sensitive configuration files
|
||||
appsettings.Staging.json
|
||||
appsettings.Production.json
|
||||
appsettings.*.local.json
|
||||
```
|
||||
|
||||
### ✅ روش امن:
|
||||
|
||||
1. **فایلهای Template**: فایلهای `appsettings.Staging.json` و `appsettings.Production.json` به صورت template در Git هستند
|
||||
2. **مقادیر واقعی**: از **Environment Variables** یا **Kubernetes Secrets** استفاده کنید
|
||||
3. **CI/CD**: مقادیر حساس را از Azure Key Vault یا Kubernetes Secrets تزریق کنید
|
||||
|
||||
---
|
||||
|
||||
## 🚀 نحوه اجرا در محیطهای مختلف
|
||||
|
||||
### Local Development:
|
||||
```bash
|
||||
dotnet run --environment Development
|
||||
# یا
|
||||
export ASPNETCORE_ENVIRONMENT=Development
|
||||
dotnet run
|
||||
```
|
||||
|
||||
### Staging:
|
||||
```bash
|
||||
dotnet run --environment Staging
|
||||
```
|
||||
|
||||
### Production:
|
||||
```bash
|
||||
dotnet run --environment Production
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🐳 Docker
|
||||
|
||||
برای Docker، environment را با `-e` تنظیم کنید:
|
||||
|
||||
```bash
|
||||
docker run -e ASPNETCORE_ENVIRONMENT=Staging yourimage:tag
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ☸️ Kubernetes
|
||||
|
||||
در Deployment manifest:
|
||||
|
||||
```yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: cms-api
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: cms
|
||||
env:
|
||||
- name: ASPNETCORE_ENVIRONMENT
|
||||
value: "Production" # یا "Staging"
|
||||
# Override تنظیمات از Secrets
|
||||
- name: ConnectionStrings__DefaultConnection
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: cms-secrets
|
||||
key: db-connection
|
||||
- name: Sms__KavenegarApiKey
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: cms-secrets
|
||||
key: kavenegar-key
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📋 Checklist تنظیمات محیط Production
|
||||
|
||||
- [ ] ConnectionString database production
|
||||
- [ ] JwtSecurityKey یونیک
|
||||
- [ ] Sentry DSN
|
||||
- [ ] Slack Webhook
|
||||
- [ ] SMTP credentials
|
||||
- [ ] Kavenegar API Key
|
||||
- [ ] Daya API Key
|
||||
- [ ] Chatika API Key
|
||||
- [ ] Seq Server URL
|
||||
- [ ] SSL/TLS enabled
|
||||
- [ ] UseRealPaymentGateway = true
|
||||
- [ ] Background jobs enabled با cron صحیح
|
||||
|
||||
---
|
||||
|
||||
## 🔄 CI/CD Pipeline
|
||||
|
||||
### برای برنچ `kub-stage`:
|
||||
|
||||
```yaml
|
||||
# در GitLab CI یا GitHub Actions
|
||||
environment:
|
||||
name: staging
|
||||
variables:
|
||||
ASPNETCORE_ENVIRONMENT: "Staging"
|
||||
|
||||
# یا در Kubernetes ConfigMap:
|
||||
kubectl create secret generic cms-secrets \
|
||||
--from-literal=db-connection="..." \
|
||||
--from-literal=kavenegar-key="..." \
|
||||
--namespace=staging
|
||||
```
|
||||
|
||||
### برای برنچ `production`:
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
name: production
|
||||
variables:
|
||||
ASPNETCORE_ENVIRONMENT: "Production"
|
||||
|
||||
kubectl create secret generic cms-secrets \
|
||||
--from-literal=db-connection="..." \
|
||||
--from-literal=kavenegar-key="..." \
|
||||
--namespace=production
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🎛️ Override تنظیمات با Environment Variables
|
||||
|
||||
ASP.NET Core به صورت خودکار از environment variables استفاده میکند:
|
||||
|
||||
```bash
|
||||
# Format: Section__Property
|
||||
export ConnectionStrings__DefaultConnection="Server=..."
|
||||
export Sms__KavenegarApiKey="your-key"
|
||||
export BackgroundJobs__WeeklyCommissionCalculation__Enabled="true"
|
||||
```
|
||||
|
||||
**اولویت تنظیمات:**
|
||||
1. Environment Variables (بالاترین)
|
||||
2. appsettings.{Environment}.json
|
||||
3. appsettings.json (پایینترین)
|
||||
|
||||
---
|
||||
|
||||
## 📊 تفاوتهای کلیدی محیطها
|
||||
|
||||
| تنظیم | Development | Staging | Production |
|
||||
|-------|-------------|---------|------------|
|
||||
| Payment Gateway | Mock | Mock | Real |
|
||||
| SMS | Disabled | Disabled | Enabled |
|
||||
| Email | Disabled | Disabled | Enabled |
|
||||
| Sentry | Disabled | Enabled | Enabled |
|
||||
| Background Jobs | Disabled | Enabled | Enabled |
|
||||
| Log Level | Debug | Information | Warning |
|
||||
| Chatika | Disabled | Disabled | Enabled |
|
||||
| Daya API | Mock | Mock | Real |
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ تست تنظیمات
|
||||
|
||||
برای تست اینکه کدام فایل لود شده:
|
||||
|
||||
```csharp
|
||||
// در Program.cs یا Controller
|
||||
app.Logger.LogInformation("Environment: {Env}", app.Environment.EnvironmentName);
|
||||
app.Logger.LogInformation("Connection: {Conn}",
|
||||
app.Configuration.GetConnectionString("DefaultConnection"));
|
||||
```
|
||||
|
||||
یا از endpoint health check:
|
||||
```
|
||||
GET /health
|
||||
```
|
||||
Reference in New Issue
Block a user