From 9ed519ec69f179ae92ad11e07d04af3284532b34 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Thu, 4 Jun 2020 12:41:04 -0500 Subject: [PATCH] chores & lints --- .editorconfig | 9 ++++ .golangci.yml | 5 ++ .pre-commit-config.yaml | 115 ++++++++++++++++++++++++++++++++++++++++ .prettierignore | 1 + .prettierrc | 4 ++ README.md | 41 ++++++++------ go.sum | 17 ++++++ handler.go | 3 +- justfile | 31 +++++++++++ ldap.go | 25 +++++---- metrics.go | 2 - setup.go | 17 +++--- vendor/modules.txt | 7 +-- 13 files changed, 234 insertions(+), 43 deletions(-) create mode 100644 .editorconfig create mode 100644 .golangci.yml create mode 100644 .pre-commit-config.yaml create mode 100644 .prettierignore create mode 100644 .prettierrc create mode 100644 justfile diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0385e34 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..08fe5a9 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,5 @@ +linters: + enable-all: true +output: + # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" + format: code-climate diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..83aa16d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,115 @@ +repos: + # ========================================================================== + # Golang Pre-Commit Hooks | https://github.com/tekwizely/pre-commit-golang + # + # Visit the project home page to learn more about the available Hooks, + # including useful arguments you might want to pass into them. + # + # File-Based Hooks: + # Run against matching staged files individually. + # + # Module-Based Hooks: + # Run against module root folders containing matching staged files. + # + # Package-Based Hooks: + # Run against folders containing one or more staged files. + # + # Repo-Based Hooks: + # Run against the entire repo. + # The hooks only run once (if any matching files are staged), + # and are NOT provided the list of staged files, + # + # Hook Suffixes + # Hooks have suffixes in their name that indicate their targets: + # + # +-----------+--------------+ + # | Suffix | Target | + # |-----------+--------------+ + # | | Files | + # | -mod | Module | + # | -pkg | Package | + # | -repo-mod | All Modules | + # | -repo-pkg | All Packages | + # +-----------+--------------+ + # + # ! Multiple Hook Invocations + # ! Due to OS command-line-length limits, Pre-Commit can invoke a hook + # ! multiple times if a large number of files are staged. + # ! For file and repo-based hooks, this isn't an issue, but for module + # ! and package-based hooks, there is a potential for the hook to run + # ! against the same module or package multiple times, duplicating any + # ! errors or warnings. + # + # Useful Hook Parameters: + # - id: hook-id + # args: [arg1, arg2, ..., '--'] # Pass options ('--' is optional) + # always_run: true # Run even if no matching files staged + # alias: hook-alias # Create an alias + # + # Passing Options To Hooks: + # If your options contain a reference to an existing file, then you will + # need to use a trailing '--' argument to separate the hook options from + # the modified-file list that Pre-Commit passes into the hook. + # NOTE: For repo-based hooks, '--' is not needed. + # + # Always Run: + # By default, hooks ONLY run when matching file types are staged. + # When configured to "always_run", a hook is executed as if EVERY matching + # file were staged. + # + # Aliases: + # Consider adding aliases to longer-named hooks for easier CLI usage. + # ========================================================================== + - repo: https://github.com/tekwizely/pre-commit-golang + rev: master + hooks: + # + # Go Build + # + # - id: go-build-mod + # - id: go-build-pkg + # - id: go-build-repo-mod + # - id: go-build-repo-pkg + # + # Go Test + # + - id: go-test-mod + # - id: go-test-pkg + # - id: go-test-repo-mod + # - id: go-test-repo-pkg + # + # Go Vet + # + # - id: go-vet + - id: go-vet-mod + # - id: go-vet-pkg + # - id: go-vet-repo-mod + # - id: go-vet-repo-pkg + # + # Formatters + # + # - id: go-fmt + # - id: go-imports # Replaces go-fmt + - id: go-returns # Replaces go-imports & go-fmt + # + # Style Checkers + # + - id: go-lint + - id: go-critic + # + # GolangCI-Lint + # - Fast Multi-Linter + # - Can be configured to replace MOST other hooks + # - Supports repo config file for configuration + # - https://github.com/golangci/golangci-lint + # + # - id: golangci-lint + - id: golangci-lint-mod + # - id: golangci-lint-pkg + # - id: golangci-lint-repo-mod + # - id: golangci-lint-repo-pkg + + - repo: https://github.com/prettier/prettier + rev: "master" + hooks: + - id: prettier diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..22d0d82 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +vendor diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..8ca7a36 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,4 @@ +{ + "semi": false, + "proseWrap": "always" +} diff --git a/README.md b/README.md index 93da7ef..337a896 100644 --- a/README.md +++ b/README.md @@ -2,23 +2,30 @@ ## Name -*ldap* - serves a zone from a ldap backend. +_ldap_ - serves a zone from a ldap backend. ## Description -The ldap plugin resolves A, AAAA y PTR RR from a ldap backend. To reduce load on the backend, you can enable cache by configuring `cacheTimeout=30m`. +The ldap plugin resolves A, AAAA y PTR RR from a ldap backend. To reduce load on +the backend, you can enable cache by configuring `cacheTimeout=30m`. ## Compilation -This package will always be compiled as part of CoreDNS and not in a standalone way. It will require you to use `go get` or as a dependency on [plugin.cfg](https://github.com/coredns/coredns/blob/master/plugin.cfg). +This package will always be compiled as part of CoreDNS and not in a standalone +way. It will require you to use `go get` or as a dependency on +[plugin.cfg](https://github.com/coredns/coredns/blob/master/plugin.cfg). -The [manual](https://coredns.io/manual/toc/#what-is-coredns) will have more information about how to configure and extend the server with external plugins. +The [manual](https://coredns.io/manual/toc/#what-is-coredns) will have more +information about how to configure and extend the server with external plugins. -A simple way to consume this plugin, is by adding the following on [plugin.cfg](https://github.com/coredns/coredns/blob/master/plugin.cfg), and recompile it as [detailed on coredns.io](https://coredns.io/2017/07/25/compile-time-enabling-or-disabling-plugins/#build-with-compile-time-configuration-file). +A simple way to consume this plugin, is by adding the following on +[plugin.cfg](https://github.com/coredns/coredns/blob/master/plugin.cfg), and +recompile it as +[detailed on coredns.io](https://coredns.io/2017/07/25/compile-time-enabling-or-disabling-plugins/#build-with-compile-time-configuration-file). -~~~ +``` ldap:github.com/xoe-labs/ldap -~~~ +``` After this you can compile coredns by: @@ -35,17 +42,19 @@ make ## Syntax -~~~ txt +```txt ldap -~~~ +``` ## Metrics -If monitoring is enabled (via the *prometheus* directive) the following metric is exported: +If monitoring is enabled (via the _prometheus_ directive) the following metric +is exported: -* `coredns_ldap_request_count_total{server}` - query count to the *ldap* plugin. +- `coredns_ldap_request_count_total{server}` - query count to the _ldap_ plugin. -The `server` label indicated which server handled the request, see the *metrics* plugin for details. +The `server` label indicated which server handled the request, see the _metrics_ +plugin for details. ## Ready @@ -53,15 +62,15 @@ This plugin reports readiness to the ready plugin. It will be immediately ready. ## Examples -In this configuration, we forward all queries to 9.9.9.9 and print "ldap" whenever we receive -a query. +In this configuration, we forward all queries to 9.9.9.9 and print "ldap" +whenever we receive a query. -~~~ corefile +```corefile . { forward . 9.9.9.9 ldap } -~~~ +``` ## Also See diff --git a/go.sum b/go.sum index d79d377..4061068 100644 --- a/go.sum +++ b/go.sum @@ -134,6 +134,7 @@ github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRx github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d h1:3PaI8p3seN09VjbTYC/QWlUZdZ1qS1zGjy7LH2Wt07I= github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -165,6 +166,7 @@ github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= +github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= @@ -199,6 +201,7 @@ github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uG github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4= github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI= github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/infobloxopen/go-trees v0.0.0-20190313150506-2af4e13f9062/go.mod h1:PcNJqIlcX/dj3DTG/+QQnRvSgTMG6CLpRMjWcv4+J6w= @@ -210,6 +213,7 @@ github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCV github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= @@ -253,9 +257,11 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk github.com/mitchellh/go-vnc v0.0.0-20150629162542-723ed9867aed/go.mod h1:3rdaFaCv4AyBgu5ALFM0+tSuHrBh6v692nyQe3ikrq0= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= @@ -335,6 +341,7 @@ github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTd github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -418,6 +425,7 @@ golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3ob golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -462,6 +470,7 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 h1:xQwXv67TxFo9nC1GJFyab5eq/5B590r6RlnL/G8Sz7w= golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -491,6 +500,7 @@ google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/ google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1 h1:QzqyMA1tlu6CgqCDUtU9V+ZKhLFT2dkJuANu5QaxI3I= google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= @@ -530,6 +540,7 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= +gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.44.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= @@ -554,15 +565,21 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +k8s.io/api v0.17.4 h1:HbwOhDapkguO8lTAE8OX3hdF2qp8GtpC9CW/MQATXXo= k8s.io/api v0.17.4/go.mod h1:5qxx6vjmwUVG2nHQTKGlLts8Tbok8PzHl4vHtVFuZCA= +k8s.io/apimachinery v0.17.4 h1:UzM+38cPUJnzqSQ+E1PY4YxMHIzQyCg29LOoGfo79Zw= k8s.io/apimachinery v0.17.4/go.mod h1:gxLnyZcGNdZTCLnq3fgzyg2A5BVCHTNDFrw8AmuJ+0g= +k8s.io/client-go v0.17.4 h1:VVdVbpTY70jiNHS1eiFkUt7ZIJX3txd29nDxxXH4en8= k8s.io/client-go v0.17.4/go.mod h1:ouF6o5pz3is8qU0/qYL2RnoxOPqgfuidYLowytyLJmc= k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= +k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8= k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E= +k8s.io/utils v0.0.0-20191114184206-e782cd3c129f h1:GiPwtSzdP43eI1hpPCbROQCCIgCuiMMNF8YUVLF3vJo= k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI= +sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= diff --git a/handler.go b/handler.go index 624bdd7..e20c481 100644 --- a/handler.go +++ b/handler.go @@ -9,7 +9,6 @@ import ( "github.com/miekg/dns" ) - // ServeDNS implements the plugin.Handler interface. func (l Ldap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { opt := plugin.Options{} @@ -80,4 +79,4 @@ func (l Ldap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i } // Name implements the Handler interface. -func (l Ldap) Name() string { return "ldap" } \ No newline at end of file +func (l Ldap) Name() string { return "ldap" } diff --git a/justfile b/justfile new file mode 100644 index 0000000..ec10d8a --- /dev/null +++ b/justfile @@ -0,0 +1,31 @@ +# use with https://github.com/casey/just + +# fixe auto-fixable lint issues in all files +fix: + ~/bin/pre-commit run go-returns # fixes all Go lint issues + ~/bin/pre-commit run prettier # fixes all Markdown (& other) lint issues + +# lint most common issues in all files +lint: + ~/bin/pre-commit run go-vet-mod || true # runs go vet + ~/bin/pre-commit run go-lint || true # runs golint + ~/bin/pre-commit run go-critic || true # runs gocritic + +# lint all issues in all files through meta linter +lint-all: + ~/bin/pre-commit run golangci-lint-mod || true # runs golangci-lint on the module level + +# commit skipping pre-commit hooks +commit m: + git commit --no-verify -m "{{m}}" + +# amend skipping pre-commit hooks +amend: + git commit --amend --no-verify + +# install / update code automation tools (prettier, pre-commit, goreturns) +setup: + npm i -g prettier + curl https://pre-commit.com/install-local.py | python3 - + ~/bin/pre-commit install --install-hooks + go get github.com/sqs/goreturns diff --git a/ldap.go b/ldap.go index b1c6ba6..f153ea6 100644 --- a/ldap.go +++ b/ldap.go @@ -10,15 +10,15 @@ package ldap import ( "context" + "crypto/tls" "errors" "fmt" - "net" - "io" - "os" + "strings" "github.com/coredns/coredns/plugin" - "github.com/coredns/coredns/plugin/metrics" + "github.com/coredns/coredns/plugin/etcd/msg" "github.com/coredns/coredns/plugin/pkg/fall" + "github.com/coredns/coredns/request" "github.com/miekg/dns" "gopkg.in/ldap.v3" @@ -26,12 +26,11 @@ import ( // Ldap is an ldap plugin to serve zone entries from a ldap backend. type Ldap struct { - Next plugin.Handler - Fall fall.F - Zones []string - Client *ldap.Client + Next plugin.Handler + Fall fall.F + Zones []string + Client *ldap.Client clientConfig - } // New returns an initialized Ldap with defaults. @@ -41,22 +40,22 @@ func New(zones []string) *Ldap { return k } - var ( errNoItems = errors.New("no items found") errNsNotExposed = errors.New("namespace is not exposed") errInvalidRequest = errors.New("invalid query name") ) +// InitClient initializes a Ldap client. func (l *Ldap) InitClient() (err error) { - l, err := Dial("tcp", fmt.Sprintf("%s:%d", "ldap.example.com", 389)) + l.Client, err = Dial("tcp", fmt.Sprintf("%s:%d", "ldap.example.com", 389)) if err != nil { log.Fatal(err) } - defer l.Close() + defer l.Client.Close() // Reconnect with TLS - err = l.StartTLS(&tls.Config{InsecureSkipVerify: true}) + err = l.Client.StartTLS(&tls.Config{InsecureSkipVerify: true}) if err != nil { log.Fatal(err) } diff --git a/metrics.go b/metrics.go index eedaa7e..04f6f8e 100644 --- a/metrics.go +++ b/metrics.go @@ -1,7 +1,6 @@ package ldap import ( - "github.com/coredns/coredns/plugin" "github.com/prometheus/client_golang/prometheus" @@ -14,4 +13,3 @@ var requestCount = prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "request_count_total", Help: "Counter of requests made.", }, []string{"server"}) - diff --git a/setup.go b/setup.go index 734cbe3..dae0bb5 100644 --- a/setup.go +++ b/setup.go @@ -1,19 +1,25 @@ package ldap import ( - "sync" "context" + "errors" + "fmt" + "strconv" + "strings" + "sync" + "time" + "github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin/metrics" "github.com/coredns/coredns/plugin/pkg/dnsutil" clog "github.com/coredns/coredns/plugin/pkg/log" + "github.com/coredns/coredns/plugin/pkg/parse" "github.com/coredns/coredns/plugin/pkg/upstream" "github.com/caddyserver/caddy" ) - const pluginName = "ldap" // Define log to be a logger with the plugin name in it. @@ -59,7 +65,6 @@ func setup(c *caddy.Controller) error { var once sync.Once - // RegisterLdapCache registers LdapCache start and stop functions with Caddy func (l *Ldap) RegisterLdapCache(c *caddy.Controller) { c.OnStartup(func() error { @@ -84,11 +89,10 @@ func (l *Ldap) RegisterLdapCache(c *caddy.Controller) { }) } - func ldapParse(c *caddy.Controller) (*Ldap, error) { var ( ldap *Ldap - err error + err error ) i := 0 @@ -106,7 +110,6 @@ func ldapParse(c *caddy.Controller) (*Ldap, error) { return ldap, nil } - // ParseStanza parses a ldap stanza func ParseStanza(c *caddy.Controller) (*Ldap, error) { @@ -283,4 +286,4 @@ func ParseStanza(c *caddy.Controller) (*Ldap, error) { } return ldap, nil -} \ No newline at end of file +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 200ff23..2903962 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -20,6 +20,7 @@ github.com/coredns/coredns/plugin/pkg/dnstest github.com/coredns/coredns/plugin/pkg/dnsutil github.com/coredns/coredns/plugin/pkg/doh github.com/coredns/coredns/plugin/pkg/edns +github.com/coredns/coredns/plugin/pkg/fall github.com/coredns/coredns/plugin/pkg/log github.com/coredns/coredns/plugin/pkg/nonwriter github.com/coredns/coredns/plugin/pkg/parse @@ -29,6 +30,7 @@ github.com/coredns/coredns/plugin/pkg/reuseport github.com/coredns/coredns/plugin/pkg/trace github.com/coredns/coredns/plugin/pkg/transport github.com/coredns/coredns/plugin/pkg/uniq +github.com/coredns/coredns/plugin/pkg/upstream github.com/coredns/coredns/plugin/test github.com/coredns/coredns/request # github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 @@ -164,8 +166,7 @@ google.golang.org/protobuf/types/known/anypb google.golang.org/protobuf/types/known/durationpb google.golang.org/protobuf/types/known/timestamppb # gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d -## explicit gopkg.in/asn1-ber.v1 -# gopkg.in/ldap.v2 v2.5.1 +# gopkg.in/ldap.v3 v3.1.0 ## explicit -gopkg.in/ldap.v2 +gopkg.in/ldap.v3