forked from letsencrypt/boulder
/
authz.go
73 lines (66 loc) · 1.44 KB
/
authz.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package sa
import (
"fmt"
"strings"
"time"
"gopkg.in/go-gorp/gorp.v2"
"github.com/letsencrypt/boulder/core"
)
var authorizationTables = []string{
"authz",
"pendingAuthorizations",
}
const getAuthorizationIDsMax = 1000
func getAuthorizationIDsByDomain(db *gorp.DbMap, tableName string, ident string, now time.Time) ([]string, error) {
var allIDs []string
_, err := db.Select(
&allIDs,
fmt.Sprintf(
`SELECT id FROM %s
WHERE identifier = :ident AND
status != :invalid AND
status != :revoked AND
expires > :now
LIMIT :limit`,
tableName,
),
map[string]interface{}{
"ident": ident,
"invalid": string(core.StatusInvalid),
"revoked": string(core.StatusRevoked),
"now": now,
"limit": getAuthorizationIDsMax,
},
)
if err != nil {
return nil, err
}
return allIDs, nil
}
func revokeAuthorizations(db *gorp.DbMap, tableName string, authIDs []string) (int64, error) {
stmtArgs := []interface{}{string(core.StatusRevoked)}
qmarks := []string{}
for _, id := range authIDs {
stmtArgs = append(stmtArgs, id)
qmarks = append(qmarks, "?")
}
idStmt := fmt.Sprintf("(%s)", strings.Join(qmarks, ", "))
result, err := db.Exec(
fmt.Sprintf(
`UPDATE %s
SET status = ?
WHERE id IN %s`,
tableName,
idStmt,
),
stmtArgs...,
)
if err != nil {
return 0, err
}
batchSize, err := result.RowsAffected()
if err != nil {
return 0, err
}
return batchSize, nil
}