Skip to content

Commit

Permalink
Release v0.8.0 (#12)
Browse files Browse the repository at this point in the history
- feat(nameserver): added GET_req, GET_res, POST, DELETE
- feat(group): separate GET_req, GET_res from GET
- feat(group,user): added DELETE
- feat(shared): added int8, uint8, int16, uint16, int32
  • Loading branch information
msimerson committed Mar 6, 2024
1 parent 4dbb61e commit 553e58c
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .release
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

### Unreleased

### [0.8.0] - 2024-03-06

- feat(nameserver): added GET_req, GET_res, POST, DELETE
- feat(group,permission,session,user): separate GET_req, GET_res
- feat(group,user): added DELETE
- feat(shared): added int8, uint8, int16, uint16, int32

### [0.7.4] - 2024-03-04

Expand Down Expand Up @@ -50,3 +56,4 @@
[0.7.2]: https://github.com/NicTool/validate/releases/tag/0.7.2
[0.7.3]: https://github.com/NicTool/validate/releases/tag/0.7.3
[0.7.4]: https://github.com/NicTool/validate/releases/tag/0.7.4
[0.8.0]: https://github.com/NicTool/validate/releases/tag/0.8.0
13 changes: 12 additions & 1 deletion lib/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ exports.v2 = Joi.object({
permission: permission.v3,
})

exports.GET = Joi.object({
exports.GET_req = Joi.object({
id: exports.pid,
name: exports.name,
deleted: Joi.boolean(),
})

exports.GET_res = Joi.object({
group: Joi.object({
id: exports.pid,
name: exports.name,
Expand All @@ -48,3 +54,8 @@ exports.POST = Joi.object({
parent_gid: exports.pid,
deleted: Joi.boolean(),
})

exports.DELETE = Joi.object({
id: exports.id,
deleted: Joi.boolean(),
})
80 changes: 46 additions & 34 deletions lib/nameserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,60 @@ const Joi = require('joi')

const shared = require('./shared')

exports.v3 = Joi.object({
id: Joi.number().integer().greater(-1),

gid: Joi.number().integer().greater(0).required(),

name: Joi.string()
.min(2)
.max(127)
.domain({ allowFullyQualified: true, tlds: false })
.pattern(/\.$/)
.required(),
exports.id = shared.uint16.min(0)

exports.name = Joi.string()
.min(2)
.max(127)
.domain({ allowFullyQualified: true, tlds: false })
.pattern(/\.$/)

exports.type = Joi.string().valid(
'bind',
'djbdns',
'knot',
'NSD',
'maradns',
'powerdns',
'dynect',
)

exports.remote_login = Joi.string().empty('').max(127)

exports.v3 = Joi.object({
id: exports.id,
gid: shared.uint32.required(),
name: exports.name.required(),
ttl: shared.ttl.required(),

description: Joi.string().empty('').max(255),

address: Joi.string()
.ip({ version: ['ipv4'], cidr: 'forbidden' })
.min(7)
.max(15)
.required(),

address6: Joi.string()
.ip({ version: ['ipv6'], cidr: 'forbidden' })
.min(2)
.max(39),

remote_login: Joi.string().max(127),

address: shared.ipv4.required(),
address6: shared.ipv6,
remote_login: exports.remote_login,
logdir: Joi.string().empty('').max(255),

datadir: Joi.string().empty('').min(2).max(255),
export: Joi.object({
interval: shared.uint16,
serials: Joi.boolean(),
status: Joi.string().empty('').max(255),
type: exports.type.required(),
}),
deleted: Joi.boolean(),
})

export_interval: Joi.number().integer().greater(-1).max(65535),

export_serials: Joi.boolean(),
exports.GET_req = Joi.object({
id: exports.id,
name: exports.name,
deleted: Joi.boolean(),
})

export_status: Joi.string().max(255),
exports.GET_res = Joi.object({
nameserver: exports.v3,
meta: shared.meta,
})

export_type: Joi.string()
.valid('bind', 'djbdns', 'knot', 'nsd', 'maradns', 'powerdns', 'dynect')
.required(),
exports.POST = exports.v3

exports.DELETE = Joi.object({
id: exports.id,
deleted: Joi.boolean(),
})
14 changes: 7 additions & 7 deletions lib/nameserver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,29 @@ describe('nameserver', function () {
}
})

describe('export_type', function () {
describe('export.type', function () {
it(`rejects missing`, () => {
const testCase = JSON.parse(JSON.stringify(testNS))
delete testCase.export_type
delete testCase.export.type

const { error, value } = schema.validate(testCase)

assert.strictEqual(error.message, '"export_type" is required')
assert.strictEqual(error.message, '"export.type" is required')
assert.deepEqual(value, testCase)
})

for (const n of [
'bind',
'djbdns',
'knot',
'nsd',
'NSD',
'maradns',
'powerdns',
'dynect',
]) {
it(`accepts valid: ${n}`, () => {
const testCase = JSON.parse(JSON.stringify(testNS))
testCase.export_type = n
testCase.export.type = n

const { error, value } = schema.validate(testCase)

Expand All @@ -109,13 +109,13 @@ describe('nameserver', function () {
]) {
it(`rejects invalid: ${n}`, () => {
const testCase = JSON.parse(JSON.stringify(testNS))
testCase.export_type = n
testCase.export.type = n

const { error, value } = schema.validate(testCase)

assert.strictEqual(
error.message,
'"export_type" must be one of [bind, djbdns, knot, nsd, maradns, powerdns, dynect]',
'"export.type" must be one of [bind, djbdns, knot, NSD, maradns, powerdns, dynect]',
)
assert.deepEqual(value, testCase)
})
Expand Down
7 changes: 6 additions & 1 deletion lib/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ exports.v3 = Joi.object({

exports.POST = exports.v3

exports.GET = Joi.object({
exports.GET_req = Joi.object({
id: exports.id,
deleted: Joi.boolean(),
})

exports.GET_res = Joi.object({
permission: exports.v3,
meta: shared.meta,
})
Expand Down
2 changes: 1 addition & 1 deletion lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports.POST = Joi.object({
password: user.password.required(),
})

exports.GET = Joi.object({
exports.GET_res = Joi.object({
user: user.v3,
group: group.v3,
session: Joi.object({
Expand Down
22 changes: 20 additions & 2 deletions lib/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,28 @@ exports.meta = Joi.object({
}).unknown(),
}).unknown()

exports.int32 = Joi.number().integer().min(0).max(2147483647)
exports.int8 = Joi.number().integer().min(-128).max(127)

exports.uint8 = Joi.number().integer().min(0).max(255)

exports.int16 = Joi.number().integer().min(-32768).max(32767)

exports.uint16 = Joi.number().integer().min(0).max(65535)

exports.int32 = Joi.number().integer().min(-2147483648).max(2147483647)

exports.uint32 = Joi.number().integer().min(0).max(4294967295)

exports.ipv4 = Joi.string()
.ip({ version: ['ipv4'], cidr: 'forbidden' })
.min(7)
.max(15)

exports.ipv6 = Joi.string()
.ip({ version: ['ipv6'], cidr: 'forbidden' })
.min(2)
.max(39)

// Clarifications to the DNS specification: http://tools.ietf.org/html/rfc2181
// valid TTL is unsigned number from 0 to 2147483647
exports.ttl = exports.int32
exports.ttl = exports.int32.min(0)
15 changes: 12 additions & 3 deletions lib/test/nameserver.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
{
"id": 3,
"gid": 1,
"name": "ns.tld.",
"gid": 4096,
"name": "a.ns.example.com.",
"address": "1.2.3.4",
"export_type": "djbdns",
"address6": "2001:DB8::1",
"remote_login": "nsd",
"logdir": "/foo",
"datadir": "/bar",
"export": {
"type": "NSD",
"interval": 0,
"serials": true,
"status": "last run:03-05 15:25<br>last cp :09-20 12:59"
},
"ttl": 3600,
"deleted": false
}
11 changes: 10 additions & 1 deletion lib/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ exports.v3 = Joi.object({
deleted: Joi.boolean(),
})

exports.GET = Joi.object({
exports.GET_req = Joi.object({
id: exports.id,
deleted: Joi.boolean(),
})

exports.GET_res = Joi.object({
user: exports.v3,
group: Joi.object({
id: group.id,
Expand All @@ -55,6 +60,10 @@ exports.POST = Joi.object({
is_admin: Joi.boolean(),
})

exports.DELETE = Joi.object({
id: exports.id,
})

exports.v2 = Joi.object({
nt_user_id: exports.id,
nt_group_id: group.id,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nictool/validate",
"version": "0.7.4",
"version": "0.8.0",
"description": "NicTool Object Validation",
"main": "index.js",
"directories": {
Expand Down

0 comments on commit 553e58c

Please sign in to comment.