Skip to content

Commit fc2df47

Browse files
committed
Add certificate model for http and dns
change is_ecc to boolean, its still stored as int in sqlite
1 parent 7455acc commit fc2df47

File tree

22 files changed

+599
-71
lines changed

22 files changed

+599
-71
lines changed

backend/internal/api/schema/certificates.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ func createCertificateHTTP() string {
5151
"type": "object"
5252
},
5353
"is_ecc": {
54-
"type": "integer",
55-
"minimum": 0,
56-
"maximum": 1
54+
"type": "boolean"
5755
}
5856
}
5957
}`, strictString("http"), intMinOne, stringMinMax(1, 100), domainNames())
@@ -83,9 +81,7 @@ func createCertificateDNS() string {
8381
"type": "object"
8482
},
8583
"is_ecc": {
86-
"type": "integer",
87-
"minimum": 0,
88-
"maximum": 1
84+
"type": "boolean"
8985
}
9086
}
9187
}`, strictString("dns"), intMinOne, intMinOne, stringMinMax(1, 100), domainNames())

backend/internal/entity/certificate/model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type Model struct {
5757
Status string `json:"status" db:"status" filter:"status,string"`
5858
ErrorMessage string `json:"error_message" db:"error_message" filter:"error_message,string"`
5959
Meta types.JSONB `json:"-" db:"meta"`
60-
IsECC int `json:"is_ecc" db:"is_ecc" filter:"is_ecc,integer"`
60+
IsECC bool `json:"is_ecc" db:"is_ecc" filter:"is_ecc,bool"`
6161
IsDeleted bool `json:"is_deleted,omitempty" db:"is_deleted"`
6262
// Expansions:
6363
CertificateAuthority *certificateauthority.Model `json:"certificate_authority,omitempty"`

backend/internal/entity/certificate/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Template struct {
1313
Name string
1414
DomainNames []string
1515
Status string
16-
IsECC int
16+
IsECC bool
1717
// These are helpers for template generation
1818
IsCustom bool
1919
IsAcme bool // non-custom

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@typescript-eslint/parser": "^5.30.6",
2323
"ajv": "^8.12.0",
2424
"babel-eslint": "^10.1.0",
25+
"chakra-react-select": "^4.5.0",
2526
"classnames": "^2.3.1",
2627
"country-flag-icons": "^1.5.5",
2728
"date-fns": "2.28.0",

frontend/src/api/npm/models.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,16 @@ export interface Certificate {
5252
id: number;
5353
createdOn: number;
5454
modifiedOn: number;
55+
expiresOn: number | null;
56+
type: string;
57+
userId: number;
58+
certificateAuthorityId: number;
59+
dnsProviderId: number;
5560
name: string;
56-
acmeshServer: string;
57-
caBundle: string;
58-
maxDomains: number;
59-
isWildcardSupported: boolean;
60-
isSetup: boolean;
61+
domainNames: string[];
62+
status: string;
63+
errorMessage: string;
64+
isEcc: boolean;
6165
}
6266

6367
export interface CertificateAuthority {

frontend/src/hooks/useCertificate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const useSetCertificate = () => {
4747
onError: (error, values, rollback: any) => rollback(),
4848
onSuccess: async ({ id }: Certificate) => {
4949
queryClient.invalidateQueries(["certificate", id]);
50-
queryClient.invalidateQueries("certificate");
50+
queryClient.invalidateQueries("certificates");
5151
},
5252
},
5353
);

frontend/src/hooks/useCertificates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const useCertificates = (
2828
options = {},
2929
) => {
3030
return useQuery<CertificatesResponse, Error>(
31-
["hosts", { offset, limit, sortBy, filters }],
31+
["certificates", { offset, limit, sortBy, filters }],
3232
() => fetchCertificates(offset, limit, sortBy, filters),
3333
{
3434
keepPreviousData: true,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
# Certificates Help
22

3+
## HTTP Certificate
4+
5+
todo
6+
7+
## DNS Certificate
8+
9+
todo
10+
11+
## Custom Certificate
12+
13+
todo
14+
15+
## MKCert Certificate
16+
317
todo

frontend/src/locale/src/en.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@
314314
"certificate-authorities.title": {
315315
"defaultMessage": "Certificate Authorities"
316316
},
317+
"certificate-authority": {
318+
"defaultMessage": "Certificate Authority"
319+
},
317320
"certificate-authority.acmesh-server": {
318321
"defaultMessage": "ACME Server"
319322
},
@@ -404,12 +407,24 @@
404407
"disabled": {
405408
"defaultMessage": "Disabled"
406409
},
410+
"dns-provider": {
411+
"defaultMessage": "DNS Provider"
412+
},
407413
"dns-provider.acmesh-name": {
408414
"defaultMessage": "Acme.sh Provider"
409415
},
410416
"dns-provider.create": {
411417
"defaultMessage": "Create DNS Provider"
412418
},
419+
"dns-providers-empty": {
420+
"defaultMessage": "No DNS Providers - Create one first"
421+
},
422+
"domain_names": {
423+
"defaultMessage": "Domain Names"
424+
},
425+
"domain_names.max": {
426+
"defaultMessage": "{count} ___domain names maximum"
427+
},
413428
"name": {
414429
"defaultMessage": "Name"
415430
},
@@ -524,6 +539,9 @@
524539
"https-only": {
525540
"defaultMessage": "HTTPS Only"
526541
},
542+
"is-ecc": {
543+
"defaultMessage": "ECC Certificate"
544+
},
527545
"lets-go": {
528546
"defaultMessage": "Let's go"
529547
},
@@ -638,6 +656,9 @@
638656
"type.http": {
639657
"defaultMessage": "HTTP"
640658
},
659+
"type.mkcert": {
660+
"defaultMessage": "MKCert"
661+
},
641662
"type.proxy": {
642663
"defaultMessage": "Proxy Host"
643664
},

frontend/src/modals/CertificateCreateModal/CertificateCreateModal.tsx

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import {
22
Button,
3-
FormControl,
4-
FormErrorMessage,
5-
FormLabel,
6-
Input,
73
Modal,
84
ModalOverlay,
95
ModalContent,
@@ -16,14 +12,14 @@ import {
1612
} from "@chakra-ui/react";
1713
import { Certificate } from "api/npm";
1814
import { PrettyButton } from "components";
19-
import { Formik, Form, Field } from "formik";
15+
import { Formik, Form } from "formik";
2016
import { useSetCertificate } from "hooks";
2117
import { intl } from "locale";
22-
import { validateString } from "modules/Validations";
2318

2419
import CustomForm from "./CustomForm";
2520
import DNSForm from "./DNSForm";
2621
import HTTPForm from "./HTTPForm";
22+
import MKCertForm from "./MKCertForm";
2723

2824
interface CertificateCreateModalProps {
2925
isOpen: boolean;
@@ -44,8 +40,9 @@ function CertificateCreateModal({
4440

4541
const onSubmit = async (
4642
payload: Certificate,
47-
{ setErrors, setSubmitting }: any,
43+
{ /*setErrors,*/ setSubmitting }: any,
4844
) => {
45+
payload.type = certType;
4946
const showErr = (msg: string) => {
5047
toast({
5148
description: intl.formatMessage({
@@ -60,6 +57,8 @@ function CertificateCreateModal({
6057

6158
setCertificate(payload, {
6259
onError: (err: any) => {
60+
showErr(err.message);
61+
/*
6362
if (err.message === "ca-bundle-does-not-exist") {
6463
setErrors({
6564
caBundle: intl.formatMessage({
@@ -68,28 +67,52 @@ function CertificateCreateModal({
6867
});
6968
} else {
7069
showErr(err.message);
71-
}
70+
}*/
7271
},
7372
onSuccess: () => onModalClose(),
7473
onSettled: () => setSubmitting(false),
7574
});
7675
};
7776

77+
const getInitialValues = (type: string): any => {
78+
switch (type) {
79+
case "http":
80+
return {
81+
certificateAuthorityId: 0,
82+
name: "",
83+
domainNames: [],
84+
isEcc: false,
85+
} as any;
86+
case "dns":
87+
return {
88+
certificateAuthorityId: 0,
89+
dnsProviderId: 0,
90+
name: "",
91+
domainNames: [],
92+
isEcc: false,
93+
} as any;
94+
case "custom":
95+
return {
96+
name: "",
97+
domainNames: [],
98+
// isEcc: false, // todo, required?
99+
// todo: add meta?
100+
} as any;
101+
case "mkcert":
102+
return {
103+
name: "",
104+
domainNames: [],
105+
// isEcc: false, // todo, supported?
106+
// todo: add meta?
107+
} as any;
108+
}
109+
};
110+
78111
return (
79112
<Modal isOpen={isOpen} onClose={onModalClose} closeOnOverlayClick={false}>
80113
<ModalOverlay />
81114
<ModalContent>
82-
<Formik
83-
initialValues={
84-
{
85-
name: "",
86-
acmeshServer: "",
87-
caBundle: "",
88-
maxDomains: 5,
89-
isWildcardSupported: false,
90-
} as Certificate
91-
}
92-
onSubmit={onSubmit}>
115+
<Formik initialValues={getInitialValues(certType)} onSubmit={onSubmit}>
93116
{({ isSubmitting }) => (
94117
<Form>
95118
<ModalHeader>
@@ -98,39 +121,16 @@ function CertificateCreateModal({
98121
<ModalCloseButton />
99122
<ModalBody>
100123
<Stack spacing={4}>
101-
<Field name="name" validate={validateString(1, 100)}>
102-
{({ field, form }: any) => (
103-
<FormControl
104-
isRequired
105-
isInvalid={form.errors.name && form.touched.name}>
106-
<FormLabel htmlFor="name">
107-
{intl.formatMessage({
108-
id: "name",
109-
})}
110-
</FormLabel>
111-
<Input
112-
{...field}
113-
id="name"
114-
placeholder={intl.formatMessage({
115-
id: "name",
116-
})}
117-
/>
118-
<FormErrorMessage>{form.errors.name}</FormErrorMessage>
119-
</FormControl>
120-
)}
121-
</Field>
124+
{certType === "http" ? <HTTPForm /> : null}
125+
{certType === "dns" ? <DNSForm /> : null}
126+
{certType === "custom" ? <CustomForm /> : null}
127+
{certType === "mkcert" ? <MKCertForm /> : null}
122128
</Stack>
123-
124-
{certType === "http" ? <HTTPForm /> : null}
125-
{certType === "dns" ? <DNSForm /> : null}
126-
{certType === "custom" ? <CustomForm /> : null}
127129
</ModalBody>
128130
<ModalFooter>
129-
{certType !== "" ? (
130-
<PrettyButton mr={3} isLoading={isSubmitting}>
131-
{intl.formatMessage({ id: "form.save" })}
132-
</PrettyButton>
133-
) : null}
131+
<PrettyButton mr={3} isLoading={isSubmitting}>
132+
{intl.formatMessage({ id: "form.save" })}
133+
</PrettyButton>
134134
<Button onClick={onModalClose} isLoading={isSubmitting}>
135135
{intl.formatMessage({ id: "form.cancel" })}
136136
</Button>

0 commit comments

Comments
 (0)