mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 13:39:53 +00:00
refactor: clean code
This commit is contained in:
parent
4883b3bb88
commit
382de0d6d6
@ -73,12 +73,7 @@ func NewWithApplyNode(node *domain.WorkflowNode) (Applicant, error) {
|
|||||||
if access, err := accessRepo.GetById(context.Background(), nodeConfig.ProviderAccessId); err != nil {
|
if access, err := accessRepo.GetById(context.Background(), nodeConfig.ProviderAccessId); err != nil {
|
||||||
return nil, fmt.Errorf("failed to get access #%s record: %w", nodeConfig.ProviderAccessId, err)
|
return nil, fmt.Errorf("failed to get access #%s record: %w", nodeConfig.ProviderAccessId, err)
|
||||||
} else {
|
} else {
|
||||||
accessConfig, err := access.UnmarshalConfigToMap()
|
options.ProviderAccessConfig = access.Config
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to unmarshal access config: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
options.ProviderAccessConfig = accessConfig
|
|
||||||
}
|
}
|
||||||
|
|
||||||
certRepo := repository.NewCertificateRepository()
|
certRepo := repository.NewCertificateRepository()
|
||||||
|
@ -39,14 +39,9 @@ func NewWithDeployNode(node *domain.WorkflowNode, certdata struct {
|
|||||||
return nil, fmt.Errorf("failed to get access #%s record: %w", nodeConfig.ProviderAccessId, err)
|
return nil, fmt.Errorf("failed to get access #%s record: %w", nodeConfig.ProviderAccessId, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
accessConfig, err := access.UnmarshalConfigToMap()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to unmarshal access config: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
deployer, err := createDeployer(&deployerOptions{
|
deployer, err := createDeployer(&deployerOptions{
|
||||||
Provider: domain.DeployProviderType(nodeConfig.Provider),
|
Provider: domain.DeployProviderType(nodeConfig.Provider),
|
||||||
ProviderAccessConfig: accessConfig,
|
ProviderAccessConfig: access.Config,
|
||||||
ProviderDeployConfig: nodeConfig.ProviderConfig,
|
ProviderDeployConfig: nodeConfig.ProviderConfig,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package domain
|
package domain
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,19 +10,10 @@ type Access struct {
|
|||||||
Meta
|
Meta
|
||||||
Name string `json:"name" db:"name"`
|
Name string `json:"name" db:"name"`
|
||||||
Provider string `json:"provider" db:"provider"`
|
Provider string `json:"provider" db:"provider"`
|
||||||
Config string `json:"config" db:"config"`
|
Config map[string]any `json:"config" db:"config"`
|
||||||
DeletedAt *time.Time `json:"deleted" db:"deleted"`
|
DeletedAt *time.Time `json:"deleted" db:"deleted"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Access) UnmarshalConfigToMap() (map[string]any, error) {
|
|
||||||
config := make(map[string]any)
|
|
||||||
if err := json.Unmarshal([]byte(a.Config), &config); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type AccessConfigFor1Panel struct {
|
type AccessConfigFor1Panel struct {
|
||||||
ApiUrl string `json:"apiUrl"`
|
ApiUrl string `json:"apiUrl"`
|
||||||
ApiKey string `json:"apiKey"`
|
ApiKey string `json:"apiKey"`
|
||||||
|
@ -39,6 +39,11 @@ func (r *AccessRepository) castRecordToModel(record *core.Record) (*domain.Acces
|
|||||||
return nil, fmt.Errorf("record is nil")
|
return nil, fmt.Errorf("record is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config := make(map[string]any)
|
||||||
|
if err := record.UnmarshalJSONField("config", &config); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
access := &domain.Access{
|
access := &domain.Access{
|
||||||
Meta: domain.Meta{
|
Meta: domain.Meta{
|
||||||
Id: record.Id,
|
Id: record.Id,
|
||||||
@ -47,7 +52,7 @@ func (r *AccessRepository) castRecordToModel(record *core.Record) (*domain.Acces
|
|||||||
},
|
},
|
||||||
Name: record.GetString("name"),
|
Name: record.GetString("name"),
|
||||||
Provider: record.GetString("provider"),
|
Provider: record.GetString("provider"),
|
||||||
Config: record.GetString("config"),
|
Config: config,
|
||||||
}
|
}
|
||||||
return access, nil
|
return access, nil
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ import Show from "@/components/Show";
|
|||||||
import { type CertificateModel } from "@/domain/certificate";
|
import { type CertificateModel } from "@/domain/certificate";
|
||||||
import type { WorkflowLogModel } from "@/domain/workflowLog";
|
import type { WorkflowLogModel } from "@/domain/workflowLog";
|
||||||
import { WORKFLOW_RUN_STATUSES, type WorkflowRunModel } from "@/domain/workflowRun";
|
import { WORKFLOW_RUN_STATUSES, type WorkflowRunModel } from "@/domain/workflowRun";
|
||||||
|
import { useBrowserTheme } from "@/hooks";
|
||||||
import { listByWorkflowRunId as listCertificatesByWorkflowRunId } from "@/repository/certificate";
|
import { listByWorkflowRunId as listCertificatesByWorkflowRunId } from "@/repository/certificate";
|
||||||
import { listByWorkflowRunId as listLogsByWorkflowRunId } from "@/repository/workflowLog";
|
import { listByWorkflowRunId as listLogsByWorkflowRunId } from "@/repository/workflowLog";
|
||||||
import { mergeCls } from "@/utils/css";
|
import { mergeCls } from "@/utils/css";
|
||||||
@ -67,6 +68,7 @@ const WorkflowRunLogs = ({ runId, runStatus }: { runId: string; runStatus: strin
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { token: themeToken } = theme.useToken();
|
const { token: themeToken } = theme.useToken();
|
||||||
|
const { theme: browserTheme } = useBrowserTheme();
|
||||||
|
|
||||||
type Log = Pick<WorkflowLogModel, "timestamp" | "level" | "message" | "data">;
|
type Log = Pick<WorkflowLogModel, "timestamp" | "level" | "message" | "data">;
|
||||||
type LogGroup = { id: string; name: string; records: Log[] };
|
type LogGroup = { id: string; name: string; records: Log[] };
|
||||||
@ -212,7 +214,7 @@ const WorkflowRunLogs = ({ runId, runStatus }: { runId: string; runStatus: strin
|
|||||||
}}
|
}}
|
||||||
trigger={["click"]}
|
trigger={["click"]}
|
||||||
>
|
>
|
||||||
<Button icon={<SettingOutlinedIcon />} ghost />
|
<Button color="primary" icon={<SettingOutlinedIcon />} ghost={browserTheme === "light"} />
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user