summaryrefslogtreecommitdiff
path: root/README.md
blob: 5614f2cd4e929a7d51da45f7298ae5ab8251fa5a (plain) (blame)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# PowerDNSex

A client to [PowerDNS 4 API](https://doc.powerdns.com/md/httpapi/README/), with all CRUD operations to manage zones and records.

[![Build Status](https://travis-ci.org/digaoddc/power_dnsex.svg?branch=travis)](https://travis-ci.org/digaoddc/power_dnsex)

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed as:

  1. Add `powerdnsex` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [{:powerdnsex, "~> 0.1.0"}]
end
```

  2. Ensure `powerdnsex` is started before your application:

```elixir
def application do
  [applications: [:powerdnsex]]
end
```

## Configuration
Insert this in your configuration files. Eg:  `config.exs`

```elixir
config :powerdnsex, url: "localhost:8081",
                    token: "sometoken"
```

You can also use ENV vars to configure PowerDNSex.
```elixir
config :powerdnsex, url: {:system, "POWERDNS_URL"},
                    token: {:system, "POWERDNS_TOKEN"}
```
Make sure you set those environment variables.

## Example usage

### Zone Management

```elixir
# CREATE ZONE:
zone_model = %PowerDNSex.Models.Zone{
  id: "example.com.",
  kind: "Master",
  name: "example.com.",
  serial: 1,
}
{:ok, zone} = PowerDNSex.create_zone(zone_model)

# SHOW ZONE:
{:ok, zone} = PowerDNSex.show_zone("example.com")

# SHOW ZONE without RRSets:
{:ok, zone} = PowerDNSex.get_zone("example.com")

# DELETE ZONE:
res = PowerDNSex.delete_zone("example.com")
```


### Record management

```elixir
# CREATE RECORD:
{:ok, zone} = PowerDNSex.show_zone("example.com")
record = %{
  name: "test.example.com.",
  type: "A",
  ttl: 60,
  records: [
    %{
      content: "192.168.11.67",
      disabled: false,
    }
  ]
}
res = PowerDNSex.create_record(zone, record)

# SHOW RECORD:
record = %{
  name: "test.example.com.",
  type: "A",
}
rrset = PowerDNSex.show_record("example.com", record)

# UPDATE RECORD:
{:ok, zone} = PowerDNSex.show_zone("example.com")
record = %{
  name: "test.example.com.",
  type: "A",
  ttl: 60,
  records: [
    %{
      content: "192.168.11.100",
      disabled: false,
    }
  ]
}
res = PowerDNSex.update_record(zone, record)

# DELETE RECORD:
{:ok, zone} = PowerDNSex.show_zone("example.com")
record = %{
  name: "test.example.com.",
  type: "A",
}
rrset = PowerDNSex.show_record("example.com", record)
res = PowerDNSex.delete_record(zone, rrset)
```

## Development

### Setup application
```bash
$ script/setup
```

### Run local console (IEX)
```bash
$ script/run
```

### Run tests
```bash
$ script/test
```

#### Run tests to a specific File
```bash
$ script/test test/lib/powerdnsex/powerdnsex_test.exs
```

### Reset environment (clean + setup)
### YOU WILL LOSE EVERYTHING

Good for then you change the elixir version and need to delete everything and start again

```bash
$ script/reset
```