en-aws-synchronizer 0.1.0

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: cb9acf091bb20cffe0b9e7e28ff17ac86cc77ac265038a96697aff13fad93d70
4
+ data.tar.gz: 86f767e582ed1e7bff70f8db33cd55d2f0bd33f3c9c655cdc30d839be05c1bd7
5
+ SHA512:
6
+ metadata.gz: c8e63fcd2832670605f6702962682227964581c80d5ae3481febb787ce5688d137bb2bbccdd15a9a8f3df386e427a0ec250909c737f3867db90b544c152de16b
7
+ data.tar.gz: 62a5293e1322fa133da9e13df1678eb193d64219943b5d1f44c013701de60b586958260f9798f9ec676ba052cc3a84beddc6c4ebc9f0f93df8c42bf580863ee8
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Style/Documentation:
13
+ Enabled: false
14
+
15
+ Layout/LineLength:
16
+ Max: 120
17
+
18
+ Security/Eval:
19
+ Enabled: false
20
+
21
+ Metrics/MethodLength:
22
+ Max: 16
23
+
24
+ Lint/UnusedMethodArgument:
25
+ Enabled: false
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at admin@eaglenube.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 admin
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,25 @@
1
+ # Eaglenube Aws Synchronizer
2
+
3
+ Introducing this powerful gem, designed to seamlessly sync AWS resources to any Rails application model. Our innovative solution streamlines the process of integrating Amazon Web Services' cloud-based resources into your Ruby on Rails projects. With this gem, you can effortlessly connect AWS services like Vpc, Subnet, SecurityGroup, Snapshots, EC2, or RDS to your application models, enabling efficient data synchronization and management. Whether it's handling file storage, cloud computing, or database operations, this gem simplifies AWS resource integration, saving you time and effort. Say goodbye to complex setup processes and hello to a smoother, more streamlined experience, making AWS integration a breeze for your Rails applications.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add en-aws-synchronizer
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install en-aws-synchronizer
14
+
15
+ ## Contributing
16
+
17
+ Bug reports and pull requests are welcome on GitHub at https://gitlab.com/eaglenube1/en_aws_synchronizer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://gitlab.com/eaglenube1/en_aws_synchronizer/blob/master/CODE_OF_CONDUCT.md).
18
+
19
+ ## License
20
+
21
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
22
+
23
+ ## Code of Conduct
24
+
25
+ Everyone interacting in the EnAwsSynchronizer project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/eaglenube1/en_aws_synchronizer/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/eaglenube/synchronizer/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "en-aws-synchronizer"
7
+ spec.version = Eaglenube::Synchronizer::VERSION
8
+ spec.authors = ["Eaglenube"]
9
+ spec.email = ["admin@eaglenube.com"]
10
+
11
+ spec.summary = "Synchronize your aws resource to your rails model "
12
+ spec.description = "You can sync aws ec2, volume, eip, rds, vpc, subnet, security groups to your aws model quickly with few setup only"
13
+ spec.homepage = "https://gitlab.com/eaglenube1/en_aws_synchronizer"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = "https://gitlab.com/eaglenube1/en_aws_synchronizer"
18
+ spec.metadata["source_code_uri"] = "https://gitlab.com/eaglenube1/en_aws_synchronizer"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (File.expand_path(f) == __FILE__) ||
25
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "aws-sdk-acm", "~> 1"
33
+ spec.add_dependency "aws-sdk-autoscaling", "~> 1"
34
+ spec.add_dependency "aws-sdk-cloudwatch", "~> 1"
35
+ spec.add_dependency "aws-sdk-ec2", "~> 1"
36
+ spec.add_dependency "aws-sdk-ecs", "~> 1"
37
+ spec.add_dependency "aws-sdk-elasticloadbalancing", "~> 1"
38
+ spec.add_dependency "aws-sdk-iam", "~> 1"
39
+ spec.add_dependency "aws-sdk-rds", "~> 1"
40
+ spec.add_dependency "aws-sdk-redshift", "~> 1"
41
+ spec.add_dependency "aws-sdk-route53", "~> 1"
42
+ spec.add_dependency "aws-sdk-s3", "~> 1"
43
+
44
+ # For more information and examples about making a new gem, check out our
45
+ # guide at: https://bundler.io/guides/creating_gem.html
46
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eaglenube
4
+ module AWSAgent
5
+ def get_compute_agent(customer_cred, region_code = "us-east-1")
6
+ Aws::EC2::Client.new(region: region_code, credentials: build_credential(customer_cred))
7
+ end
8
+
9
+ def get_rds_agent(customer_cred, region_code = "us-east-1")
10
+ Aws::RDS::Client.new(region: region_code, credentials: build_credential(customer_cred))
11
+ end
12
+
13
+ def get_elb_agent(customer_cred, region_code = "us-east-1")
14
+ Aws::ElasticLoadBalancing::Client.new(region: region_code, credentials: build_credential(customer_cred))
15
+ end
16
+
17
+ def get_auto_scaling_agent(customer_cred, region_code = "us-east-1")
18
+ Aws::AutoScaling::Client.new(region: region_code, credentials: build_credential(customer_cred))
19
+ end
20
+
21
+ def get_s3_agent(customer_cred, region_code = "us-east-1")
22
+ Aws::S3::Client.new(region: region_code, credentials: build_credential(customer_cred))
23
+ end
24
+
25
+ def get_cloud_watch_agent(customer_cred, region_code = "us-east-1")
26
+ Aws::CloudWatch::Client.new(region: region_code, credentials: build_credential(customer_cred))
27
+ end
28
+
29
+ def get_redshift_agent(customer_cred, region_code = "us-east-1")
30
+ Aws::Redshift::Client.new(region: region_code, credentials: build_credential(customer_cred))
31
+ end
32
+
33
+ def get_kms_agent(customer_cred, region_code = "us-east-1")
34
+ Aws::KMS::Client.new(region: region_code, credentials: build_credential(customer_cred))
35
+ end
36
+
37
+ def get_ecs_agent(customer_cred, region_code = "us-east-1")
38
+ Aws::ECS::Client.new(region: region_code, credentials: build_credential(customer_cred))
39
+ end
40
+
41
+ def get_iam_agent(customer_cred, region_code = "us-east-1")
42
+ Aws::IAM::Client.new(region: region_code, credentials: build_credential(customer_cred))
43
+ end
44
+
45
+ def get_acm_agent(customer_cred, region_code = "us-east-1")
46
+ Aws::ACM::Client.new(region: region_code, credentials: build_credential(customer_cred))
47
+ end
48
+
49
+ def build_credential(credential)
50
+ if credential[:session_token].blank?
51
+ Aws::Credentials.new(credential[:access_key_id], credential[:secret_access_key])
52
+ else
53
+ Aws::Credentials.new(credential[:access_key_id], credential[:secret_access_key], credential[:session_token])
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Eaglenube::CloudObjectMapper::AWS
4
+ # This is the class use for mapping aws resource attributes to model attaribute
5
+ module Eaglenube
6
+ module CloudObjectMapper
7
+ module AWS
8
+ def cloud_obj_mapper_yml(file_path)
9
+ raise StandardError, "#{file_path} not found." unless File.exist?(file_path)
10
+
11
+ @attr_map = begin
12
+ YAML.safe_load(File.open(file_path)).symbolize_keys
13
+ rescue StandardError => e
14
+ puts e.message
15
+ {}
16
+ end
17
+ end
18
+
19
+ def cloud_obj_mapper(**options)
20
+ @attr_map = options
21
+ end
22
+
23
+ def parse_provider_data(obj)
24
+ @attr_map.transform_values { |v| eval v }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "eaglenube/aws_agent"
4
+ require "eaglenube/synchronizer/aws"
5
+ require "eaglenube/cloud_object_mapper/aws"
6
+
7
+ # Eaglenube::Synchronizer::AWS::DbSnapshot
8
+ module Eaglenube
9
+ module Synchronizer
10
+ module AWS
11
+ module DbSnapshot
12
+ def self.included(receiver)
13
+ receiver.extend Eaglenube::Synchronizer::AWS::CommonMethods
14
+ receiver.extend DbSnapshotSyncMethods
15
+ end
16
+
17
+ module DbSnapshotSyncMethods
18
+ include Eaglenube::AWSAgent
19
+ include Eaglenube::CloudObjectMapper::AWS
20
+
21
+ def list_all_remote_db_snapshots(credential, region_code)
22
+ agent = get_rds_agent(credential, region_code)
23
+ agent.describe_db_snapshots({ include_public: false, include_shared: true,
24
+ snapshot_type: "manual" }).try(:db_snapshots)
25
+ end
26
+
27
+ def sync(credential, region_code)
28
+ remote_db_snapshots = list_all_remote_db_snapshots(credential, region_code)
29
+ remote_db_snapshots.each do |remote_db_snapshot|
30
+ object_identifying_attributes, optional_attributes = yield(remote_db_snapshot)
31
+ create_or_update(remote_db_snapshot, object_identifying_attributes, **optional_attributes)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "eaglenube/aws_agent"
4
+ require "eaglenube/synchronizer/aws"
5
+ require "eaglenube/cloud_object_mapper/aws"
6
+
7
+ # Eaglenube::Synchronizer::AWS::ElasticIp
8
+ module Eaglenube
9
+ module Synchronizer
10
+ module AWS
11
+ module ElasticIp
12
+ def self.included(receiver)
13
+ receiver.extend Eaglenube::Synchronizer::AWS::CommonMethods
14
+ receiver.extend EipSyncMethods
15
+ end
16
+
17
+ module EipSyncMethods
18
+ include Eaglenube::AWSAgent
19
+ include Eaglenube::CloudObjectMapper::AWS
20
+
21
+ def list_all_elastic_ips(credential, region_code)
22
+ agent = get_compute_agent(credential, region_code)
23
+ agent.describe_addresses.try(:addresses)
24
+ end
25
+
26
+ def sync(credential, region_code)
27
+ remote_eips = list_all_elastic_ips(credential, region_code)
28
+ remote_eips.each do |remote_eip|
29
+ object_identifying_attributes, optional_attributes = yield(remote_eip)
30
+ create_or_update(remote_eip, object_identifying_attributes, **optional_attributes)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "eaglenube/aws_agent"
4
+ require "eaglenube/cloud_object_mapper/aws"
5
+
6
+ module Eaglenube
7
+ module Synchronizer
8
+ module AWS
9
+ module SecurityGroup
10
+ def self.included(receiver)
11
+ receiver.extend Eaglenube::Synchronizer::AWS::CommonMethods
12
+ receiver.extend SecurityGroupSyncMethods
13
+ end
14
+
15
+ module SecurityGroupSyncMethods
16
+ include Eaglenube::AWSAgent
17
+ include Eaglenube::CloudObjectMapper::AWS
18
+
19
+ def list_all_remote_security_groups(credential, region_code)
20
+ agent = get_compute_agent(credential, region_code)
21
+ agent.describe_security_groups.try(:security_groups)
22
+ end
23
+
24
+ def sync(credential, region_code)
25
+ remote_security_groups = list_all_remote_security_groups(credential, region_code)
26
+ remote_security_groups.each do |remote_security_group|
27
+ object_identifying_attributes, optional_attributes = yield(remote_security_group)
28
+ create_or_update(remote_security_group, object_identifying_attributes, **optional_attributes)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "eaglenube/aws_agent"
4
+ require "eaglenube/synchronizer/aws"
5
+ require "eaglenube/cloud_object_mapper/aws"
6
+
7
+ # Eaglenube::Synchronizer::AWS::Snapshot
8
+ module Eaglenube
9
+ module Synchronizer
10
+ module AWS
11
+ module Snapshot
12
+ def self.included(receiver)
13
+ receiver.extend Eaglenube::Synchronizer::AWS::CommonMethods
14
+ receiver.extend SnapshotSyncMethods
15
+ end
16
+
17
+ module SnapshotSyncMethods
18
+ include Eaglenube::AWSAgent
19
+ include Eaglenube::CloudObjectMapper::AWS
20
+
21
+ def list_all_remote_snapshots(credential, region_code, aws_account_id)
22
+ agent = get_compute_agent(credential, region_code)
23
+ agent.describe_snapshots({ owner_ids: [aws_account_id] }).try(:snapshots)
24
+ end
25
+
26
+ def sync(credential, region_code, aws_account_id)
27
+ remote_snapshots = list_all_remote_snapshots(credential, region_code, aws_account_id)
28
+ remote_snapshots.each do |remote_snapshot|
29
+ object_identifying_attributes, optional_attributes = yield(remote_snapshot)
30
+ create_or_update(remote_snapshot, object_identifying_attributes, **optional_attributes)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "eaglenube/aws_agent"
4
+ require "eaglenube/synchronizer/aws"
5
+ require "eaglenube/cloud_object_mapper/aws"
6
+
7
+ module Eaglenube
8
+ module Synchronizer
9
+ module AWS
10
+ module Subnet
11
+ def self.included(receiver)
12
+ receiver.extend Eaglenube::Synchronizer::AWS::CommonMethods
13
+ receiver.extend SubnetSyncMethods
14
+ end
15
+
16
+ module SubnetSyncMethods
17
+ include Eaglenube::AWSAgent
18
+ include Eaglenube::CloudObjectMapper::AWS
19
+
20
+ def list_all_remote_subnets(credential, region_code)
21
+ agent = get_compute_agent(credential, region_code)
22
+ agent.describe_subnets.try(:subnets)
23
+ end
24
+
25
+ def sync(credential, region_code, &_block)
26
+ remote_subnets = list_all_remote_subnets(credential, region_code)
27
+ remote_subnets.each do |remote_subnet|
28
+ object_identifying_attributes, optional_attributes = yield(remote_subnet)
29
+ create_or_update(remote_subnet, object_identifying_attributes, **optional_attributes)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "eaglenube/aws_agent"
4
+ require "eaglenube/synchronizer/aws"
5
+ require "eaglenube/cloud_object_mapper/aws"
6
+
7
+ # Eaglenube::Synchronizer::AWS::Volume
8
+ module Eaglenube
9
+ module Synchronizer
10
+ module AWS
11
+ module Volume
12
+ def self.included(receiver)
13
+ receiver.extend Eaglenube::Synchronizer::AWS::CommonMethods
14
+ receiver.extend VolumeSyncMethods
15
+ end
16
+
17
+ module VolumeSyncMethods
18
+ include Eaglenube::AWSAgent
19
+ include Eaglenube::CloudObjectMapper::AWS
20
+
21
+ def list_all_remote_volumes(credential, region_code)
22
+ agent = get_compute_agent(credential, region_code)
23
+ agent.describe_volumes.try(:volumes)
24
+ end
25
+
26
+ def sync(credential, region_code, &_block)
27
+ remote_volumes = list_all_remote_volumes(credential, region_code)
28
+ remote_volumes.each do |remote_volume|
29
+ object_identifying_attributes, optional_attributes = yield(remote_volume)
30
+ create_or_update(remote_volume, object_identifying_attributes, **optional_attributes)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "eaglenube/aws_agent"
4
+ require "eaglenube/synchronizer/aws"
5
+ require "eaglenube/cloud_object_mapper/aws"
6
+
7
+ # Eaglenube::Synchronizer::AWS::Vpc
8
+ module Eaglenube
9
+ module Synchronizer
10
+ module AWS
11
+ module Vpc
12
+ def self.included(receiver)
13
+ puts "receiver module name: #{receiver}"
14
+ # module_name = Eaglenube::Synchronizer.config.find_sync_module(receiver)
15
+ # puts "module name to extend: #{module_name}"
16
+ # receiver.extend module_name if defined?(receiver)
17
+ receiver.extend Eaglenube::Synchronizer::AWS::CommonMethods
18
+ receiver.extend VpcSyncMethods
19
+ end
20
+
21
+ module VpcSyncMethods
22
+ include Eaglenube::AWSAgent
23
+ include Eaglenube::CloudObjectMapper::AWS
24
+
25
+ def list_all_remote_vpcs(credential, region_code)
26
+ agent = get_compute_agent(credential, region_code)
27
+ agent.describe_vpcs.try(:vpcs)
28
+ end
29
+
30
+ def list_all_remote_igs(credential, region_code)
31
+ agent = get_compute_agent(credential, region_code)
32
+ agent.describe_internet_gateways.try(:internet_gateways)
33
+ end
34
+
35
+ def sync(credential, region_code)
36
+ remote_vpcs = list_all_remote_vpcs(credential, region_code)
37
+ describe_vpc_attribute_permisssion_error = false
38
+ remote_vpcs.each do |remote_vpc|
39
+ object_identifying_attributes, optional_attributes = yield(remote_vpc)
40
+
41
+ dns_support = false
42
+ dns_hostname = false
43
+ unless describe_vpc_attribute_permisssion_error
44
+ begin
45
+ dns_support, dns_hostname = sync_addtional_attributes(credential, region_code, remote_vpc.vpc_id)
46
+ rescue Aws::EC2::Errors::UnauthorizedOperation
47
+ describe_vpc_attribute_permisssion_error = true
48
+ end
49
+ end
50
+ optional_attributes.merge({ dns_support: dns_support, dns_hostname: dns_hostname })
51
+
52
+ create_or_update(remote_vpc, object_identifying_attributes, **optional_attributes)
53
+ end
54
+ end
55
+
56
+ def sync_addtional_attributes(credential, region_code, vpc_id)
57
+ agent = get_compute_agent(credential, region_code)
58
+ dns_support_attrs = { vpc_id: vpc_id, attribute: "enableDnsSupport" }
59
+ dns_support = agent.describe_vpc_attribute(dns_support_attrs).try(:enable_dns_support).try(:value)
60
+ dns_hostname_attrs = { vpc_id: vpc_id, attribute: "enableDnsHostnames" }
61
+ dns_hostname = agent.describe_vpc_attribute(dns_hostname_attrs).try(:enable_dns_hostnames).try(:value)
62
+ [dns_support, dns_hostname]
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eaglenube
4
+ module Synchronizer
5
+ module AWS
6
+ module CommonMethods
7
+ def create_or_update(provider_vpc, object_identifying_attributes, **optional_params)
8
+ unless optional_params.is_a?(Hash)
9
+ raise Eaglenube::Synchronizer::Error, "Expecting common_params to be hash type"
10
+ end
11
+
12
+ db_object = find_by(object_identifying_attributes) || new(object_identifying_attributes)
13
+ attributes = parse_provider_data(provider_vpc)
14
+ attributes.merge(optional_params || {}).each { |k, v| db_object.send("#{k}=", v) }
15
+ puts "Error in saving db_object: #{db_object.errors.to_a}" unless db_object.save
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "eaglenube/synchronizer/error"
4
+
5
+ # This is not in use. Will use later if required
6
+ module Eaglenube
7
+ module Synchronizer
8
+ class CloudModelConfig
9
+ attr_accessor :vpc, :subnet, :security_group, :s3, :ec2, :volume, :rds, :loadbalancer, :auto_scaling, :kms_key
10
+
11
+ def initialize
12
+ @vpc = "Vpc"
13
+ @subnet = "Subnet"
14
+ @security_group = "SecurityGroup"
15
+ @s3 = "S3"
16
+ @ec2 = "Ec2"
17
+ @rds = "Rds"
18
+ @loadbalancer = "Loadbalancer"
19
+ @auto_scaling = "AutoScaling"
20
+ @kms_key = "KmsKey"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "eaglenube/synchronizer/cloud_model_config"
4
+
5
+ # Class use for getting configuration from parent app to gem
6
+ module Eaglenube
7
+ module Synchronizer
8
+ class Configuration
9
+ attr_accessor :option1, :option2, :model_config
10
+
11
+ def initialize
12
+ @option1 = "default_value_1"
13
+ @option2 = "default_value_2"
14
+ end
15
+
16
+ # def configure_cloud_model
17
+ # self.model_config ||= CloudModelConfig.new
18
+ # yield(model_config)
19
+ # end
20
+
21
+ # # def find_sync_module(receiver)
22
+ # # var_name = search_match_variable_for_receiver_model(receiver.to_s)
23
+ # # raise Eaglenube::Synchronizer::Error.new("#{receiver.to_s} not mapped to any aws resource") if var_name.nil?
24
+ # # "Eaglenube::Synchronizer::AWS::#{var_name.to_s.gsub("@", "").classify}".constantize
25
+ # # end
26
+
27
+ # # def search_match_variable_for_receiver_model(value)
28
+ # # instance_var = nil
29
+ # # @model_config.instance_variables.each do |var_name|
30
+ # # instance_variable_value = @model_config.instance_variable_get(var_name)
31
+ # # if instance_variable_value == value
32
+ # # # puts "Match found in #{var_name}: #{instance_variable_value}"
33
+ # # instance_var = var_name
34
+ # # end
35
+ # # end
36
+ # # instance_var
37
+ # # end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eaglenube
4
+ module Synchronizer
5
+ class Error < StandardError; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eaglenube
4
+ module Synchronizer
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "eaglenube/synchronizer/configuration"
4
+ require "eaglenube/synchronizer/aws/subnet"
5
+
6
+ module Eaglenube
7
+ module Synchronizer
8
+ class << self
9
+ attr_accessor :config
10
+
11
+ def configure
12
+ self.config ||= Configuration.new
13
+ yield(config)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "eaglenube/cloud_object_mapper/aws"
4
+
5
+ require "eaglenube/synchronizer/aws"
6
+
7
+ require "eaglenube/synchronizer"
@@ -0,0 +1,4 @@
1
+ module EnAwsSynchronizer
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,224 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: en-aws-synchronizer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eaglenube
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-09-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-acm
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk-autoscaling
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk-cloudwatch
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aws-sdk-ec2
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aws-sdk-ecs
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: aws-sdk-elasticloadbalancing
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: aws-sdk-iam
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: aws-sdk-rds
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1'
125
+ - !ruby/object:Gem::Dependency
126
+ name: aws-sdk-redshift
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1'
139
+ - !ruby/object:Gem::Dependency
140
+ name: aws-sdk-route53
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1'
153
+ - !ruby/object:Gem::Dependency
154
+ name: aws-sdk-s3
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1'
167
+ description: You can sync aws ec2, volume, eip, rds, vpc, subnet, security groups
168
+ to your aws model quickly with few setup only
169
+ email:
170
+ - admin@eaglenube.com
171
+ executables: []
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - ".rspec"
176
+ - ".rubocop.yml"
177
+ - CODE_OF_CONDUCT.md
178
+ - LICENSE.txt
179
+ - README.md
180
+ - Rakefile
181
+ - en_aws_synchronizer.gemspec
182
+ - lib/eaglenube/aws_agent.rb
183
+ - lib/eaglenube/cloud_object_mapper/aws.rb
184
+ - lib/eaglenube/synchronizer.rb
185
+ - lib/eaglenube/synchronizer/aws.rb
186
+ - lib/eaglenube/synchronizer/aws/db_snapshot.rb
187
+ - lib/eaglenube/synchronizer/aws/elastic_ip.rb
188
+ - lib/eaglenube/synchronizer/aws/security_group.rb
189
+ - lib/eaglenube/synchronizer/aws/snapshot.rb
190
+ - lib/eaglenube/synchronizer/aws/subnet.rb
191
+ - lib/eaglenube/synchronizer/aws/volume.rb
192
+ - lib/eaglenube/synchronizer/aws/vpc.rb
193
+ - lib/eaglenube/synchronizer/cloud_model_config.rb
194
+ - lib/eaglenube/synchronizer/configuration.rb
195
+ - lib/eaglenube/synchronizer/error.rb
196
+ - lib/eaglenube/synchronizer/version.rb
197
+ - lib/en_aws_synchronizer.rb
198
+ - sig/en_aws_synchronizer.rbs
199
+ homepage: https://gitlab.com/eaglenube1/en_aws_synchronizer
200
+ licenses:
201
+ - MIT
202
+ metadata:
203
+ homepage_uri: https://gitlab.com/eaglenube1/en_aws_synchronizer
204
+ source_code_uri: https://gitlab.com/eaglenube1/en_aws_synchronizer
205
+ post_install_message:
206
+ rdoc_options: []
207
+ require_paths:
208
+ - lib
209
+ required_ruby_version: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: 2.6.0
214
+ required_rubygems_version: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - ">="
217
+ - !ruby/object:Gem::Version
218
+ version: '0'
219
+ requirements: []
220
+ rubygems_version: 3.4.19
221
+ signing_key:
222
+ specification_version: 4
223
+ summary: Synchronize your aws resource to your rails model
224
+ test_files: []