Add IntranetEndpoint to provider.

This commit is contained in:
Gucheng Wang 2021-12-04 16:35:33 +08:00
parent c8b8488797
commit dc9d2389a5
12 changed files with 68 additions and 21 deletions

View File

@ -8,6 +8,7 @@ dataSourceName = root:123456@tcp(localhost:3306)/
dbName = casdoor dbName = casdoor
redisEndpoint = redisEndpoint =
defaultStorageProvider = defaultStorageProvider =
isCloudIntranet = false
authState = "casdoor" authState = "casdoor"
httpProxy = "127.0.0.1:10808" httpProxy = "127.0.0.1:10808"
verificationCodeTimeout = 10 verificationCodeTimeout = 10

View File

@ -44,6 +44,7 @@ type Provider struct {
AppId string `xorm:"varchar(100)" json:"appId"` AppId string `xorm:"varchar(100)" json:"appId"`
Endpoint string `xorm:"varchar(100)" json:"endpoint"` Endpoint string `xorm:"varchar(100)" json:"endpoint"`
IntranetEndpoint string `xorm:"varchar(100)" json:"intranetEndpoint"`
Domain string `xorm:"varchar(100)" json:"domain"` Domain string `xorm:"varchar(100)" json:"domain"`
Bucket string `xorm:"varchar(100)" json:"bucket"` Bucket string `xorm:"varchar(100)" json:"bucket"`

View File

@ -19,10 +19,29 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/astaxie/beego"
"github.com/casbin/casdoor/storage" "github.com/casbin/casdoor/storage"
"github.com/casbin/casdoor/util" "github.com/casbin/casdoor/util"
) )
var isCloudIntranet bool
func init() {
var err error
isCloudIntranet, err = beego.AppConfig.Bool("isCloudIntranet")
if err != nil {
panic(err)
}
}
func getProviderEndpoint(provider *Provider) string {
endpoint := provider.Endpoint
if provider.IntranetEndpoint != "" && isCloudIntranet {
endpoint = provider.IntranetEndpoint
}
return endpoint
}
func getUploadFileUrl(provider *Provider, fullFilePath string, hasTimestamp bool) (string, string) { func getUploadFileUrl(provider *Provider, fullFilePath string, hasTimestamp bool) (string, string) {
objectKey := util.UrlJoin(util.GetUrlPath(provider.Domain), fullFilePath) objectKey := util.UrlJoin(util.GetUrlPath(provider.Domain), fullFilePath)
@ -47,7 +66,8 @@ func getUploadFileUrl(provider *Provider, fullFilePath string, hasTimestamp bool
} }
func uploadFile(provider *Provider, fullFilePath string, fileBuffer *bytes.Buffer) (string, string, error) { func uploadFile(provider *Provider, fullFilePath string, fileBuffer *bytes.Buffer) (string, string, error) {
storageProvider := storage.GetStorageProvider(provider.Type, provider.ClientId, provider.ClientSecret, provider.RegionId, provider.Bucket, provider.Endpoint) endpoint := getProviderEndpoint(provider)
storageProvider := storage.GetStorageProvider(provider.Type, provider.ClientId, provider.ClientSecret, provider.RegionId, provider.Bucket, endpoint)
if storageProvider == nil { if storageProvider == nil {
return "", "", fmt.Errorf("the provider type: %s is not supported", provider.Type) return "", "", fmt.Errorf("the provider type: %s is not supported", provider.Type)
} }
@ -87,7 +107,8 @@ func UploadFileSafe(provider *Provider, fullFilePath string, fileBuffer *bytes.B
} }
func DeleteFile(provider *Provider, objectKey string) error { func DeleteFile(provider *Provider, objectKey string) error {
storageProvider := storage.GetStorageProvider(provider.Type, provider.ClientId, provider.ClientSecret, provider.RegionId, provider.Bucket, provider.Endpoint) endpoint := getProviderEndpoint(provider)
storageProvider := storage.GetStorageProvider(provider.Type, provider.ClientId, provider.ClientSecret, provider.RegionId, provider.Bucket, endpoint)
if storageProvider == nil { if storageProvider == nil {
return fmt.Errorf("the provider type: %s is not supported", provider.Type) return fmt.Errorf("the provider type: %s is not supported", provider.Type)
} }

View File

@ -272,7 +272,7 @@ class ProviderEditPage extends React.Component {
<div> <div>
<Row style={{marginTop: '20px'}} > <Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={2}> <Col style={{marginTop: '5px'}} span={2}>
{Setting.getLabel(i18next.t("provider:Endpoint"), i18next.t("provider:Endpoint - Tooltip"))} : {Setting.getLabel(i18next.t("provider:Endpoint"), i18next.t("provider:Region endpoint for Internet"))} :
</Col> </Col>
<Col span={22} > <Col span={22} >
<Input value={this.state.provider.endpoint} onChange={e => { <Input value={this.state.provider.endpoint} onChange={e => {
@ -280,6 +280,16 @@ class ProviderEditPage extends React.Component {
}} /> }} />
</Col> </Col>
</Row> </Row>
<Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={2}>
{Setting.getLabel(i18next.t("provider:Endpoint (Intranet)"), i18next.t("provider:Region endpoint for Intranet"))} :
</Col>
<Col span={22} >
<Input value={this.state.provider.intranetEndpoint} onChange={e => {
this.updateProviderField('intranetEndpoint', e.target.value);
}} />
</Col>
</Row>
<Row style={{marginTop: '20px'}} > <Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={2}> <Col style={{marginTop: '5px'}} span={2}>
{Setting.getLabel(i18next.t("provider:Bucket"), i18next.t("provider:Bucket - Tooltip"))} : {Setting.getLabel(i18next.t("provider:Bucket"), i18next.t("provider:Bucket - Tooltip"))} :

View File

@ -168,13 +168,13 @@ class ResourceListPage extends React.Component {
width: '80px', width: '80px',
sorter: (a, b) => a.tag.localeCompare(b.tag), sorter: (a, b) => a.tag.localeCompare(b.tag),
}, },
{ // {
title: i18next.t("resource:File name"), // title: i18next.t("resource:File name"),
dataIndex: 'fileName', // dataIndex: 'fileName',
key: 'fileName', // key: 'fileName',
width: '120px', // width: '120px',
sorter: (a, b) => a.fileName.localeCompare(b.fileName), // sorter: (a, b) => a.fileName.localeCompare(b.fileName),
}, // },
{ {
title: i18next.t("resource:Type"), title: i18next.t("resource:Type"),
dataIndex: 'fileType', dataIndex: 'fileType',

View File

@ -214,7 +214,7 @@
"Email Title": "Email Title", "Email Title": "Email Title",
"Email Title - Tooltip": "Unique string-style identifier", "Email Title - Tooltip": "Unique string-style identifier",
"Endpoint": "Endpoint", "Endpoint": "Endpoint",
"Endpoint - Tooltip": "Storage bucket endpoint", "Endpoint (Intranet)": "Endpoint (Intranet)",
"Host": "Host", "Host": "Host",
"Host - Tooltip": "Unique string-style identifier", "Host - Tooltip": "Unique string-style identifier",
"Method": "Method", "Method": "Method",
@ -226,6 +226,8 @@
"Provider URL - Tooltip": "Unique string-style identifier", "Provider URL - Tooltip": "Unique string-style identifier",
"Region ID": "Region ID", "Region ID": "Region ID",
"Region ID - Tooltip": "Region ID - Tooltip", "Region ID - Tooltip": "Region ID - Tooltip",
"Region endpoint for Internet": "Region endpoint for Internet",
"Region endpoint for Intranet": "Region endpoint for Intranet",
"Secret access key": "Secret access key", "Secret access key": "Secret access key",
"SecretAccessKey - Tooltip": "SecretAccessKey - Tooltip", "SecretAccessKey - Tooltip": "SecretAccessKey - Tooltip",
"Sign Name": "Sign Name", "Sign Name": "Sign Name",

View File

@ -214,7 +214,7 @@
"Email Title": "Email Title", "Email Title": "Email Title",
"Email Title - Tooltip": "Email Title - Tooltip", "Email Title - Tooltip": "Email Title - Tooltip",
"Endpoint": "Endpoint", "Endpoint": "Endpoint",
"Endpoint - Tooltip": "Endpoint - Tooltip", "Endpoint (Intranet)": "Endpoint (Intranet)",
"Host": "Host", "Host": "Host",
"Host - Tooltip": "Host - Tooltip", "Host - Tooltip": "Host - Tooltip",
"Method": "Method", "Method": "Method",
@ -226,6 +226,8 @@
"Provider URL - Tooltip": "Provider URL - Tooltip", "Provider URL - Tooltip": "Provider URL - Tooltip",
"Region ID": "Region ID", "Region ID": "Region ID",
"Region ID - Tooltip": "Region ID - Tooltip", "Region ID - Tooltip": "Region ID - Tooltip",
"Region endpoint for Internet": "Region endpoint for Internet",
"Region endpoint for Intranet": "Region endpoint for Intranet",
"Secret access key": "Secret access key", "Secret access key": "Secret access key",
"SecretAccessKey - Tooltip": "SecretAccessKey - Tooltip", "SecretAccessKey - Tooltip": "SecretAccessKey - Tooltip",
"Sign Name": "Sign Name", "Sign Name": "Sign Name",

View File

@ -214,7 +214,7 @@
"Email Title": "Email Title", "Email Title": "Email Title",
"Email Title - Tooltip": "Unique string-style identifier", "Email Title - Tooltip": "Unique string-style identifier",
"Endpoint": "Endpoint", "Endpoint": "Endpoint",
"Endpoint - Tooltip": "Storage bucket endpoint", "Endpoint (Intranet)": "Endpoint (Intranet)",
"Host": "Host", "Host": "Host",
"Host - Tooltip": "Unique string-style identifier", "Host - Tooltip": "Unique string-style identifier",
"Method": "Method", "Method": "Method",
@ -226,6 +226,8 @@
"Provider URL - Tooltip": "Unique string-style identifier", "Provider URL - Tooltip": "Unique string-style identifier",
"Region ID": "Region ID", "Region ID": "Region ID",
"Region ID - Tooltip": "Region ID - Tooltip", "Region ID - Tooltip": "Region ID - Tooltip",
"Region endpoint for Internet": "Region endpoint for Internet",
"Region endpoint for Intranet": "Region endpoint for Intranet",
"Secret access key": "Secret access key", "Secret access key": "Secret access key",
"SecretAccessKey - Tooltip": "SecretAccessKey - Tooltip", "SecretAccessKey - Tooltip": "SecretAccessKey - Tooltip",
"Sign Name": "Sign Name", "Sign Name": "Sign Name",

View File

@ -214,7 +214,7 @@
"Email Title": "Email Title", "Email Title": "Email Title",
"Email Title - Tooltip": "Unique string-style identifier", "Email Title - Tooltip": "Unique string-style identifier",
"Endpoint": "Endpoint", "Endpoint": "Endpoint",
"Endpoint - Tooltip": "Storage bucket endpoint", "Endpoint (Intranet)": "Endpoint (Intranet)",
"Host": "Host", "Host": "Host",
"Host - Tooltip": "Unique string-style identifier", "Host - Tooltip": "Unique string-style identifier",
"Method": "Method", "Method": "Method",
@ -226,6 +226,8 @@
"Provider URL - Tooltip": "Unique string-style identifier", "Provider URL - Tooltip": "Unique string-style identifier",
"Region ID": "Region ID", "Region ID": "Region ID",
"Region ID - Tooltip": "Region ID - Tooltip", "Region ID - Tooltip": "Region ID - Tooltip",
"Region endpoint for Internet": "Region endpoint for Internet",
"Region endpoint for Intranet": "Region endpoint for Intranet",
"Secret access key": "Secret access key", "Secret access key": "Secret access key",
"SecretAccessKey - Tooltip": "SecretAccessKey - Tooltip", "SecretAccessKey - Tooltip": "SecretAccessKey - Tooltip",
"Sign Name": "Sign Name", "Sign Name": "Sign Name",

View File

@ -214,7 +214,7 @@
"Email Title": "Email Title", "Email Title": "Email Title",
"Email Title - Tooltip": "Unique string-style identifier", "Email Title - Tooltip": "Unique string-style identifier",
"Endpoint": "Endpoint", "Endpoint": "Endpoint",
"Endpoint - Tooltip": "Storage bucket endpoint", "Endpoint (Intranet)": "Endpoint (Intranet)",
"Host": "Host", "Host": "Host",
"Host - Tooltip": "Unique string-style identifier", "Host - Tooltip": "Unique string-style identifier",
"Method": "Method", "Method": "Method",
@ -226,6 +226,8 @@
"Provider URL - Tooltip": "Unique string-style identifier", "Provider URL - Tooltip": "Unique string-style identifier",
"Region ID": "Region ID", "Region ID": "Region ID",
"Region ID - Tooltip": "Region ID - Tooltip", "Region ID - Tooltip": "Region ID - Tooltip",
"Region endpoint for Internet": "Region endpoint for Internet",
"Region endpoint for Intranet": "Region endpoint for Intranet",
"Secret access key": "Secret access key", "Secret access key": "Secret access key",
"SecretAccessKey - Tooltip": "SecretAccessKey - Tooltip", "SecretAccessKey - Tooltip": "SecretAccessKey - Tooltip",
"Sign Name": "Sign Name", "Sign Name": "Sign Name",

View File

@ -214,7 +214,7 @@
"Email Title": "Email Title", "Email Title": "Email Title",
"Email Title - Tooltip": "Unique string-style identifier", "Email Title - Tooltip": "Unique string-style identifier",
"Endpoint": "Endpoint", "Endpoint": "Endpoint",
"Endpoint - Tooltip": "Storage bucket endpoint", "Endpoint (Intranet)": "Endpoint (Intranet)",
"Host": "Host", "Host": "Host",
"Host - Tooltip": "Unique string-style identifier", "Host - Tooltip": "Unique string-style identifier",
"Method": "Method", "Method": "Method",
@ -226,6 +226,8 @@
"Provider URL - Tooltip": "Unique string-style identifier", "Provider URL - Tooltip": "Unique string-style identifier",
"Region ID": "Region ID", "Region ID": "Region ID",
"Region ID - Tooltip": "Region ID - Tooltip", "Region ID - Tooltip": "Region ID - Tooltip",
"Region endpoint for Internet": "Region endpoint for Internet",
"Region endpoint for Intranet": "Region endpoint for Intranet",
"Secret access key": "Secret access key", "Secret access key": "Secret access key",
"SecretAccessKey - Tooltip": "SecretAccessKey - Tooltip", "SecretAccessKey - Tooltip": "SecretAccessKey - Tooltip",
"Sign Name": "Sign Name", "Sign Name": "Sign Name",

View File

@ -213,8 +213,8 @@
"Email Content - Tooltip": "邮件内容", "Email Content - Tooltip": "邮件内容",
"Email Title": "邮件标题", "Email Title": "邮件标题",
"Email Title - Tooltip": "邮件标题", "Email Title - Tooltip": "邮件标题",
"Endpoint": "Endpoint", "Endpoint": "地域节点 (外网)",
"Endpoint - Tooltip": "地域节点地址", "Endpoint (Intranet)": "地域节点 (内网)",
"Host": "主机", "Host": "主机",
"Host - Tooltip": "主机", "Host - Tooltip": "主机",
"Method": "方式", "Method": "方式",
@ -226,6 +226,8 @@
"Provider URL - Tooltip": "提供商URL", "Provider URL - Tooltip": "提供商URL",
"Region ID": "地域ID", "Region ID": "地域ID",
"Region ID - Tooltip": "地域ID", "Region ID - Tooltip": "地域ID",
"Region endpoint for Internet": "地域节点 (外网)",
"Region endpoint for Intranet": "地域节点 (内网)",
"Secret access key": "Secret access key", "Secret access key": "Secret access key",
"SecretAccessKey - Tooltip": "SecretAccessKey - Tooltip", "SecretAccessKey - Tooltip": "SecretAccessKey - Tooltip",
"Sign Name": "签名名称", "Sign Name": "签名名称",