mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-08-28 19:40:28 +00:00
Work on acme.sh hander
and dns providers
This commit is contained in:
@@ -33,16 +33,16 @@ func Create(provider *Model) (int, error) {
|
||||
created_on,
|
||||
modified_on,
|
||||
user_id,
|
||||
provider_key,
|
||||
name,
|
||||
acme_sh_name,
|
||||
meta,
|
||||
is_deleted
|
||||
) VALUES (
|
||||
:created_on,
|
||||
:modified_on,
|
||||
:user_id,
|
||||
:provider_key,
|
||||
:name,
|
||||
:acme_sh_name,
|
||||
:meta,
|
||||
:is_deleted
|
||||
)`, provider)
|
||||
@@ -73,8 +73,8 @@ func Update(provider *Model) error {
|
||||
created_on = :created_on,
|
||||
modified_on = :modified_on,
|
||||
user_id = :user_id,
|
||||
provider_key = :provider_key,
|
||||
name = :name,
|
||||
acme_sh_name = :acme_sh_name,
|
||||
meta = :meta,
|
||||
is_deleted = :is_deleted
|
||||
WHERE id = :id`, provider)
|
||||
|
@@ -14,14 +14,14 @@ const (
|
||||
|
||||
// Model is the user model
|
||||
type Model struct {
|
||||
ID int `json:"id" db:"id" filter:"id,integer"`
|
||||
CreatedOn types.DBDate `json:"created_on" db:"created_on" filter:"created_on,integer"`
|
||||
ModifiedOn types.DBDate `json:"modified_on" db:"modified_on" filter:"modified_on,integer"`
|
||||
UserID int `json:"user_id" db:"user_id" filter:"user_id,integer"`
|
||||
ProviderKey string `json:"provider_key" db:"provider_key" filter:"provider_key,string"`
|
||||
Name string `json:"name" db:"name" filter:"name,string"`
|
||||
Meta types.JSONB `json:"meta" db:"meta"`
|
||||
IsDeleted bool `json:"is_deleted,omitempty" db:"is_deleted"`
|
||||
ID int `json:"id" db:"id" filter:"id,integer"`
|
||||
CreatedOn types.DBDate `json:"created_on" db:"created_on" filter:"created_on,integer"`
|
||||
ModifiedOn types.DBDate `json:"modified_on" db:"modified_on" filter:"modified_on,integer"`
|
||||
UserID int `json:"user_id" db:"user_id" filter:"user_id,integer"`
|
||||
Name string `json:"name" db:"name" filter:"name,string"`
|
||||
AcmeShName string `json:"acme_sh_name" db:"acme_sh_name" filter:"acme_sh_name,string"`
|
||||
Meta types.JSONB `json:"meta" db:"meta"`
|
||||
IsDeleted bool `json:"is_deleted,omitempty" db:"is_deleted"`
|
||||
}
|
||||
|
||||
func (m *Model) getByQuery(query string, params []interface{}) error {
|
||||
@@ -71,3 +71,41 @@ func (m *Model) Delete() bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// GetAcmeShEnvVars returns the env vars required for acme.sh dns cert requests
|
||||
func (m *Model) GetAcmeShEnvVars() ([]string, error) {
|
||||
envs := make([]string, 0)
|
||||
switch m.AcmeShName {
|
||||
|
||||
// AWS
|
||||
case "dns_aws":
|
||||
envs = []string{
|
||||
"AWS_ACCESS_KEY_ID=\"sdfsdfsdfljlbjkljlkjsdfoiwje\"",
|
||||
"AWS_SECRET_ACCESS_KEY=\"xxxxxxx\"",
|
||||
}
|
||||
|
||||
// Cloudflare
|
||||
case "dns_cf":
|
||||
envs = []string{
|
||||
"CF_Key=\"sdfsdfsdfljlbjkljlkjsdfoiwje\"",
|
||||
"CF_Email=\"xxxx@sss.com\"",
|
||||
"CF_Token=\"xxxx\"",
|
||||
"CF_Account_ID=\"xxxx\"",
|
||||
"CF_Zone_ID=\"xxxx\"",
|
||||
}
|
||||
|
||||
// DuckDNS
|
||||
case "dns_duckdns":
|
||||
envs = []string{
|
||||
"DuckDNS_Token=\"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\"",
|
||||
}
|
||||
|
||||
// Njalla
|
||||
case "dns_njalla":
|
||||
envs = []string{
|
||||
"NJALLA_Token=\"sdfsdfsdfljlbjkljlkjsdfoiwje\"",
|
||||
}
|
||||
}
|
||||
|
||||
return envs, nil
|
||||
}
|
||||
|
70
backend/internal/entity/dnsprovider/model_test.go
Normal file
70
backend/internal/entity/dnsprovider/model_test.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package dnsprovider
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestModelGetAcmeShEnvVars(t *testing.T) {
|
||||
type want struct {
|
||||
envs []string
|
||||
err error
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
dnsProvider Model
|
||||
want want
|
||||
}{
|
||||
{
|
||||
name: "dns_aws",
|
||||
dnsProvider: Model{
|
||||
AcmeShName: "dns_aws",
|
||||
},
|
||||
want: want{
|
||||
envs: []string{
|
||||
"AWS_ACCESS_KEY_ID=\"sdfsdfsdfljlbjkljlkjsdfoiwje\"",
|
||||
"AWS_SECRET_ACCESS_KEY=\"xxxxxxx\"",
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "dns_cf",
|
||||
dnsProvider: Model{
|
||||
AcmeShName: "dns_cf",
|
||||
},
|
||||
want: want{
|
||||
envs: []string{
|
||||
"CF_Key=\"sdfsdfsdfljlbjkljlkjsdfoiwje\"",
|
||||
"CF_Email=\"xxxx@sss.com\"",
|
||||
"CF_Token=\"xxxx\"",
|
||||
"CF_Account_ID=\"xxxx\"",
|
||||
"CF_Zone_ID=\"xxxx\"",
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "dns_duckdns",
|
||||
dnsProvider: Model{
|
||||
AcmeShName: "dns_duckdns",
|
||||
},
|
||||
want: want{
|
||||
envs: []string{
|
||||
"DuckDNS_Token=\"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\"",
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
envs, err := tt.dnsProvider.GetAcmeShEnvVars()
|
||||
assert.Equal(t, tt.want.envs, envs)
|
||||
assert.Equal(t, tt.want.err, err)
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user