activerecord_aad 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a48d0ca00ef9c661c33af8afd9f5e960ed7d64b16966c544c4f3d2216b7b53d5
4
+ data.tar.gz: 9d807d04d19a013900ec0d3f88a5c8f455dbe0fc576c009e22b893508a9e4eb4
5
+ SHA512:
6
+ metadata.gz: 3708212cbe063704278a117defd086077464a2cbd326dfcdd1a6f91c8d2901ac6952f881c3d1766410e8cb16b1d1c1e073b970e7587ab12193163fd072415aae
7
+ data.tar.gz: 1576b4ab5cda795ccb239c7ef80fc1eae01e40525d52a62adb4583cf35d580aecbd4c26f62a4f3da626967223265c00f83f811d8ce944c781d5feb6a373f9af5
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Microsoft
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # activerecord-aad
2
+
3
+ This gem enables using an Azure ActiveDirectory Managed Identity to connect to an Azure Database Service
4
+
5
+ ## Installation
6
+
7
+ - Add `gem :activerecord_aad` to your Gemfile.
8
+ - Run `bin/bundle install`
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'activerecord_aad'
7
+ s.version = '0.0.1'
8
+ s.authors = ['Taylor Yelverton']
9
+ s.email = 'rubygems@yelvert.io'
10
+ s.homepage = 'https://github.com/ComplyMD/activerecord_aad'
11
+ s.summary = ''
12
+ s.license = 'MIT'
13
+ s.description = ''
14
+ s.metadata = {
15
+ 'bug_tracker_uri' => 'https://github.com/ComplyMD/activerecord_aad/issues',
16
+ 'changelog_uri' => 'https://github.com/ComplyMD/activerecord_aad/commits/master',
17
+ 'documentation_uri' => 'https://github.com/ComplyMD/activerecord_aad/wiki',
18
+ 'homepage_uri' => 'https://github.com/ComplyMD/activerecord_aad',
19
+ 'source_code_uri' => 'https://github.com/ComplyMD/activerecord_aad',
20
+ 'rubygems_mfa_required' => 'true',
21
+ }
22
+
23
+ s.files = Dir['lib/**/*', 'README.md', 'LICENSE', 'activerecord_aad.gemspec']
24
+
25
+ s.require_paths = %w[ lib ]
26
+
27
+ s.required_ruby_version = '>= 2.7.0'
28
+
29
+ s.add_dependency('activerecord', '>= 6.0.0', '< 8.0.0')
30
+ s.add_dependency('httparty', '~> 0.21.0')
31
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Azure
4
+ module ActiveDirectory
5
+ module ActiveRecord
6
+
7
+ module HashConfig
8
+
9
+ def configuration_hash
10
+ hash = super.dup
11
+ if hash.key?(:azure_managed_identity)
12
+ @managed_identity_manager ||= ManagedIdentityManager.new(hash[:azure_managed_identity])
13
+ @managed_identity_manager.apply(hash)
14
+ end
15
+ hash.symbolize_keys!.freeze
16
+ puts hash
17
+ hash
18
+ end
19
+
20
+ end
21
+
22
+ class ManagedIdentityManager
23
+ URL = 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fossrdbms-aad.database.windows.net'
24
+
25
+ attr_reader :config, :url
26
+
27
+ def initialize(conf)
28
+ raise "ActiveRecordAAD: invalid config: `#{conf}`" unless conf.is_a?(Hash)
29
+ @config = conf.with_indifferent_access
30
+ raise 'ActiveRecordAAD: missing client_id' unless config[:client_id].present?
31
+ @client_id = config[:client_id]
32
+ @url = URL
33
+ @url += "&client_id=#{@client_id}" if @client_id.present?
34
+ end
35
+
36
+ def apply(hash)
37
+ hash.merge!(password: access_token, enable_cleartext_plugin: true)
38
+ end
39
+
40
+ def access_token
41
+ @access_token_response = HTTParty.get(url, { headers: { Metadata: 'true' } })
42
+ raise "ActiveRecordAAD: unable to get access token: `#{@access_token_response}`" unless @access_token_response.ok?
43
+ @access_token = @access_token_response['access_token']
44
+ end
45
+
46
+ end
47
+
48
+ class Railtie < Rails::Railtie
49
+ railtie_name :activerecord_aad
50
+
51
+ initializer 'activerecord_aad.config' do
52
+ ::ActiveRecord::DatabaseConfigurations::HashConfig.prepend HashConfig
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord_aad
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Taylor Yelverton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 6.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 8.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 6.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 8.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: httparty
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.21.0
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.21.0
47
+ description: ''
48
+ email: rubygems@yelvert.io
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - LICENSE
54
+ - README.md
55
+ - activerecord_aad.gemspec
56
+ - lib/activerecord_aad.rb
57
+ homepage: https://github.com/ComplyMD/activerecord_aad
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ bug_tracker_uri: https://github.com/ComplyMD/activerecord_aad/issues
62
+ changelog_uri: https://github.com/ComplyMD/activerecord_aad/commits/master
63
+ documentation_uri: https://github.com/ComplyMD/activerecord_aad/wiki
64
+ homepage_uri: https://github.com/ComplyMD/activerecord_aad
65
+ source_code_uri: https://github.com/ComplyMD/activerecord_aad
66
+ rubygems_mfa_required: 'true'
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.7.0
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.1.4
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: ''
86
+ test_files: []