Netflix / denominator

Portably control DNS clouds using java or bash
Apache License 2.0
580 stars 110 forks source link

example http daemon #237

Closed codefromthecrypt closed 9 years ago

codefromthecrypt commented 11 years ago

DenominatorD Example

DenominatorD is an example HTTP server that proxies a connection to your DNS provider. Technically, it is a MockWebServer. Once built, denominatord is a really executable jar, weighing in at 1.25MB, and starting up in <200ms on a modern laptop.

Building

To build the daemon, execute gradle clean build. The binary will end up at ./build/denominatord. If you don't have gradle, install it.

Running

The syntax is simple. First arg is the name of the provider. For example, clouddns, dynect, mock, route53, or ultradns. The remaining args are any credentials to that provider.

Ex. If you have no account, you can use mock.

$ build/denominatord mock
     16 - proxying MockProvider{name=mock,url=mem:mock}
    136 - MockWebServer[8080] starting to accept connections

Ex. To connect to a real cloud, you'll specify your credentials. You'll notice status messages for each outbound request.

$ build/denominatord route53 accessKey secretKey
     14 - proxying Route53Provider{name=route53,url=https://route53.amazonaws.com}
    181 - MockWebServer[8080] starting to accept connections
   2395 - [Route53#listHostedZones] ---> GET https://route53.amazonaws.com/2012-12-12/hostedzone HTTP/1.1
   3155 - [Route53#listHostedZones] <--- HTTP/1.1 200 OK (759ms)
   3193 - MockWebServer[8080] received request: GET /zones HTTP/1.1 and responded: HTTP/1.1 200 OK

By default, denominatord listens on port 8080. Export DENOMINATORD_PORT to use a different port.

API

The api is read-only, and based on OpenStack Designate V2.

Output is always json, and there's really only a few error cases.

Here are the resources exposed.

HealthCheck

GET /healthcheck

Returns 200 when the dns provider is healthy, 503 if not.

Ex. you might want to put a guard in a shell script to fail when health is bad.

$ curl -f http://localhost:8080/healthcheck

Zones

GET /zones

Returns a possibly empty array of your zones.

Ex. for clouds like ultradns, you'll only see the zone name.

$ curl http://localhost:8080/zones
[
  {
    "name": "denominator.io."
  }
]

Ex. for clouds like route53, zones are not unique by name, so you'll see an id.

$ curl http://localhost:8080/zones
[
  {
    "name": "myzone.com.",
    "id": "ABCDEFGHIJK"
  }
]

Record Sets

All record set commands require the zone specified as a path parameter. This is either the id of the zone, or when there is no id, it is the name.

/zones/{zoneIdOrName}/recordsets

Pay attention to trailing dots!

Ex. for clouds like ultradns, the zone parameter is the zone name.

/zones/denominator.io./recordsets

Where for clouds like route53, you'd use the id.

/zones/Z1V14BIB35Q8HU/recordsets

GET /zones/{zoneIdOrName}/recordsets?name={name}&type={type}&qualifier={qualifier}

Returns a possibly empty array of your record sets.

Supported Query params:

Ex. for route53, where the zone has an id

$ curl http://localhost:8080/zones/Z1V14BIB35Q8HU/recordsets
[
  {
    "name": "denominator.io.",
    "type": "NS",
    "ttl": 172800,
    "records": [
      {
        "nsdname": "ns-1707.awsdns-21.co.uk."
      },
      {
        "nsdname": "ns-1359.awsdns-41.org."
      },
      {
        "nsdname": "ns-981.awsdns-58.net."
      },
      {
        "nsdname": "ns-86.awsdns-10.com."
      }
    ]
  },
--snip--

Ex. refining results by name, type, and qualifier.

$ curl 'http://localhost:8080/zones/denominator.io./recordsets?name=www2.geo.denominator.io.&type=A&qualifier=alazona'
[
  {
    "name": "www2.geo.denominator.io.",
    "type": "A",
    "qualifier": "alazona",
    "ttl": 300,
    "records": [
      {
        "address": "192.0.2.1"
      }
    ],
    "geo": {
      "regions": {
        "United States (US)": [
          "Alaska",
          "Arizona"
        ]
      }
    }
  }
]

PUT /zones/{zoneIdOrName}/recordsets

Adds or replaces a record set and returns 204.

Ex. to add or replace an MX record.

$ curl -X PUT http://localhost:8080/zones/Z3I0BTR7N27QRM/recordsets -d'{
  "name": "test.myzone.com.",
  "type": "TXT",
  "ttl": 1800,
  "records": [{
    "txtdata": "made in norway"
  }, {
    "txtdata": "made in sweden"
  }]
}'

DELETE /zones/{zoneIdOrName}/recordsets?name={name}&type={type}&qualifier={qualifier}

Deletes a record set if present and returns 204.

Supported Query params:

Ex. to delete a normal MX record

$ curl -X DELETE 'http://localhost:8080/zones/Z3I0BTR7N27QRM/recordsets?name=test.myzone.com.&type=TXT'
codefromthecrypt commented 9 years ago

rebased to latest versions of things. next step, port to rxnetty. @NiteshKant which version should we target? (note this is just an example, so drift is ok)

codefromthecrypt commented 9 years ago

actually, looks like rxnetty 0.5 is quite a ways off. Also, there's quite a bit of handiness in undertow I'm not sure how to translate, yet. I'm inclined to stick with undertow for now, and leave a future port as a fun exercise for later.

codefromthecrypt commented 9 years ago

actually I have a better idea. since denominator isn't yet async anyway, I'll strip this down to a mock web server. When we do real async, we can make a new proxy example to show it off instead of mixing.

codefromthecrypt commented 9 years ago

Updated to use MockWebServer. all good now, and very small (1.2MB).

cloudbees-pull-request-builder commented 9 years ago

NetflixOSS » denominator » denominator-pull-requests #80 SUCCESS This pull request looks good

cloudbees-pull-request-builder commented 9 years ago

NetflixOSS » denominator » denominator-pull-requests #81 SUCCESS This pull request looks good