lex-consul 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ffef59de9734ecea3f1f7a1f3ddd987705022d9340ed7284034843b0934b411c
4
+ data.tar.gz: 5ae1ef9cab784f51f516b627448b5c198953c874ba601c1a3da34c0f20bf5fad
5
+ SHA512:
6
+ metadata.gz: b4a52d05f508d068c957d3a06bee4008b29fb1a4f57abba92c02084de28be5522a5764cc92796a68fcf5587520c67ed3c3f8ea753605fc7abfd6c797a35032e0
7
+ data.tar.gz: 9bfffc6c5937b54ea43528e55ff6786b62c75236c587b8dc8fdead6b48061c318381c245106594c49550c3ed8953e2ae6c112a0fdd40b410d2315bdec6cb3b9d
@@ -0,0 +1,16 @@
1
+ name: CI
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ pull_request:
6
+
7
+ jobs:
8
+ ci:
9
+ uses: LegionIO/.github/.github/workflows/ci.yml@main
10
+
11
+ release:
12
+ needs: ci
13
+ if: github.event_name == 'push' && github.ref == 'refs/heads/main'
14
+ uses: LegionIO/.github/.github/workflows/release.yml@main
15
+ secrets:
16
+ rubygems-api-key: ${{ secrets.RUBYGEMS_API_KEY }}
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,58 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.4
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Layout/LineLength:
7
+ Max: 160
8
+
9
+ Layout/SpaceAroundEqualsInParameterDefault:
10
+ EnforcedStyle: space
11
+
12
+ Layout/HashAlignment:
13
+ EnforcedHashRocketStyle: table
14
+ EnforcedColonStyle: table
15
+
16
+ Metrics/MethodLength:
17
+ Max: 50
18
+
19
+ Metrics/ClassLength:
20
+ Max: 1500
21
+
22
+ Metrics/ModuleLength:
23
+ Max: 1500
24
+
25
+ Metrics/BlockLength:
26
+ Max: 40
27
+ Exclude:
28
+ - 'spec/**/*'
29
+
30
+ Metrics/ParameterLists:
31
+ Max: 8
32
+
33
+ Metrics/AbcSize:
34
+ Max: 60
35
+
36
+ Metrics/CyclomaticComplexity:
37
+ Max: 15
38
+
39
+ Metrics/PerceivedComplexity:
40
+ Max: 17
41
+
42
+ Style/Documentation:
43
+ Enabled: false
44
+
45
+ Style/SymbolArray:
46
+ Enabled: true
47
+
48
+ Style/FrozenStringLiteralComment:
49
+ Enabled: true
50
+ EnforcedStyle: always
51
+
52
+ Naming/FileName:
53
+ Enabled: false
54
+
55
+ Naming/MethodParameterName:
56
+ AllowedNames:
57
+ - dc
58
+ - id
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## [0.1.1] - 2026-03-21
4
+
5
+ ### Added
6
+ - `Runners::Partitions` with `list_partitions`, `get_partition`, `create_partition`, `delete_partition` for Consul Enterprise admin partition CRUD
7
+
8
+ ## [0.1.0] - 2026-03-13
9
+
10
+ ### Added
11
+ - Initial release
data/CLAUDE.md ADDED
@@ -0,0 +1,62 @@
1
+ # lex-consul: HashiCorp Consul Integration for LegionIO
2
+
3
+ **Repository Level 3 Documentation**
4
+ - **Parent (Level 2)**: `/Users/miverso2/rubymine/legion/extensions/CLAUDE.md`
5
+ - **Parent (Level 1)**: `/Users/miverso2/rubymine/legion/CLAUDE.md`
6
+
7
+ ## Purpose
8
+
9
+ Legion Extension that connects LegionIO to HashiCorp Consul. Provides runners for interacting with the Consul HTTP API covering KV store, agent management, service catalog, health checks, sessions, events, and cluster status.
10
+
11
+ **GitHub**: https://github.com/LegionIO/lex-consul
12
+ **License**: MIT
13
+ **Version**: 0.1.0
14
+
15
+ ## Architecture
16
+
17
+ ```
18
+ Legion::Extensions::Consul
19
+ ├── Runners/
20
+ │ ├── Kv # KV store CRUD (get, put, delete, list keys)
21
+ │ ├── Agent # Agent info, members, join/leave, maintenance
22
+ │ ├── Catalog # Datacenters, nodes, services, register/deregister
23
+ │ ├── Health # Node health, service checks, checks by state
24
+ │ ├── Session # Distributed lock sessions (create, destroy, renew)
25
+ │ ├── Event # Custom event fire and list
26
+ │ └── Status # Raft leader and peers
27
+ ├── Helpers/
28
+ │ └── Client # Faraday connection builder (Consul HTTP API v1)
29
+ └── Client # Standalone client class (includes all runners)
30
+ ```
31
+
32
+ ## Dependencies
33
+
34
+ | Gem | Purpose |
35
+ |-----|---------|
36
+ | `faraday` | HTTP client for Consul HTTP API |
37
+
38
+ ## API Coverage
39
+
40
+ | Consul API | Runner | Methods |
41
+ |------------|--------|---------|
42
+ | `/v1/kv/` | Kv | get_key, put_key, delete_key, list_keys |
43
+ | `/v1/agent/` | Agent | self_info, members, join, leave, force_leave, reload, maintenance |
44
+ | `/v1/catalog/` | Catalog | datacenters, nodes, services, service, node, register, deregister |
45
+ | `/v1/health/` | Health | node_health, service_checks, service_health, checks_in_state, connect_health |
46
+ | `/v1/session/` | Session | create_session, destroy_session, session_info, list_sessions, node_sessions, renew_session |
47
+ | `/v1/event/` | Event | fire_event, list_events |
48
+ | `/v1/status/` | Status | leader, peers |
49
+
50
+ ## Testing
51
+
52
+ 30 specs across 9 spec files.
53
+
54
+ ```bash
55
+ bundle install
56
+ bundle exec rspec
57
+ bundle exec rubocop
58
+ ```
59
+
60
+ ---
61
+
62
+ **Maintained By**: Matthew Iverson (@Esity)
data/Dockerfile ADDED
@@ -0,0 +1,6 @@
1
+ FROM legionio/legion
2
+
3
+ COPY . /usr/src/app/lex-consul
4
+
5
+ WORKDIR /usr/src/app/lex-consul
6
+ RUN bundle install
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'rake'
8
+ gem 'rspec'
9
+ gem 'rspec_junit_formatter'
10
+ gem 'rubocop'
11
+ gem 'simplecov'
12
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Esity
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # lex-consul
2
+
3
+ HashiCorp Consul integration for [LegionIO](https://github.com/LegionIO/LegionIO). Provides runners for interacting with the Consul HTTP API covering KV store, agent management, catalog, health checks, sessions, events, and cluster status.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install lex-consul
9
+ ```
10
+
11
+ ## Functions
12
+
13
+ ### KV Store (`Runners::Kv`)
14
+ - `get_key` - Read a key (supports recursive and raw modes)
15
+ - `put_key` - Write a key (supports CAS, flags, lock acquire/release)
16
+ - `delete_key` - Delete a key (supports recursive delete and CAS)
17
+ - `list_keys` - List keys by prefix
18
+
19
+ ### Agent (`Runners::Agent`)
20
+ - `self_info` - Read agent configuration
21
+ - `members` - List cluster members
22
+ - `join` - Join a node to the cluster
23
+ - `leave` - Graceful leave
24
+ - `force_leave` - Force remove a node
25
+ - `reload` - Reload agent configuration
26
+ - `maintenance` - Enable/disable maintenance mode
27
+
28
+ ### Catalog (`Runners::Catalog`)
29
+ - `datacenters` - List known datacenters
30
+ - `nodes` - List catalog nodes
31
+ - `services` - List catalog services
32
+ - `service` - List nodes for a service
33
+ - `node` - Get services on a node
34
+ - `register` - Register a node/service/check
35
+ - `deregister` - Deregister a node/service/check
36
+
37
+ ### Health (`Runners::Health`)
38
+ - `node_health` - Health checks for a node
39
+ - `service_checks` - Checks for a service
40
+ - `service_health` - Healthy service instances
41
+ - `checks_in_state` - Checks by state (passing/warning/critical)
42
+ - `connect_health` - Mesh-capable service instances
43
+
44
+ ### Session (`Runners::Session`)
45
+ - `create_session` - Create a session (for distributed locks)
46
+ - `destroy_session` - Destroy a session
47
+ - `session_info` - Read session details
48
+ - `list_sessions` - List all sessions
49
+ - `node_sessions` - List sessions for a node
50
+ - `renew_session` - Renew a session TTL
51
+
52
+ ### Event (`Runners::Event`)
53
+ - `fire_event` - Fire a custom event
54
+ - `list_events` - List recent events
55
+
56
+ ### Status (`Runners::Status`)
57
+ - `leader` - Get Raft leader address
58
+ - `peers` - List Raft peer addresses
59
+
60
+ ## Standalone Usage
61
+
62
+ ```ruby
63
+ require 'legion/extensions/consul'
64
+
65
+ client = Legion::Extensions::Consul::Client.new(
66
+ url: 'http://consul.example.com:8500',
67
+ token: 'my-consul-token'
68
+ )
69
+
70
+ # KV operations
71
+ client.put_key(key: 'config/db/host', value: 'db.example.com')
72
+ client.get_key(key: 'config/db/host')
73
+ client.list_keys(prefix: 'config/')
74
+
75
+ # Service discovery
76
+ client.services
77
+ client.service_health(service: 'web', passing: true)
78
+
79
+ # Cluster status
80
+ client.leader
81
+ client.members
82
+ ```
83
+
84
+ ## Requirements
85
+
86
+ - Ruby >= 3.4
87
+ - [LegionIO](https://github.com/LegionIO/LegionIO) framework (optional for standalone client usage)
88
+ - HashiCorp Consul cluster (any version with HTTP API v1)
89
+ - `faraday` >= 2.0
90
+
91
+ ## License
92
+
93
+ MIT
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/legion/extensions/consul/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'lex-consul'
7
+ spec.version = Legion::Extensions::Consul::VERSION
8
+ spec.authors = ['Esity']
9
+ spec.email = ['matthewdiverson@gmail.com']
10
+
11
+ spec.summary = 'LEX Consul'
12
+ spec.description = 'Connects LegionIO to HashiCorp Consul'
13
+ spec.homepage = 'https://github.com/LegionIO/lex-consul'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.4'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/LegionIO/lex-consul'
19
+ spec.metadata['documentation_uri'] = 'https://github.com/LegionIO/lex-consul'
20
+ spec.metadata['changelog_uri'] = 'https://github.com/LegionIO/lex-consul'
21
+ spec.metadata['bug_tracker_uri'] = 'https://github.com/LegionIO/lex-consul/issues'
22
+ spec.metadata['rubygems_mfa_required'] = 'true'
23
+
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_dependency 'faraday', '>= 2.0'
30
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/consul/helpers/client'
4
+ require 'legion/extensions/consul/runners/kv'
5
+ require 'legion/extensions/consul/runners/agent'
6
+ require 'legion/extensions/consul/runners/catalog'
7
+ require 'legion/extensions/consul/runners/health'
8
+ require 'legion/extensions/consul/runners/session'
9
+ require 'legion/extensions/consul/runners/event'
10
+ require 'legion/extensions/consul/runners/status'
11
+
12
+ module Legion
13
+ module Extensions
14
+ module Consul
15
+ class Client
16
+ include Helpers::Client
17
+ include Runners::Kv
18
+ include Runners::Agent
19
+ include Runners::Catalog
20
+ include Runners::Health
21
+ include Runners::Session
22
+ include Runners::Event
23
+ include Runners::Status
24
+ include Runners::Partitions
25
+
26
+ attr_reader :opts
27
+
28
+ def initialize(url: 'http://127.0.0.1:8500', token: nil, **extra)
29
+ @opts = { url: url, token: token, **extra }
30
+ end
31
+
32
+ def connection(**override)
33
+ super(**@opts.merge(override))
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Consul
8
+ module Helpers
9
+ module Client
10
+ def connection(url: 'http://127.0.0.1:8500', token: nil, **_opts)
11
+ Faraday.new(url: url) do |conn|
12
+ conn.request :json
13
+ conn.response :json, content_type: /\bjson$/
14
+ conn.headers['X-Consul-Token'] = token if token
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/consul/helpers/client'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Consul
8
+ module Runners
9
+ module Agent
10
+ include Legion::Extensions::Consul::Helpers::Client
11
+
12
+ def self_info(**)
13
+ response = connection(**).get('/v1/agent/self')
14
+ { result: response.body }
15
+ end
16
+
17
+ def members(wan: false, **)
18
+ params = {}
19
+ params[:wan] = true if wan
20
+ response = connection(**).get('/v1/agent/members', params)
21
+ { result: response.body }
22
+ end
23
+
24
+ def join(address:, wan: false, **)
25
+ params = {}
26
+ params[:wan] = true if wan
27
+ response = connection(**).put("/v1/agent/join/#{address}", nil, params)
28
+ { result: response.body }
29
+ end
30
+
31
+ def leave(**)
32
+ response = connection(**).put('/v1/agent/leave')
33
+ { result: response.body }
34
+ end
35
+
36
+ def force_leave(node:, prune: false, **)
37
+ params = {}
38
+ params[:prune] = true if prune
39
+ response = connection(**).put("/v1/agent/force-leave/#{node}", nil, params)
40
+ { result: response.body }
41
+ end
42
+
43
+ def reload(**)
44
+ response = connection(**).put('/v1/agent/reload')
45
+ { result: response.body }
46
+ end
47
+
48
+ def maintenance(enable:, reason: nil, **)
49
+ params = { enable: enable }
50
+ params[:reason] = reason if reason
51
+ response = connection(**).put('/v1/agent/maintenance', nil, params)
52
+ { result: response.body }
53
+ end
54
+
55
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
56
+ Legion::Extensions::Helpers.const_defined?(:Lex)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/consul/helpers/client'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Consul
8
+ module Runners
9
+ module Catalog
10
+ include Legion::Extensions::Consul::Helpers::Client
11
+
12
+ def datacenters(**)
13
+ response = connection(**).get('/v1/catalog/datacenters')
14
+ { result: response.body }
15
+ end
16
+
17
+ def nodes(dc: nil, near: nil, filter: nil, **)
18
+ params = {}
19
+ params[:dc] = dc if dc
20
+ params[:near] = near if near
21
+ params[:filter] = filter if filter
22
+ response = connection(**).get('/v1/catalog/nodes', params)
23
+ { result: response.body }
24
+ end
25
+
26
+ def services(dc: nil, filter: nil, **)
27
+ params = {}
28
+ params[:dc] = dc if dc
29
+ params[:filter] = filter if filter
30
+ response = connection(**).get('/v1/catalog/services', params)
31
+ { result: response.body }
32
+ end
33
+
34
+ def service(service:, dc: nil, tag: nil, near: nil, filter: nil, **)
35
+ params = {}
36
+ params[:dc] = dc if dc
37
+ params[:tag] = tag if tag
38
+ params[:near] = near if near
39
+ params[:filter] = filter if filter
40
+ response = connection(**).get("/v1/catalog/service/#{service}", params)
41
+ { result: response.body }
42
+ end
43
+
44
+ def node(node:, dc: nil, filter: nil, **)
45
+ params = {}
46
+ params[:dc] = dc if dc
47
+ params[:filter] = filter if filter
48
+ response = connection(**).get("/v1/catalog/node/#{node}", params)
49
+ { result: response.body }
50
+ end
51
+
52
+ def register(node:, address:, service: nil, check: nil, dc: nil, **)
53
+ body = { Node: node, Address: address }
54
+ body[:Service] = service if service
55
+ body[:Check] = check if check
56
+ body[:Datacenter] = dc if dc
57
+ response = connection(**).put('/v1/catalog/register', body)
58
+ { result: response.body }
59
+ end
60
+
61
+ def deregister(node:, check_id: nil, service_id: nil, dc: nil, **)
62
+ body = { Node: node }
63
+ body[:CheckID] = check_id if check_id
64
+ body[:ServiceID] = service_id if service_id
65
+ body[:Datacenter] = dc if dc
66
+ response = connection(**).put('/v1/catalog/deregister', body)
67
+ { result: response.body }
68
+ end
69
+
70
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
71
+ Legion::Extensions::Helpers.const_defined?(:Lex)
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/consul/helpers/client'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Consul
8
+ module Runners
9
+ module Event
10
+ include Legion::Extensions::Consul::Helpers::Client
11
+
12
+ def fire_event(name:, body: nil, dc: nil, node: nil, service: nil, tag: nil, **)
13
+ params = {}
14
+ params[:dc] = dc if dc
15
+ params[:node] = node if node
16
+ params[:service] = service if service
17
+ params[:tag] = tag if tag
18
+ response = connection(**).put("/v1/event/fire/#{name}", body) do |req|
19
+ req.params = params
20
+ req.headers['Content-Type'] = 'text/plain' if body
21
+ end
22
+ { result: response.body }
23
+ end
24
+
25
+ def list_events(name: nil, node: nil, service: nil, tag: nil, **)
26
+ params = {}
27
+ params[:name] = name if name
28
+ params[:node] = node if node
29
+ params[:service] = service if service
30
+ params[:tag] = tag if tag
31
+ response = connection(**).get('/v1/event/list', params)
32
+ { result: response.body }
33
+ end
34
+
35
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
36
+ Legion::Extensions::Helpers.const_defined?(:Lex)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/consul/helpers/client'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Consul
8
+ module Runners
9
+ module Health
10
+ include Legion::Extensions::Consul::Helpers::Client
11
+
12
+ def node_health(node:, dc: nil, filter: nil, **)
13
+ params = {}
14
+ params[:dc] = dc if dc
15
+ params[:filter] = filter if filter
16
+ response = connection(**).get("/v1/health/node/#{node}", params)
17
+ { result: response.body }
18
+ end
19
+
20
+ def service_checks(service:, dc: nil, near: nil, filter: nil, **)
21
+ params = {}
22
+ params[:dc] = dc if dc
23
+ params[:near] = near if near
24
+ params[:filter] = filter if filter
25
+ response = connection(**).get("/v1/health/checks/#{service}", params)
26
+ { result: response.body }
27
+ end
28
+
29
+ def service_health(service:, dc: nil, passing: false, tag: nil, filter: nil, **)
30
+ params = {}
31
+ params[:dc] = dc if dc
32
+ params[:passing] = true if passing
33
+ params[:tag] = tag if tag
34
+ params[:filter] = filter if filter
35
+ response = connection(**).get("/v1/health/service/#{service}", params)
36
+ { result: response.body }
37
+ end
38
+
39
+ def checks_in_state(state:, dc: nil, near: nil, filter: nil, **)
40
+ params = {}
41
+ params[:dc] = dc if dc
42
+ params[:near] = near if near
43
+ params[:filter] = filter if filter
44
+ response = connection(**).get("/v1/health/state/#{state}", params)
45
+ { result: response.body }
46
+ end
47
+
48
+ def connect_health(service:, dc: nil, passing: false, filter: nil, **)
49
+ params = {}
50
+ params[:dc] = dc if dc
51
+ params[:passing] = true if passing
52
+ params[:filter] = filter if filter
53
+ response = connection(**).get("/v1/health/connect/#{service}", params)
54
+ { result: response.body }
55
+ end
56
+
57
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
58
+ Legion::Extensions::Helpers.const_defined?(:Lex)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/consul/helpers/client'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Consul
8
+ module Runners
9
+ module Kv
10
+ include Legion::Extensions::Consul::Helpers::Client
11
+
12
+ def get_key(key:, dc: nil, recurse: false, raw: false, **)
13
+ params = {}
14
+ params[:dc] = dc if dc
15
+ params[:recurse] = true if recurse
16
+ params[:raw] = true if raw
17
+ response = connection(**).get("/v1/kv/#{key}", params)
18
+ { result: response.body }
19
+ end
20
+
21
+ def put_key(key:, value:, dc: nil, flags: nil, cas: nil, **)
22
+ params = {}
23
+ params[:dc] = dc if dc
24
+ params[:flags] = flags if flags
25
+ params[:cas] = cas if cas
26
+ response = connection(**).put("/v1/kv/#{key}", value) do |req|
27
+ req.params = params
28
+ req.headers['Content-Type'] = 'text/plain'
29
+ end
30
+ { result: response.body }
31
+ end
32
+
33
+ def delete_key(key:, dc: nil, recurse: false, cas: nil, **)
34
+ params = {}
35
+ params[:dc] = dc if dc
36
+ params[:recurse] = true if recurse
37
+ params[:cas] = cas if cas
38
+ response = connection(**).delete("/v1/kv/#{key}", params)
39
+ { result: response.body }
40
+ end
41
+
42
+ def list_keys(prefix: '', dc: nil, separator: nil, **)
43
+ params = { keys: true }
44
+ params[:dc] = dc if dc
45
+ params[:separator] = separator if separator
46
+ response = connection(**).get("/v1/kv/#{prefix}", params)
47
+ { result: response.body }
48
+ end
49
+
50
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
51
+ Legion::Extensions::Helpers.const_defined?(:Lex)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/consul/helpers/client'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Consul
8
+ module Runners
9
+ module Partitions
10
+ include Legion::Extensions::Consul::Helpers::Client
11
+
12
+ def list_partitions(**)
13
+ response = connection(**).get('/v1/partitions')
14
+ { result: response.body }
15
+ end
16
+
17
+ def get_partition(name:, **)
18
+ response = connection(**).get("/v1/partition/#{name}")
19
+ { result: response.body }
20
+ end
21
+
22
+ def create_partition(name:, description: nil, **)
23
+ body = { Name: name }
24
+ body[:Description] = description if description
25
+ response = connection(**).put("/v1/partition/#{name}", body)
26
+ { result: response.body }
27
+ end
28
+
29
+ def delete_partition(name:, **)
30
+ response = connection(**).delete("/v1/partition/#{name}")
31
+ { result: response.body }
32
+ end
33
+
34
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
35
+ Legion::Extensions::Helpers.const_defined?(:Lex)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/consul/helpers/client'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Consul
8
+ module Runners
9
+ module Session
10
+ include Legion::Extensions::Consul::Helpers::Client
11
+
12
+ def create_session(node: nil, name: nil, lock_delay: nil, ttl: nil, behavior: nil, checks: nil, dc: nil, **)
13
+ body = {}
14
+ body[:Node] = node if node
15
+ body[:Name] = name if name
16
+ body[:LockDelay] = lock_delay if lock_delay
17
+ body[:TTL] = ttl if ttl
18
+ body[:Behavior] = behavior if behavior
19
+ body[:Checks] = checks if checks
20
+ params = {}
21
+ params[:dc] = dc if dc
22
+ response = connection(**).put('/v1/session/create', body) do |req|
23
+ req.params = params
24
+ end
25
+ { result: response.body }
26
+ end
27
+
28
+ def destroy_session(id:, dc: nil, **)
29
+ params = {}
30
+ params[:dc] = dc if dc
31
+ response = connection(**).put("/v1/session/destroy/#{id}", nil, params)
32
+ { result: response.body }
33
+ end
34
+
35
+ def session_info(id:, dc: nil, **)
36
+ params = {}
37
+ params[:dc] = dc if dc
38
+ response = connection(**).get("/v1/session/info/#{id}", params)
39
+ { result: response.body }
40
+ end
41
+
42
+ def list_sessions(dc: nil, **)
43
+ params = {}
44
+ params[:dc] = dc if dc
45
+ response = connection(**).get('/v1/session/list', params)
46
+ { result: response.body }
47
+ end
48
+
49
+ def node_sessions(node:, dc: nil, **)
50
+ params = {}
51
+ params[:dc] = dc if dc
52
+ response = connection(**).get("/v1/session/node/#{node}", params)
53
+ { result: response.body }
54
+ end
55
+
56
+ def renew_session(id:, dc: nil, **)
57
+ params = {}
58
+ params[:dc] = dc if dc
59
+ response = connection(**).put("/v1/session/renew/#{id}", nil, params)
60
+ { result: response.body }
61
+ end
62
+
63
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
64
+ Legion::Extensions::Helpers.const_defined?(:Lex)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/consul/helpers/client'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Consul
8
+ module Runners
9
+ module Status
10
+ include Legion::Extensions::Consul::Helpers::Client
11
+
12
+ def leader(dc: nil, **)
13
+ params = {}
14
+ params[:dc] = dc if dc
15
+ response = connection(**).get('/v1/status/leader', params)
16
+ { result: response.body }
17
+ end
18
+
19
+ def peers(dc: nil, **)
20
+ params = {}
21
+ params[:dc] = dc if dc
22
+ response = connection(**).get('/v1/status/peers', params)
23
+ { result: response.body }
24
+ end
25
+
26
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
27
+ Legion::Extensions::Helpers.const_defined?(:Lex)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Consul
6
+ VERSION = '0.1.1'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/consul/version'
4
+ require 'legion/extensions/consul/helpers/client'
5
+ require 'legion/extensions/consul/runners/kv'
6
+ require 'legion/extensions/consul/runners/agent'
7
+ require 'legion/extensions/consul/runners/catalog'
8
+ require 'legion/extensions/consul/runners/health'
9
+ require 'legion/extensions/consul/runners/session'
10
+ require 'legion/extensions/consul/runners/event'
11
+ require 'legion/extensions/consul/runners/status'
12
+ require 'legion/extensions/consul/runners/partitions'
13
+ require 'legion/extensions/consul/client'
14
+
15
+ module Legion
16
+ module Extensions
17
+ module Consul
18
+ extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
19
+ end
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lex-consul
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Esity
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ description: Connects LegionIO to HashiCorp Consul
27
+ email:
28
+ - matthewdiverson@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".github/workflows/ci.yml"
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - CHANGELOG.md
38
+ - CLAUDE.md
39
+ - Dockerfile
40
+ - Gemfile
41
+ - LICENSE
42
+ - README.md
43
+ - lex-consul.gemspec
44
+ - lib/legion/extensions/consul.rb
45
+ - lib/legion/extensions/consul/client.rb
46
+ - lib/legion/extensions/consul/helpers/client.rb
47
+ - lib/legion/extensions/consul/runners/agent.rb
48
+ - lib/legion/extensions/consul/runners/catalog.rb
49
+ - lib/legion/extensions/consul/runners/event.rb
50
+ - lib/legion/extensions/consul/runners/health.rb
51
+ - lib/legion/extensions/consul/runners/kv.rb
52
+ - lib/legion/extensions/consul/runners/partitions.rb
53
+ - lib/legion/extensions/consul/runners/session.rb
54
+ - lib/legion/extensions/consul/runners/status.rb
55
+ - lib/legion/extensions/consul/version.rb
56
+ homepage: https://github.com/LegionIO/lex-consul
57
+ licenses:
58
+ - MIT
59
+ metadata:
60
+ homepage_uri: https://github.com/LegionIO/lex-consul
61
+ source_code_uri: https://github.com/LegionIO/lex-consul
62
+ documentation_uri: https://github.com/LegionIO/lex-consul
63
+ changelog_uri: https://github.com/LegionIO/lex-consul
64
+ bug_tracker_uri: https://github.com/LegionIO/lex-consul/issues
65
+ rubygems_mfa_required: 'true'
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '3.4'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubygems_version: 3.6.9
81
+ specification_version: 4
82
+ summary: LEX Consul
83
+ test_files: []