Skip to content

Commit ae6807b

Browse files
authored
Merge pull request #309 from jonathannewman/PE-36370/main/remove-yaml-support
(PE-36370) remove yaml support
2 parents 383f621 + 64ab29f commit ae6807b

28 files changed

+373
-296
lines changed

.clj-kondo/config.edn

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{:linters {:unresolved-symbol {:level :warning :exclude [(puppetlabs.trapperkeeper.services/service)
2+
(puppetlabs.trapperkeeper.core/defservice)
3+
(puppetlabs.trapperkeeper.core/service)
4+
(puppetlabs.trapperkeeper.services/defservice)
5+
(clojure.test/is [thrown+? thrown+-with-msg? logged?])
6+
(puppetlabs.trapperkeeper.testutils.bootstrap/with-app-with-cli-data)
7+
(puppetlabs.trapperkeeper.testutils.bootstrap/with-app-with-config)
8+
(puppetlabs.trapperkeeper.testutils.bootstrap/with-app-with-empty-config)
9+
(puppetlabs.trapperkeeper.testutils.bootstrap/with-app-with-cli-args)
10+
(puppetlabs.trapperkeeper.testutils.logging/with-started)
11+
(puppetlabs.trapperkeeper.testutils.logging/with-logger-event-maps)
12+
(puppetlabs.trapperkeeper.testutils.logging/with-logged-event-maps)]}
13+
:invalid-arity {:skip-args [puppetlabs.trapperkeeper.services/service
14+
puppetlabs.trapperkeeper.services/defservice
15+
puppetlabs.trapperkeeper.core/defservice
16+
puppetlabs.trapperkeeper.core/service]}
17+
:refer-all {:level :off}
18+
:inline-def {:level :off}
19+
:deprecated-var {:level :off}}
20+
21+
:lint-as {puppetlabs.trapperkeeper.core/defservice clojure.core/def
22+
puppetlabs.trapperkeeper.services/defservice clojure.core/def
23+
slingshot.slingshot/try+ clojure.core/try
24+
puppetlabs.kitchensink.core/while-let clojure.core/let}}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Clojure Linting
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, edited, synchronize]
6+
paths: ['src/**','test/**','.clj-kondo/config.edn','project.clj','.github/**']
7+
8+
jobs:
9+
clojure-linting:
10+
name: Clojure Linting
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: setup java
14+
uses: actions/setup-java@v3
15+
with:
16+
distribution: temurin
17+
java-version: 17
18+
- name: checkout repo
19+
uses: actions/checkout@v2
20+
- name: install clj-kondo (this is quite fast)
21+
run: |
22+
curl -sLO https://raw.githubusercontent.com/clj-kondo/clj-kondo/master/script/install-clj-kondo
23+
chmod +x install-clj-kondo
24+
./install-clj-kondo --dir .
25+
- name: kondo lint
26+
run: ./clj-kondo --lint src test
27+
- name: eastwood lint
28+
run: |
29+
java -version
30+
lein eastwood

.github/workflows/lein-test.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: PR Testing
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
types: [opened, reopened, edited, synchronize]
7+
paths: ['src/**','test/**','project.clj']
8+
9+
jobs:
10+
pr-testing:
11+
name: PR Testing
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
version: ['8', '11', '17']
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: checkout repo
19+
uses: actions/checkout@v3
20+
with:
21+
submodules: recursive
22+
- name: setup java
23+
uses: actions/setup-java@v3
24+
with:
25+
distribution: 'temurin'
26+
java-version: ${{ matrix.version }}
27+
- name: clojure tests
28+
run: lein test
29+
timeout-minutes: 30

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 4.0.0
2+
3+
This is a major release with breaking changes.
4+
* remove support for yaml configuration files
5+
* add clj-kondo linting and fix issues found
6+
* add eastwood linting and fix issues found
7+
18
## 3.3.1
29

310
This is a maintenance release

dev-resources/config/file/config.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

dev-resources/config/mixeddir/qux.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.

project.clj

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
(defproject puppetlabs/trapperkeeper "3.3.1-SNAPSHOT"
1+
(defproject puppetlabs/trapperkeeper "4.0.0-SNAPSHOT"
22
:description "A framework for configuring, composing, and running Clojure services."
33

44
:license {:name "Apache License, Version 2.0"
55
:url "http://www.apache.org/licenses/LICENSE-2.0.html"}
66

77
:min-lein-version "2.9.0"
88

9-
:parent-project {:coords [puppetlabs/clj-parent "5.3.2"]
9+
:parent-project {:coords [puppetlabs/clj-parent "6.0.1"]
1010
:inherit [:managed-dependencies]}
1111

1212
;; Abort when version ranges or version conflicts are detected in
@@ -32,7 +32,6 @@
3232

3333
[clj-time]
3434
[clj-commons/fs]
35-
[clj-commons/clj-yaml]
3635

3736
[prismatic/plumbing]
3837
[prismatic/schema]
@@ -44,7 +43,8 @@
4443
;; see https://github.com/puppetlabs/trapperkeeper/pull/306#issuecomment-1467059264
4544
[puppetlabs/kitchensink nil :exclusions [cheshire]]
4645
[puppetlabs/i18n]
47-
[nrepl/nrepl]]
46+
[nrepl/nrepl]
47+
[io.github.clj-kondo/config-slingshot-slingshot "1.0.0"]]
4848

4949
:deploy-repositories [["releases" {:url "https://clojars.org/repo"
5050
:username :env/clojars_jenkins_username
@@ -70,7 +70,25 @@
7070
:classifiers ^:replace []}}
7171

7272
:plugins [[lein-parent "0.3.7"]
73-
[puppetlabs/i18n "0.8.0"]]
73+
[jonase/eastwood "1.2.2" :exclusions [org.clojure/clojure]]
74+
[puppetlabs/i18n "0.9.2"]]
75+
76+
:eastwood {:ignored-faults {:reflection {puppetlabs.trapperkeeper.logging [{:line 92}]
77+
puppetlabs.trapperkeeper.internal [{:line 128}]
78+
puppetlabs.trapperkeeper.testutils.logging true
79+
puppetlabs.trapperkeeper.testutils.logging-test true
80+
puppetlabs.trapperkeeper.services.nrepl.nrepl-service-test true
81+
puppetlabs.trapperkeeper.plugins-test true}
82+
:local-shadows-var {puppetlabs.trapperkeeper.config-test true
83+
puppetlabs.trapperkeeper.services-test true
84+
java-service-example.java-service true
85+
puppetlabs.trapperkeeper.optional-deps-test true}
86+
:deprecations {puppetlabs.trapperkeeper.testutils.logging true
87+
puppetlabs.trapperkeeper.testutils.logging-test true
88+
puppetlabs.trapperkeeper.logging-test true}
89+
:def-in-def {puppetlabs.trapperkeeper.optional-deps-test true}}
90+
91+
:continue-on-exception true}
92+
93+
:main puppetlabs.trapperkeeper.main)
7494

75-
:main puppetlabs.trapperkeeper.main
76-
)

src/puppetlabs/trapperkeeper/bootstrap.clj

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
a 2-item vector containing the namespace and the service name. Throws
3838
an IllegalArgumentException if the line is not valid."
3939
[line :- schema/Str]
40-
(if-let [[match namespace service-name] (re-matches
41-
#"^([a-zA-Z0-9\.\-]+)/([a-zA-Z0-9\.\-]+)$"
42-
line)]
40+
(if-let [[_match namespace service-name] (re-matches
41+
#"^([a-zA-Z0-9\.\-]+)/([a-zA-Z0-9\.\-]+)$"
42+
line)]
4343
{:namespace namespace :service-name service-name}
4444
(throw+ {:type ::bootstrap-parse-error
4545
:message (i18n/trs "Invalid line in bootstrap config file:\n\n\t{0}\n\nAll lines must be of the form: ''<namespace>/<service-fn-name>''." line)})))
@@ -162,7 +162,7 @@
162162
[configs :- [schema/Str]]
163163
(for [config configs
164164
[line-number line-text] (indexed (map remove-comments (read-config config)))
165-
:when (not (empty? line-text))]
165+
:when (seq line-text)]
166166
{:bootstrap-file config
167167
:line-number (inc line-number)
168168
:entry line-text}))
@@ -186,12 +186,12 @@
186186
service->entry-map :- {(schema/protocol services/ServiceDefinition) AnnotatedBootstrapEntry}]
187187
(let [make-error-message (fn [service]
188188
(let [entry (get service->entry-map service)]
189-
(i18n/trs "{0}:{1}\n{2}" (:bootstrap-file entry) (:line-number entry) (:entry entry))))]
190-
(let [error-messages (for [[protocol-id services] duplicate-services]
191-
(i18n/trs "Duplicate implementations found for service protocol ''{0}'':\n{1}"
192-
protocol-id
193-
(string/join "\n" (map make-error-message services))))]
194-
(IllegalArgumentException. (string/join "\n" error-messages)))))
189+
(i18n/trs "{0}:{1}\n{2}" (:bootstrap-file entry) (:line-number entry) (:entry entry))))
190+
error-messages (for [[protocol-id services] duplicate-services]
191+
(i18n/trs "Duplicate implementations found for service protocol ''{0}'':\n{1}"
192+
protocol-id
193+
(string/join "\n" (map make-error-message services))))]
194+
(IllegalArgumentException. (string/join "\n" error-messages))))
195195

196196
(schema/defn check-duplicate-service-implementations!
197197
"Throws an exception if two services implement the same service protocol"
@@ -200,12 +200,12 @@
200200

201201
; Zip up the services and bootstrap entries and construct a map out of them
202202
; to use as a lookup table below
203-
(let [service->entry-map (zipmap services bootstrap-entries)]
204-
; Find duplicates base on the service id returned by calling service-def-id
205-
; on each service
206-
(let [duplicates (find-duplicates services services/service-def-id)]
207-
(when (not (empty? duplicates))
208-
(throw (duplicate-protocol-error duplicates service->entry-map))))))
203+
(let [service->entry-map (zipmap services bootstrap-entries)
204+
; Find duplicates base on the service id returned by calling service-def-id
205+
; on each service
206+
duplicates (find-duplicates services services/service-def-id)]
207+
(when (seq duplicates)
208+
(throw (duplicate-protocol-error duplicates service->entry-map)))))
209209

210210
(schema/defn ^:private resolve-service! :- (schema/protocol services/ServiceDefinition)
211211
"Given the namespace and name of a service, loads the namespace,
@@ -242,11 +242,11 @@
242242
243243
Throws an IllegalArgumentException if there is a problem parsing the bootstrap
244244
entry, or if the service is found but it has an invalid service graph."
245-
[{:keys [bootstrap-file line-number entry] :as bootstrap-entry} :- AnnotatedBootstrapEntry]
245+
[{:keys [bootstrap-file line-number entry]} :- AnnotatedBootstrapEntry]
246246
(try+
247247
(let [{:keys [namespace service-name]} (parse-bootstrap-line! entry)]
248248
(resolve-service! namespace service-name))
249-
(catch [:type ::missing-service] {:keys [message]}
249+
(catch [:type ::missing-service] {:keys [_message]}
250250
(log/warn (i18n/trs "Unable to load service ''{0}'' from {1}:{2}" entry bootstrap-file line-number)))
251251
; Catch and re-throw as java exception
252252
(catch [:type ::internal/invalid-service-graph] {:keys [message]}

src/puppetlabs/trapperkeeper/config.clj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
[me.raynes.fs :as fs]
2424
[puppetlabs.kitchensink.core :as ks]
2525
[puppetlabs.config.typesafe :as typesafe]
26-
[clj-yaml.core :as yaml]
2726
[puppetlabs.trapperkeeper.services :refer [service service-context]]
2827
[puppetlabs.trapperkeeper.logging :refer [configure-logging!]]
2928
[clojure.tools.logging :as log]
@@ -57,9 +56,6 @@
5756
#{".edn"}
5857
(edn/read (PushbackReader. (io/reader file)))
5958

60-
#{".yaml" ".yml"}
61-
(yaml/parse-string (slurp file))
62-
6359
(throw (IllegalArgumentException.
6460
(i18n/trs "Config file {0} must end in .conf or other recognized extension"
6561
(-> file str pr-str))))))
@@ -68,7 +64,7 @@
6864
[config-data cli-data]
6965
(if-let [cli-restart-file (:restart-file cli-data)]
7066
(do
71-
(if (get-in config-data [:global :restart-file])
67+
(when (get-in config-data [:global :restart-file])
7268
(log/warnf (i18n/trs "restart-file setting specified both on command-line and in config file, using command-line value: ''{0}''"
7369
cli-restart-file)))
7470
(assoc-in config-data [:global :restart-file] cli-restart-file))
@@ -89,7 +85,7 @@
8985
[path]
9086
(mapcat
9187
#(fs/glob (fs/file path %))
92-
["*.ini" "*.conf" "*.json" "*.properties" "*.edn" "*.yaml" "*.yml"])))
88+
["*.ini" "*.conf" "*.json" "*.properties" "*.edn"])))
9389

9490
(defn load-config
9591
"Given a path to a configuration file or directory of configuration files,

src/puppetlabs/trapperkeeper/core.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@
166166
(throw (ex-info (i18n/trs "Process exit requested")
167167
(assoc (::exit result) :kind ::exit)))))))
168168

169-
(defn- parse-args [args]
169+
(defn- parse-args
170170
"Returns valid CLIData or throws an ::exit."
171+
[args]
171172
(letfn [(quit [status msg stream ex-msg]
172173
(throw (ex-info ex-msg
173174
;; :status and :messages match exit-request-schema
@@ -177,7 +178,7 @@
177178
(try
178179
(internal/parse-cli-args! (or args ()))
179180
(catch ExceptionInfo ex
180-
(let [{:keys [kind msg] :as data} (ex-data ex)]
181+
(let [{:keys [kind msg]} (ex-data ex)]
181182
(case (some-> kind without-ns)
182183
:cli-error (quit 1 msg *err* (i18n/trs "Invalid program arguments"))
183184
:cli-help (quit 0 msg *out* (i18n/trs "Command line --help requested"))

0 commit comments

Comments
 (0)