Skip to content

Commit 429dbbc

Browse files
committed
[csr] add private_server certificate type
1 parent d033236 commit 429dbbc

File tree

14 files changed

+258
-30
lines changed

14 files changed

+258
-30
lines changed

api/docs.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ const docTemplate = `{
131131
"CSRStatusDenied"
132132
]
133133
},
134+
"ca.CSRType": {
135+
"type": "string",
136+
"enum": [
137+
"webhook",
138+
"private_server"
139+
],
140+
"x-enum-varnames": [
141+
"CSRTypeWebhook",
142+
"CSRTypePrivateServer"
143+
]
144+
},
134145
"ca.GetCSRStatusResponse": {
135146
"type": "object",
136147
"properties": {
@@ -153,6 +164,14 @@ const docTemplate = `{
153164
"$ref": "#/definitions/ca.CSRStatus"
154165
}
155166
]
167+
},
168+
"type": {
169+
"description": "Type is the type of the requested certificate.",
170+
"allOf": [
171+
{
172+
"$ref": "#/definitions/ca.CSRType"
173+
}
174+
]
156175
}
157176
}
158177
},
@@ -173,6 +192,15 @@ const docTemplate = `{
173192
"additionalProperties": {
174193
"type": "string"
175194
}
195+
},
196+
"type": {
197+
"description": "Type is the type of the CSR. By default, it is set to \"webhook\".",
198+
"default": "webhook",
199+
"allOf": [
200+
{
201+
"$ref": "#/definitions/ca.CSRType"
202+
}
203+
]
176204
}
177205
}
178206
},
@@ -198,6 +226,14 @@ const docTemplate = `{
198226
"$ref": "#/definitions/ca.CSRStatus"
199227
}
200228
]
229+
},
230+
"type": {
231+
"description": "Type is the type of the requested certificate.",
232+
"allOf": [
233+
{
234+
"$ref": "#/definitions/ca.CSRType"
235+
}
236+
]
201237
}
202238
}
203239
},

api/swagger.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@
128128
"CSRStatusDenied"
129129
]
130130
},
131+
"ca.CSRType": {
132+
"type": "string",
133+
"enum": [
134+
"webhook",
135+
"private_server"
136+
],
137+
"x-enum-varnames": [
138+
"CSRTypeWebhook",
139+
"CSRTypePrivateServer"
140+
]
141+
},
131142
"ca.GetCSRStatusResponse": {
132143
"type": "object",
133144
"properties": {
@@ -150,6 +161,14 @@
150161
"$ref": "#/definitions/ca.CSRStatus"
151162
}
152163
]
164+
},
165+
"type": {
166+
"description": "Type is the type of the requested certificate.",
167+
"allOf": [
168+
{
169+
"$ref": "#/definitions/ca.CSRType"
170+
}
171+
]
153172
}
154173
}
155174
},
@@ -170,6 +189,15 @@
170189
"additionalProperties": {
171190
"type": "string"
172191
}
192+
},
193+
"type": {
194+
"description": "Type is the type of the CSR. By default, it is set to \"webhook\".",
195+
"default": "webhook",
196+
"allOf": [
197+
{
198+
"$ref": "#/definitions/ca.CSRType"
199+
}
200+
]
173201
}
174202
}
175203
},
@@ -195,6 +223,14 @@
195223
"$ref": "#/definitions/ca.CSRStatus"
196224
}
197225
]
226+
},
227+
"type": {
228+
"description": "Type is the type of the requested certificate.",
229+
"allOf": [
230+
{
231+
"$ref": "#/definitions/ca.CSRType"
232+
}
233+
]
198234
}
199235
}
200236
},

api/swagger.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ definitions:
1010
- CSRStatusPending
1111
- CSRStatusApproved
1212
- CSRStatusDenied
13+
ca.CSRType:
14+
enum:
15+
- webhook
16+
- private_server
17+
type: string
18+
x-enum-varnames:
19+
- CSRTypeWebhook
20+
- CSRTypePrivateServer
1321
ca.GetCSRStatusResponse:
1422
properties:
1523
certificate:
@@ -27,6 +35,10 @@ definitions:
2735
allOf:
2836
- $ref: '#/definitions/ca.CSRStatus'
2937
description: Status is the status of the requested certificate.
38+
type:
39+
allOf:
40+
- $ref: '#/definitions/ca.CSRType'
41+
description: Type is the type of the requested certificate.
3042
type: object
3143
ca.PostCSRRequest:
3244
properties:
@@ -39,6 +51,11 @@ definitions:
3951
type: string
4052
description: Metadata includes additional metadata related to the CSR.
4153
type: object
54+
type:
55+
allOf:
56+
- $ref: '#/definitions/ca.CSRType'
57+
default: webhook
58+
description: Type is the type of the CSR. By default, it is set to "webhook".
4259
required:
4360
- content
4461
type: object
@@ -59,6 +76,10 @@ definitions:
5976
allOf:
6077
- $ref: '#/definitions/ca.CSRStatus'
6178
description: Status is the status of the requested certificate.
79+
type:
80+
allOf:
81+
- $ref: '#/definitions/ca.CSRType'
82+
description: Type is the type of the requested certificate.
6283
type: object
6384
http.JSONErrorResponse:
6485
properties:

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module github.com/android-sms-gateway/ca
33
go 1.23.2
44

55
require (
6-
github.com/android-sms-gateway/client-go v1.5.0
6+
github.com/android-sms-gateway/client-go v1.5.5
7+
github.com/go-playground/assert/v2 v2.2.0
78
github.com/go-playground/validator/v10 v10.23.0
89
github.com/gofiber/contrib/fiberzap/v2 v2.1.4
910
github.com/gofiber/fiber/v2 v2.52.6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
22
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
3-
github.com/android-sms-gateway/client-go v1.5.0 h1:CDREtWU2Z85dW7JcsW3a+vKZkj9g2Buq8vlrnEdGaoE=
4-
github.com/android-sms-gateway/client-go v1.5.0/go.mod h1:DQsReciU1xcaVW3T5Z2bqslNdsAwCFCtghawmA6g6L4=
3+
github.com/android-sms-gateway/client-go v1.5.5 h1:38ykCT1g+w3dW7ZNDeX1qyfZuvXI5h19MP/WFg4Rodw=
4+
github.com/android-sms-gateway/client-go v1.5.5/go.mod h1:DQsReciU1xcaVW3T5Z2bqslNdsAwCFCtghawmA6g6L4=
55
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
66
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
77
github.com/appleboy/com v0.2.1 h1:dHAHauX3eYDuheAahI83HIGFxpi0SEb2ZAu9EZ9hbUM=

internal/api/converters.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package api
2+
3+
import (
4+
"github.com/android-sms-gateway/ca/internal/csr"
5+
"github.com/android-sms-gateway/client-go/ca"
6+
)
7+
8+
func csrStatusToResponse(status csr.CSRStatus) ca.PostCSRResponse {
9+
return ca.PostCSRResponse{
10+
RequestID: status.ID(),
11+
Type: status.Type(),
12+
Status: status.Status(),
13+
Message: status.Status().Description(),
14+
Certificate: status.Certificate(),
15+
}
16+
}

internal/api/csr.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,14 @@ func (c *csrHandler) submit(ctx *fiber.Ctx) error {
3434
return err
3535
}
3636

37-
res, err := c.csrSvc.Create(ctx.Context(), csr.NewCSR(req.Content, req.Metadata))
37+
res, err := c.csrSvc.Create(ctx.Context(), csr.NewCSR(req.Type, req.Content, req.Metadata))
3838
if err != nil {
3939
return err
4040
}
4141

4242
return ctx.
4343
Status(fiber.StatusAccepted).
44-
JSON(ca.PostCSRResponse{
45-
RequestID: res.ID(),
46-
Status: res.Status(),
47-
Message: res.Status().Description(),
48-
Certificate: res.Certificate(),
49-
})
44+
JSON(csrStatusToResponse(res))
5045
}
5146

5247
// @Summary Get CSR Status
@@ -69,17 +64,10 @@ func (c *csrHandler) status(ctx *fiber.Ctx) error {
6964
return err
7065
}
7166

72-
return ctx.JSON(ca.GetCSRStatusResponse{
73-
RequestID: res.ID(),
74-
Status: res.Status(),
75-
Message: res.Status().Description(),
76-
Certificate: res.Certificate(),
77-
})
67+
return ctx.JSON(csrStatusToResponse(res))
7868
}
7969

8070
func (c *csrHandler) Register(router fiber.Router) {
81-
// router.Use(limiter.New(1, time.Minute))
82-
8371
router.Use(c.handleError)
8472

8573
router.Post("", c.submit)

internal/csr/const.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

internal/csr/domain.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,27 @@ import (
77
)
88

99
type CSR struct {
10+
csrType ca.CSRType
1011
content string
1112
metadata map[string]string
1213
}
1314

14-
func NewCSR(content string, metadata map[string]string) CSR {
15+
func NewCSR(csrType ca.CSRType, content string, metadata map[string]string) CSR {
16+
if csrType == "" {
17+
csrType = ca.CSRTypeWebhook
18+
}
19+
1520
return CSR{
21+
csrType: csrType,
1622
content: content,
1723
metadata: metadata,
1824
}
1925
}
2026

27+
func (c CSR) Type() ca.CSRType {
28+
return c.csrType
29+
}
30+
2131
func (c CSR) Content() string {
2232
return c.content
2333
}
@@ -34,6 +44,7 @@ func (c CSR) toMap() map[string]string {
3444
}
3545

3646
return map[string]string{
47+
"type": string(c.csrType),
3748
"content": c.content,
3849
"metadata": metadata,
3950
}
@@ -47,9 +58,10 @@ type CSRStatus struct {
4758
reason string
4859
}
4960

50-
func NewCSRStatus(id string, content string, metadata map[string]string, status ca.CSRStatus, certificate string, reason string) CSRStatus {
61+
func NewCSRStatus(id string, csrType ca.CSRType, content string, metadata map[string]string, status ca.CSRStatus, certificate string, reason string) CSRStatus {
5162
return CSRStatus{
5263
CSR: CSR{
64+
csrType: csrType,
5365
content: content,
5466
metadata: metadata,
5567
},

0 commit comments

Comments
 (0)