dvla-kaping 1.0.0 → 1.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09c60001616143c58b1a1023bea7cdcf653c495ea1410222d767dc8718f4507b'
4
- data.tar.gz: 713da1c1de593ffc1e516aa4a0727eae53174fb6832f82a0b8c988b7bba85ff7
3
+ metadata.gz: 760f300cb49bc582101a24d6854ad96ca73094f81423971c47c85fcbc680992e
4
+ data.tar.gz: 756336c4dc3963e399f7af55e3564c7b3165388c331ae35dd8c2895bf337c278
5
5
  SHA512:
6
- metadata.gz: f182de8966f9e515888ccfc137322df7a1fb8a84e7949ae2a9d8d439ff2ecc3f9f464766d864de3d7ec2480d3f965541be74e80af92e9eb8fc7b4d26ded224c0
7
- data.tar.gz: 25a74e3a85a3719952e7239919b53aa1e6a9294713ece79c60ee42cce20ac862fb9b4487e65ceed33661f731dad97f1fdaaacd5256b968aab9fe69fb6f3a63cf
6
+ metadata.gz: 5b3ecb88b4d6c7156921bd9afb8599045064725c0cfbf3158cefbe8e7b16e7cd365071e4c63cbbb0a4e07cf502bc5bf5fbb699587f5d8d68e7745cb9ce53f763
7
+ data.tar.gz: f6bca6eacf464d5ce73f8a1b3028f752e53dcd63969f338f6773028c10597e4974d9648b6c8d7801f44c26431eb2234dd982df8379f6cca1b89e5d55b3948fcf
data/.rubocop.yml CHANGED
@@ -2,7 +2,7 @@ inherit_gem:
2
2
  dvla-lint: ".rubocop.yml"
3
3
 
4
4
  AllCops:
5
- TargetRubyVersion: 3.0
5
+ TargetRubyVersion: 4.0
6
6
 
7
7
  Style/StringLiterals:
8
8
  EnforcedStyle: single_quotes
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.4.2
1
+ 4.0.2
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 4.0.2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2024-11-07
3
+ ## [1.0.5] - 2025-11-10
4
+
5
+ - Fixed AWS credential handling to return proper credentials from assume role
6
+ - Added AWS credential chain and SSO documentation to README
7
+
8
+ ## [1.0.4] - 2025-11-10
9
+
10
+ - Update gems and fixed issue with git actions
11
+
12
+ ## [1.0.3] - 2025-09-03
13
+
14
+ - Moved runtime dependencies to the gemspec
15
+
16
+ ## [1.0.2] - 2024-11-07
4
17
 
5
18
  - Initial release
19
+
data/README.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Dvla::Kaping
2
2
 
3
- The Kaping! gem - an idiomatic way to create DSL openSearch definitions
3
+ The Kaping! Gem, an idiomatic way to create DSL openSearch definitions
4
+
5
+ The Ka-Ping Ruby gem enables the user to build complex ElasticSearch DSL Queries for searching and filtering large data sets
6
+ without having to worry about formatting the JSON payloads.
7
+
8
+ Using Ruby dot notation with intuitive search terms and operations, it's easier to construct human-readable search definitions
9
+ without needing a deep understanding of the Query DSL syntax
10
+
4
11
 
5
12
  ## OpenSearch Query DSL
6
13
  https://opensearch.org/docs/latest/query-dsl/
@@ -28,10 +35,10 @@ complex to construct so this gem looks to simplify the process.
28
35
 
29
36
  ## Query and filter context
30
37
 
31
- A filter context asks - “Does the document match the query clause?” and returns matching documents
38
+ A filter context asks: “Does the document match the query clause?” and returns matching documents
32
39
  i.e it's a binary answer
33
40
 
34
- A query context asks - “How well does the document match the query clause?”, - also returns a relevance score
41
+ A query context asks: “How well does the document match the query clause?”, - also returns a relevance score
35
42
  good for full-text searches
36
43
 
37
44
  # How to use
@@ -55,8 +62,8 @@ DVLA::Kaping.configure { |attr| attr.yaml_override_path = './config/kaping.yml'
55
62
  ```
56
63
  The 'index' setting will control what environment to target
57
64
 
58
- The 'result_size' setting determines how many records to be returned from the query, if you are doing a post query filtering
59
- code side then you should pump this value up.
65
+ The 'result_size' setting determines how many records to be returned from the query, if you are doing a post-query filtering
66
+ code side, then you should pump this value up.
60
67
 
61
68
  ```yml
62
69
  kaping:
@@ -67,18 +74,52 @@ kaping:
67
74
 
68
75
  ```
69
76
  If you want to use the built-in client, and your OpenSearch instance is hosted in a Amazon VPC you will need to assume AWS permissions for access to run the queries.
70
- there are two options, you can either use profile or environment
77
+ There are two options, you can either use profile or environment
71
78
 
72
- Profile will just pick up the credentials save in your specified shared credentials ini file at ~/.aws/credentials,
79
+ Profile will just pick up the credentials saved in your specified shared credentials ini file at ~/.aws/credentials,
73
80
 
74
81
  ```yml
75
82
  aws:
76
- # to use a AWS profile config file then set to profile, otherwise environment settings will be used
77
- credential_type: profile
83
+ # to use an AWS profile config file, then set to profile, otherwise environment settings will be used
84
+ credential_type: profile | env | credentials
78
85
  account_id: ##########
86
+ role: ROLE
79
87
  region: aws-region
80
88
  profile: PROFILE
81
- role: ROLE
89
+
90
+ ```
91
+
92
+ ### AWS Credential Chain
93
+
94
+ The gem supports three credential strategies:
95
+
96
+ | credential_type | How it works |
97
+ |---|---|
98
+ | `profile` | Uses the named profile from `~/.aws/config` to create an STS client, then assumes the configured role. Supports SSO profiles. |
99
+ | `env` | Uses environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, or `AWS_PROFILE`) to create an STS client, then assumes the configured role. |
100
+ | `credentials` | Delegates to the AWS SDK default credential provider chain, which walks through env vars → shared config/credentials → SSO → ECS/EC2 instance roles in order. No role assumption is performed. |
101
+
102
+ ### Using AWS SSO
103
+
104
+ If your organisation uses AWS IAM Identity Center (SSO), authenticate first then set the profile:
105
+
106
+ ```bash
107
+ aws sso login --profile my-sso-profile
108
+ ```
109
+
110
+ Then either:
111
+ - Set `credential_type: profile` and `profile: my-sso-profile` in your `kaping.yml`
112
+ - Or set `credential_type: env` / `credentials` and export `AWS_PROFILE=my-sso-profile`
113
+
114
+ The SDK will resolve the cached SSO token automatically. Ensure your `~/.aws/config` has the SSO profile configured, for example:
115
+
116
+ ```ini
117
+ [profile my-sso-profile]
118
+ sso_start_url = https://my-org.awsapps.com/start
119
+ sso_region = eu-west-2
120
+ sso_account_id = 123456789012
121
+ sso_role_name = MyRole
122
+ region = eu-west-2
82
123
  ```
83
124
 
84
125
  ## Client
@@ -106,7 +147,7 @@ body = DVLA::Kaping::Query.new('bool')
106
147
  ## Query building
107
148
  A query can be built up with dot notation, but there are a few rules to follow.
108
149
 
109
- First get a new Kaping Query instance. If we want a new Boolean query then we set the type as bool.
150
+ First, get a new Kaping Query instance. If we want a new Boolean query then we set the type as bool.
110
151
  ```ruby
111
152
  my_query = DVLA::Kaping::Query.new('bool')
112
153
  my_query.filter.term('foo.bar', 'Valid').
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'aws-sdk-core'
4
3
  require 'opensearch-aws-sigv4'
5
4
  require 'aws-sigv4'
5
+ require 'aws-sdk-sts'
6
6
 
7
7
  module DVLA
8
8
  module Kaping
@@ -11,25 +11,34 @@ module DVLA
11
11
  @base_url = Kaping.yaml[:kaping_host]
12
12
  @aws_account_id = Kaping.yaml.dig(:aws, :account_id)
13
13
  @role = Kaping.yaml.dig(:aws, :role)
14
- @region = Kaping.yaml.dig(:aws, :region)
15
- Kaping.logger.info { "Kaping Client | base_url: '#{@base_url}'" }
14
+ @region = Kaping.yaml.dig(:aws, :region) || 'eu-west-2'
15
+ Kaping.logger.debug { "AWS Client | base_url: '#{@base_url}'" }
16
+ end
17
+
18
+ def select_credentials
19
+ case Kaping.yaml.dig(:aws, :credential_type)
20
+ when 'profile'
21
+ assume_role_profile(@aws_account_id, @role)
22
+ when 'env'
23
+ assume_role_env(@aws_account_id, @role)
24
+ when 'credentials'
25
+ Aws::CredentialProviderChain.new.resolve
26
+ else
27
+ logger.warn { 'Credential type not recognised, please set an option: profile, env or credentials' }
28
+ end
16
29
  end
17
30
 
18
31
  def connect
19
- credentials = if Kaping.yaml.dig(:aws, :credential_type) == 'profile'
20
- assume_role_profile(@aws_account_id, @role)
21
- else
22
- assume_role_env(@aws_account_id, @role)
23
- end
32
+ credentials = select_credentials
24
33
 
25
34
  signer = Aws::Sigv4::Signer.new(service: 'es',
26
35
  region: @region,
27
36
  credentials_provider: credentials)
28
37
 
29
38
  OpenSearch::Aws::Sigv4Client.new({
30
- host: @base_url,
31
- log: false,
32
- }, signer)
39
+ host: @base_url,
40
+ log: false,
41
+ }, signer)
33
42
  end
34
43
 
35
44
  private
@@ -38,7 +47,9 @@ module DVLA
38
47
  def assume_role_profile(aws_account_id, role)
39
48
  role_arn = "arn:aws:iam::#{aws_account_id}:role/#{role}"
40
49
  sts = Aws::STS::Client.new(region: @region, profile: Kaping.yaml.dig(:aws, :profile))
41
- sts.assume_role(role_arn: role_arn, role_session_name: 'kaping')
50
+ resp = sts.assume_role(role_arn: role_arn, role_session_name: 'kaping')
51
+ Aws::Credentials.new(resp.credentials.access_key_id, resp.credentials.secret_access_key,
52
+ resp.credentials.session_token)
42
53
  rescue Aws::STS::Errors::ServiceError => e
43
54
  raise "#{__method__}: AWS Profile Credentials Issue: #{e.message} #{e.class.name}"
44
55
  end
@@ -47,7 +58,9 @@ module DVLA
47
58
  def assume_role_env(aws_account_id, role)
48
59
  role_arn = "arn:aws:iam::#{aws_account_id}:role/#{role}"
49
60
  sts = Aws::STS::Client.new(region: @region)
50
- sts.assume_role(role_arn: role_arn, role_session_name: 'kaping')
61
+ resp = sts.assume_role(role_arn: role_arn, role_session_name: 'kaping')
62
+ Aws::Credentials.new(resp.credentials.access_key_id, resp.credentials.secret_access_key,
63
+ resp.credentials.session_token)
51
64
  rescue Aws::STS::Errors::ServiceError => e
52
65
  raise "#{__method__}: AWS ENV Credentials Issue: #{e.message} #{e.class.name}"
53
66
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module DVLA
4
4
  module Kaping
5
- VERSION = '1.0.0'
5
+ VERSION = '1.0.5'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,35 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dvla-kaping
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Driver and Vehicle Licensing Agency (DVLA)
8
8
  - Kevin Upstill
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-11 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: nokogiri
14
+ name: aws-sdk-sts
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
20
- - - ">="
19
+ version: '1.12'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
21
25
  - !ruby/object:Gem::Version
22
- version: 1.16.7
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sigv4
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
23
34
  type: :runtime
24
35
  prerelease: false
25
36
  version_requirements: !ruby/object:Gem::Requirement
26
37
  requirements:
27
38
  - - "~>"
28
39
  - !ruby/object:Gem::Version
29
- version: '1.16'
30
- - - ">="
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.19'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.19'
55
+ - !ruby/object:Gem::Dependency
56
+ name: opensearch-aws-sigv4
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
31
67
  - !ruby/object:Gem::Version
32
- version: 1.16.7
68
+ version: '1.3'
33
69
  description: Wrapper for the AWS elastic search API to create an idiomatic way to
34
70
  build complex search queries
35
71
  email:
@@ -38,10 +74,10 @@ executables: []
38
74
  extensions: []
39
75
  extra_rdoc_files: []
40
76
  files:
41
- - ".drone.yml"
42
77
  - ".rspec"
43
78
  - ".rubocop.yml"
44
79
  - ".ruby-version"
80
+ - ".tool-versions"
45
81
  - CHANGELOG.md
46
82
  - CODE_OF_CONDUCT.md
47
83
  - LICENCE
@@ -70,14 +106,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
106
  requirements:
71
107
  - - ">="
72
108
  - !ruby/object:Gem::Version
73
- version: '3'
109
+ version: '4'
74
110
  required_rubygems_version: !ruby/object:Gem::Requirement
75
111
  requirements:
76
112
  - - ">="
77
113
  - !ruby/object:Gem::Version
78
114
  version: '0'
79
115
  requirements: []
80
- rubygems_version: 3.6.2
116
+ rubygems_version: 4.0.6
81
117
  specification_version: 4
82
118
  summary: Idiomatic way to create DSL openSearch definitions
83
119
  test_files: []
data/.drone.yml DELETED
@@ -1,122 +0,0 @@
1
- ---
2
- kind: pipeline
3
- name: audit, lint & test
4
-
5
- platform:
6
- os: linux
7
- arch: amd64
8
-
9
- trigger:
10
- event:
11
- - push
12
-
13
- drone_cache_image: &drone_cache_image
14
- image: 448934085854.dkr.ecr.eu-west-2.amazonaws.com/ce/drone-cache
15
- pull: if-not-exists
16
-
17
- drone_cache_settings: &drone_cache_settings
18
- bucket: dvla-drone1-cache-448934085854
19
- region: eu-west-2
20
- encryption: AES256
21
- endpoint: https://s3.eu-west-2.amazonaws.com
22
-
23
- gem_cache_mount: &gem_cache_mount
24
- mount:
25
- - vendor/bundle
26
-
27
- ruby_image: &ruby_image
28
- image: 448934085854.dkr.ecr.eu-west-2.amazonaws.com/base-images/qe-ruby:3
29
-
30
- sonar_image: &sonar_image
31
- image: 448934085854.dkr.ecr.eu-west-2.amazonaws.com/utilities-ci-tools/ci-drone-sonar-scanner
32
- pull: if-not-exists
33
-
34
- steps:
35
- - name: Restore gems from cache
36
- <<: *drone_cache_image
37
- settings:
38
- <<: *drone_cache_settings
39
- <<: *gem_cache_mount
40
- restore: true
41
- cache_key: '{{ checksum "./README.md" }}' # Override the README to force a rebuild
42
-
43
- - name: Unit tests
44
- <<: *ruby_image
45
- depends_on:
46
- - Restore gems from cache
47
- commands:
48
- - bundle install
49
- - bundle exec rspec
50
- environment:
51
- BUNDLE_PATH: vendor/bundle
52
-
53
- - name: Gem audit
54
- <<: *ruby_image
55
- depends_on:
56
- - Restore gems from cache
57
- commands:
58
- - bundle install
59
- - bundle exec bundle-audit
60
- environment:
61
- BUNDLE_PATH: vendor/bundle
62
-
63
- - name: Lint
64
- <<: *ruby_image
65
- depends_on:
66
- - Restore gems from cache
67
- commands:
68
- - bundle install
69
- - bundle exec rubocop
70
- environment:
71
- BUNDLE_PATH: vendor/bundle
72
-
73
- - name: SonarQube
74
- <<: *sonar_image
75
- depends_on:
76
- - Unit tests
77
-
78
- - name: Build and deploy (dry-run)
79
- image: 448934085854.dkr.ecr.eu-west-2.amazonaws.com/utilities-ci-tools/ci-qe-deploy-gem:latest
80
- commands:
81
- - git fetch origin main
82
- - app
83
- environment:
84
- DRYRUN: true
85
- VERBOSE: false
86
-
87
- - name: Rebuild gem cache
88
- <<: *drone_cache_image
89
- depends_on:
90
- - Gem audit
91
- settings:
92
- <<: *drone_cache_settings
93
- <<: *gem_cache_mount
94
- rebuild: true
95
- cache_key: '{{ checksum "./README.md" }}'
96
-
97
- ---
98
- kind: pipeline
99
- name: deploy
100
- depends_on:
101
- - audit, lint & test
102
-
103
- platform:
104
- os: linux
105
- arch: amd64
106
-
107
- trigger:
108
- event:
109
- - push
110
- branch:
111
- - main
112
-
113
- steps:
114
- - name: Build and deploy
115
- image: 448934085854.dkr.ecr.eu-west-2.amazonaws.com/utilities-ci-tools/ci-qe-deploy-gem:latest
116
- commands:
117
- - git fetch origin main
118
- - app
119
- environment:
120
- DRYRUN: false
121
- VERBOSE: false
122
-