diff --git a/lib/agent/check.d.ts b/lib/agent/check.d.ts index 93cd248..fc47b34 100644 --- a/lib/agent/check.d.ts +++ b/lib/agent/check.d.ts @@ -27,19 +27,26 @@ interface Check { type ListResult = Record; -interface RegisterOptions extends CommonOptions { +export interface CheckOptions { name: string; id?: string; serviceid?: string; http?: string; + body?: string; + header?: Record; + disableredirects?: boolean; + h2ping?: string; + h2pingusetls?: boolean; tlsskipverify?: boolean; tcp?: string; + udp?: string; args?: string[]; script?: string; dockercontainerid?: string; grpc?: string; grpcusetls?: boolean; shell?: string; + timeout: string; interval?: string; ttl?: string; aliasnode?: string; @@ -47,10 +54,13 @@ interface RegisterOptions extends CommonOptions { notes?: string; status?: string; deregistercriticalserviceafter?: string; + failuresbeforewarning?: number; successbeforepassing?: number; failuresbeforecritical?: number; } +interface RegisterOptions extends CheckOptions, CommonOptions {} + type RegisterResult = any; interface DeregisterOptions extends CommonOptions { diff --git a/lib/agent/service.d.ts b/lib/agent/service.d.ts index 44abc04..5c83146 100644 --- a/lib/agent/service.d.ts +++ b/lib/agent/service.d.ts @@ -1,4 +1,5 @@ import { CommonOptions, Consul } from "../consul"; +import { CheckOptions } from "./check"; interface ListOptions extends CommonOptions { filter?: string; @@ -6,20 +7,6 @@ interface ListOptions extends CommonOptions { type ListResult = Record; -interface RegisterCheck { - http?: string; - tcp?: string; - script?: string; - dockercontainerid?: string; - shell?: string; - interval?: string; - timeout?: string; - ttl?: string; - notes?: string; - status?: string; - deregistercriticalserviceafter?: string; -} - interface RegisterConnect { native?: boolean; proxy?: any; @@ -38,8 +25,8 @@ interface RegisterOptions extends CommonOptions { kind?: string; proxy?: any; connect?: RegisterConnect; - check?: RegisterCheck; - checks?: RegisterCheck[]; + check?: CheckOptions; + checks?: CheckOptions[]; } type RegisterResult = any; diff --git a/lib/utils.js b/lib/utils.js index ad35843..54fb3ed 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -302,18 +302,36 @@ function _createServiceCheck(src) { const dst = {}; if ( - (src.grpc || src.http || src.tcp || src.args || src.script) && + (src.grpc || + src.h2ping || + src.http || + src.tcp || + src.udp || + src.args || + src.script) && src.interval ) { if (src.grpc) { dst.GRPC = src.grpc; if (src.hasOwnProperty("grpcusetls")) dst.GRPCUseTLS = src.grpcusetls; + } else if (src.h2ping) { + dst.H2Ping = src.h2ping; + if (src.hasOwnProperty("h2pingusetls")) { + dst.H2PingUseTLS = src.h2pingusetls; + } } else if (src.http) { dst.HTTP = src.http; - if (src.hasOwnProperty("tlsskipverify")) - dst.TLSSkipVerify = src.tlsskipverify; + if (src.hasOwnProperty("body")) dst.Body = src.body; + if (src.hasOwnProperty("disableredirects")) { + dst.DisableRedirects = src.disableredirects; + } + if (src.hasOwnProperty("header")) dst.Header = src.header; + if (src.hasOwnProperty("method")) dst.Method = src.method; } else if (src.tcp) { dst.TCP = src.tcp; + if (src.hasOwnProperty("tcpusetls")) dst.TCPUseTLS = src.tcpusetls; + } else if (src.udp) { + dst.UDP = src.udp; } else { if (src.args) { dst.Args = src.args; @@ -325,7 +343,16 @@ function _createServiceCheck(src) { if (src.hasOwnProperty("shell")) dst.Shell = src.shell; } dst.Interval = src.interval; + if (src.hasOwnProperty("outputmaxsize")) { + dst.OutputMaxSize = src.outputmaxsize; + } if (src.hasOwnProperty("timeout")) dst.Timeout = src.timeout; + if (src.hasOwnProperty("tlsservername")) { + dst.TLSServerName = src.tlsservername; + } + if (src.hasOwnProperty("tlsskipverify")) { + dst.TLSSkipVerify = src.tlsskipverify; + } } else if (src.ttl) { dst.TTL = src.ttl; } else if (src.aliasnode || src.aliasservice) { @@ -333,7 +360,7 @@ function _createServiceCheck(src) { if (src.hasOwnProperty("aliasservice")) dst.AliasService = src.aliasservice; } else { throw new Error( - "args/grpc/http/tcp and interval, ttl, or aliasnode/aliasservice" + "args/grpc/h2ping/http/tcp/udp and interval, ttl, or aliasnode/aliasservice" ); } if (src.hasOwnProperty("notes")) dst.Notes = src.notes; @@ -341,6 +368,9 @@ function _createServiceCheck(src) { if (src.hasOwnProperty("deregistercriticalserviceafter")) { dst.DeregisterCriticalServiceAfter = src.deregistercriticalserviceafter; } + if (src.hasOwnProperty("failuresbeforewarning")) { + dst.FailuresBeforeWarning = src.failuresbeforewarning; + } if (src.hasOwnProperty("failuresbeforecritical")) { dst.FailuresBeforeCritical = src.failuresbeforecritical; } diff --git a/package.json b/package.json index 9bafc6e..dfee797 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "consul", - "version": "2.0.0-next.2", + "version": "2.0.0-next.3", "description": "Consul client", "main": "./lib", "types": "./lib/index.d.ts", diff --git a/test/agent.js b/test/agent.js index 99dff77..5b8d670 100644 --- a/test/agent.js +++ b/test/agent.js @@ -113,7 +113,7 @@ describe("Agent", function () { } catch (err) { should(err).property( "message", - "consul: agent.check.register: args/grpc/http/tcp and interval, " + + "consul: agent.check.register: args/grpc/h2ping/http/tcp/udp and interval, " + "ttl, or aliasnode/aliasservice" ); } @@ -300,7 +300,7 @@ describe("Agent", function () { } catch (err) { should(err).property( "message", - "consul: agent.service.register: args/grpc/http/tcp and interval, " + + "consul: agent.service.register: args/grpc/h2ping/http/tcp/udp and interval, " + "ttl, or aliasnode/aliasservice" ); } diff --git a/test/utils.js b/test/utils.js index 381c51c..7afa6ba 100644 --- a/test/utils.js +++ b/test/utils.js @@ -350,8 +350,9 @@ describe("utils", function () { interval: "60s", notes: "Just a note.", status: "passing", - failuresbeforecritical: 1, - successBeforePassing: 2, + failuresbeforewarning: 1, + failuresbeforecritical: 2, + successBeforePassing: 3, }) ).eql({ ID: "id", @@ -362,8 +363,9 @@ describe("utils", function () { Interval: "60s", Notes: "Just a note.", Status: "passing", - FailuresBeforeCritical: 1, - SuccessBeforePassing: 2, + FailuresBeforeWarning: 1, + FailuresBeforeCritical: 2, + SuccessBeforePassing: 3, }); should( @@ -372,6 +374,7 @@ describe("utils", function () { name: "name", service_id: "service", tcp: "localhost:22", + tcpusetls: true, interval: "10s", notes: "SSH TCP on port 22", status: "passing", @@ -382,6 +385,7 @@ describe("utils", function () { Name: "name", ServiceID: "service", TCP: "localhost:22", + TCPUseTLS: true, Interval: "10s", Notes: "SSH TCP on port 22", Status: "passing", @@ -422,10 +426,56 @@ describe("utils", function () { utils.createServiceCheck({ grpc: "localhost:50051", interval: "5s", + tlsservername: "server", + tlsskipverify: true, + outputmaxsize: 4096, }) ).eql({ GRPC: "localhost:50051", Interval: "5s", + TLSSkipVerify: true, + TLSServerName: "server", + OutputMaxSize: 4096, + }); + + should( + utils.createServiceCheck({ + http: "https://example.com/test", + body: "{}", + disableredirects: true, + header: { authorization: ["one"] }, + method: "POST", + interval: "5s", + }) + ).eql({ + HTTP: "https://example.com/test", + Body: "{}", + DisableRedirects: true, + Header: { authorization: ["one"] }, + Method: "POST", + Interval: "5s", + }); + + should( + utils.createServiceCheck({ + h2ping: "https://example.com/test", + interval: "5s", + }) + ).eql({ + H2Ping: "https://example.com/test", + Interval: "5s", + }); + + should( + utils.createServiceCheck({ + h2ping: "http://example.com/test", + h2pingusetls: false, + interval: "5s", + }) + ).eql({ + H2Ping: "http://example.com/test", + Interval: "5s", + H2PingUseTLS: false, }); should( @@ -440,6 +490,38 @@ describe("utils", function () { Interval: "10s", }); + should( + utils.createServiceCheck({ + udp: "localhost:50051", + interval: "10s", + }) + ).eql({ + UDP: "localhost:50051", + Interval: "10s", + }); + + should( + utils.createServiceCheck({ + tcp: "localhost:50051", + interval: "10s", + }) + ).eql({ + TCP: "localhost:50051", + Interval: "10s", + }); + + should( + utils.createServiceCheck({ + tcp: "localhost:50051", + interval: "10s", + tcpusetls: true, + }) + ).eql({ + TCP: "localhost:50051", + Interval: "10s", + TCPUseTLS: true, + }); + should( utils.createServiceCheck({ ttl: "15s", @@ -472,7 +554,7 @@ describe("utils", function () { should(() => { utils.createCheck(); }).throw( - "args/grpc/http/tcp and interval, ttl, or aliasnode/aliasservice" + "args/grpc/h2ping/http/tcp/udp and interval, ttl, or aliasnode/aliasservice" ); } );