Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ab0559d
refactor gem names, locations, boot process
rjayroach Jan 24, 2022
e403512
refactor S-R/S-S; add docs and specs
rjayroach Jan 31, 2022
92b3a15
refactor framework boot process
rjayroach Jan 31, 2022
bd5ca56
update for persisted records
rjayroach Feb 6, 2022
99703e5
refactor
rjayroach Feb 25, 2022
b5ef555
path creates paths for dirs rather than documents
rjayroach Feb 25, 2022
c47de69
encapsulate LoadPath; add sandbox functionality
rjayroach Mar 8, 2022
671a401
pull app config into SolidRecord
rjayroach Mar 9, 2022
b4f8771
pull app config into SolidRecord
rjayroach Mar 11, 2022
3b58cec
use absolute path; fix encryption bug; all values in config hash
rjayroach Mar 12, 2022
5753296
create solid_view gem
rjayroach Mar 13, 2022
2563b0c
renaming and remove cruft
rjayroach Mar 13, 2022
f62764e
encapsulate navigation and context to a dedicated class
rjayroach Mar 15, 2022
82b3ab9
namepspaces refactor
rjayroach Mar 15, 2022
c533f4c
moving files and renaming modules
rjayroach Mar 16, 2022
a760c7a
moving files and renaming modules
rjayroach Mar 16, 2022
d298be9
refactoring file locations
rjayroach Mar 16, 2022
dd3f2ab
framework classes moved from hendrix to solid_support
rjayroach Mar 17, 2022
8064b48
refactor navigator/cli
rjayroach Mar 18, 2022
37976ea
solid_view -> solid_app
rjayroach Mar 18, 2022
a17d268
cosmetic updates
rjayroach Sep 14, 2022
69a7a6e
syntax fixes
rjayroach Jan 13, 2023
95b5a92
implement config.load_paths
rjayroach Jan 30, 2023
dee77d4
refactor classes to path/dir/file/element hierarchy
rjayroach Feb 14, 2023
a7d2412
refactor specs
rjayroach Feb 16, 2023
89dd022
remove duplication
rjayroach Feb 18, 2023
0c149d9
add spec helpers; remove pathname classify methods
rjayroach Feb 18, 2023
62510d7
cleanup
rjayroach Feb 18, 2023
4fb5da6
all the stuff
rjayroach Mar 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 21 additions & 0 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: rubocop

on:
push:
pull_request:

jobs:
build:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.0
- name: Install gems
run: bundle install --jobs 4 --retry 3
- name: Run RuboCop
run: bundle exec rubocop --parallel
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
**/src/
**.env

# Remove after completing refactor
**/spec/dummy/segments/
one_stack_rails/
native

.dir-locals.el

# rspec failure tracking
Expand Down
33 changes: 21 additions & 12 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
---
require:
- rubocop-rspec
- rubocop-performance
inherit_from:
- .rubocop_todo.yml
AllCops:
NewCops: enable
TargetRubyVersion: 3.0.0
Naming/FileName:
Exclude:
- '*/lib/onestack-*.rb'
Layout/LineLength:
Max: 120
Layout/SpaceAroundMethodCallOperator:
Expand All @@ -19,21 +28,21 @@ Metrics/CyclomaticComplexity:
Exclude:
- cli/app/helpers/*
Metrics/BlockLength:
IgnoredMethods:
- describe
- context
- shared_examples
- it
- xit
- xdescribe
# IgnoredMethods:
# - describe
# - context
# - shared_examples
# - it
# - xit
# - xdescribe
Exclude:
- '*/spec/**/*.rb'
- '*/*.gemspec'
Metrics/MethodLength:
Exclude:
- cli/app/helpers/*
IgnoredMethods:
- create_table
# Metrics/MethodLength:
# Exclude:
# - cli/app/helpers/*
# IgnoredMethods:
# - create_table
Metrics/PerceivedComplexity:
Exclude:
- cli/app/helpers/*
Expand Down
6 changes: 6 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
Gemspec/RequireMFA:
Enabled: false
Style/NestedTernaryOperator:
Exclude:
- '*/spec/dummy/config/application.rb'
4 changes: 4 additions & 0 deletions aws/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
inherit_from:
- ../.rubocop.yml
- .rubocop_todo.yml
4 changes: 4 additions & 0 deletions aws/.rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
Style/MissingRespondToMissing:
Exclude:
- app/models/aws/resource/ec2/instance.rb
10 changes: 10 additions & 0 deletions aws/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'onestack', path: '../onestack'
gem 'solid_app', path: '../solid_app'
gem 'solid_record', path: '../solid_record'
gem 'solid_support', path: '../solid_support'

gemspec
15 changes: 6 additions & 9 deletions aws/app/models/aws/provider.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Aws
class Provider < Provider
class Provider < OneStack::Provider
# standard credentials for aws
store :config, accessors: %i[account_id access_key_id secret_access_key region]

Expand All @@ -15,11 +15,9 @@ def client_config(resource_type)
end

def regions
begin
client.describe_regions[0].map { |r| r.region_name }.sort
rescue EC2::Errors::AuthFailure => e
raise Cnfs::Error, e.message
end
client.describe_regions[0].map(&:region_name).sort
rescue EC2::Errors::AuthFailure => e
raise OneStack::Error, e.message
end

def client() = @client ||= Resource::EC2::Instance.client(self)
Expand All @@ -29,7 +27,7 @@ def client() = @client ||= Resource::EC2::Instance.client(self)

def source() = super || 'hashicorp/aws'

def as_terraform
def as_terraform # rubocop:disable Metrics/MethodLength
{
terraform: {
required_providers: {
Expand All @@ -48,7 +46,6 @@ def as_terraform
end

# Pulumi Provisioner
def as_pulumi
end
def as_pulumi; end
end
end
9 changes: 4 additions & 5 deletions aws/app/models/aws/resource.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

class Aws::Resource < Resource

class Aws::Resource < OneStack::Resource
def client() = @client ||= self.class.client(provider)

def valid_types() = super.merge(provider: 'Aws::Provider')
Expand All @@ -10,12 +9,12 @@ class << self
def client(provider)
require "aws-sdk-#{service_name}"
klass = "Aws::#{service_class_name}::Client".safe_constantize
raise Cnfs::Error, "AWS SDK client class not found for: #{service_name}" unless klass
raise OneStack::Error, "AWS SDK client class not found for: #{service_name}" unless klass

config = client_config(provider)
klass.new(config)
rescue LoadError => e
raise Cnfs::Error, "AWS SDK not found for: #{service_name}"
rescue LoadError => _e
raise OneStack::Error, "AWS SDK not found for: #{service_name}"
end

def client_config(provider) = provider.client_config(service_name)
Expand Down
10 changes: 5 additions & 5 deletions aws/app/models/aws/resource/ec2.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# frozen_string_literal: true

class Aws::Resource::EC2 < Aws::Resource
def instance_types(family)
instance_type_offerings.select do |offer|
offer.split('.').first.eql?(family.to_s)
end.map { |offer| offer.split('.').last }.sort
def instance_types(family) = instance_types_list(family).map { |offer| offer.split('.').last }.sort

def instance_types_list(family)
instance_type_offerings.select { |offer| offer.split('.').first.eql?(family.to_s) }
end

def offers_by_family
@offers_by_family ||= instance_type_offerings.map { |offer| offer.split('.').first }.uniq.sort
end

def instance_type_offerings
@instance_type_offerings ||= client.describe_instance_type_offerings[0].map { |offer| offer.instance_type }
@instance_type_offerings ||= client.describe_instance_type_offerings[0].map(&:instance_type)
end

def describe_images(owners:, filters:)
Expand Down
6 changes: 3 additions & 3 deletions aws/app/models/aws/resource/ec2/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

class Aws::Resource::EC2::Instance < Aws::Resource::EC2
# store :config, accessors: %i[family size instance_count ami key_name monitoring
# vpc_security_group_ids subnet_id subnet_ids]
# vpc_security_group_ids subnet_id subnet_ids]
# store :config, accessors: %i[public_ip os_type arn]
# store :envs, accessors: %i[public_ip os_type arn]

belongs_to :runtime, optional: true

def instance_id() = config[:id]

def valid_types() = super.merge(runtime: %w[Compose::Runtime Skaffold::Runtime])
def valid_types() = super.merge(runtime: %w[Compose::Runtime Skaffold::Runtime])

def describe() = @describe ||= describe_instances(instance_id).reservations.first.instances.first

Expand All @@ -35,5 +35,5 @@ def ssh_user_map
}.with_indifferent_access
end

def method_missing(method, *args) = config[method]
def method_missing(method, *_args) = config[method]
end
6 changes: 2 additions & 4 deletions aws/app/models/aws/resource/ec2/vpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Aws::Resource::EC2::Vpc < Aws::Resource::EC2
store :config, accessors: %i[azs cidr enable_nat_gateway
enable_vpn_gateway private_subnets public_subnets], coder: YAML
enable_vpn_gateway private_subnets public_subnets], coder: YAML

def source
super || 'terraform-aws-modules/vpc/aws'
Expand All @@ -12,7 +12,5 @@ def version
super || '~> 2.64.0'
end

def available_azs
@azs ||= client.describe_availability_zones[0].map { |z| z.zone_name }
end
def available_azs() = @available_azs ||= client.describe_availability_zones[0].map(&:zone_name)
end
12 changes: 5 additions & 7 deletions aws/app/models/aws/resource/eks/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ def kubectl_context(target)
"arn:aws:eks:#{region}:#{account_id}:cluster/#{target.cluster_name.cnfs_sub}"
end

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
# NOTE: This will work with a cluster on any target since the provider instance, ie credentials, is per target
def init_cluster(target, options)
credentials_file = "#{Dir.home}/.aws/credentials"

unless File.exist?(credentials_file) || ENV['AWS_ACCESS_KEY_ID']
STDOUT.puts "missing #{credentials_file}"
$stdout.puts "missing #{credentials_file}"
return
end

Expand All @@ -31,10 +30,9 @@ def init_cluster(target, options)
if options.long || target.role_name
cmd_string = "#{cmd_string} --role-arn arn:aws:iam::#{account_id}:role/#{target.role_name}"
end
binding.pry
# binding.pry
cmd_string
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength

# def client
Expand All @@ -48,14 +46,14 @@ def init_cluster(target, options)

# class Target::Kubernetes < Target
# store :config, accessors: %i[role_name cluster_name], coder: YAML
#
#
# validates :role_name, presence: true
# validates :cluster_name, presence: true
#
#
# def role_name
# super.cnfs_sub
# end
#
#
# def init(options)
# provider.init_cluster(self, options)
# end
Expand Down
7 changes: 4 additions & 3 deletions aws/app/models/aws/resource/rds.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# See: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/RDS/Client.html

class Aws::Resource::RDS < Aws::Resource
Expand All @@ -9,9 +10,9 @@ def instance_types(family)
def offers_by_family
@offers_by_family ||= reserved_db_instances_offerings.map { |offer| offer[0...offer.rindex('.')] }.uniq.sort
end

def reserved_db_instances_offerings
@reserved_db_instances_offerings ||= client.describe_reserved_db_instances_offerings.
reserved_db_instances_offerings.map { |offer| offer.db_instance_class }
@reserved_db_instances_offerings ||= client.describe_reserved_db_instances_offerings
.reserved_db_instances_offerings.map(&:db_instance_class)
end
end
15 changes: 5 additions & 10 deletions aws/app/models/aws/resource/redshift.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# frozen_string_literal: true

# See: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Redshift/Client.html

class Aws::Resource::Redshift < Aws::Resource
def instance_types(family)
@types ||= offers.select { |offer| offer.start_with?(_family) }.sort
end
def instance_types(family) = @instance_types ||= offers.select { |offer| offer.start_with?(family) }.sort

def offers_by_family() = @offers_by_family ||= offers.map { |offer| offer.split('.').shift }.uniq.sort

def offers_by_family
@offers_by_family ||= offers.map { |offer| offer.split('.').shift }.uniq.sort
end

def offers
@offers ||= client.describe_reserved_node_offerings.reserved_node_offerings.map { |offer| offer.node_type }
end
def offers = @offers ||= client.describe_reserved_node_offerings.reserved_node_offerings.map(&:node_type)
end
14 changes: 6 additions & 8 deletions aws/app/views/aws/plan_view.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# frozen_string_literal: true

class Aws::PlanView < ApplicationView

class Aws::PlanView < OneStack::ApplicationView
def create
# model.name = ask('Blueprint name:', value: random_string('instance'))
binding.pry
# binding.pry
p_ask(:name)
provider_name = enum_select('Provider:', Provider.where(type: 'Provider::Aws').pluck(:name))
model.provider = Provider.find_by(name: provider_name)
provider_name = enum_select('Provider:', OneStack::Provider.where(type: 'Provider::Aws').pluck(:name))
model.provider = OneStack::Provider.find_by(name: provider_name)
# TODO: These two will become configurable
model.builder = Builder.find_by(name: 'terraform')
model.runtime = Runtime.find_by(name: 'compose')
model.builder = OneStack::Builder.find_by(name: 'terraform')
model.runtime = OneStack::Runtime.find_by(name: 'compose')
end
end

2 changes: 1 addition & 1 deletion aws/app/views/aws/provider_view.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Aws::ProviderView < ProviderView
class Aws::ProviderView < OneStack::ProviderView
def modify
super
mask_attr(:access_key_id)
Expand Down
2 changes: 1 addition & 1 deletion aws/app/views/aws/resource/acm/certificate_view.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true

class Aws::Resource::ACM::CertificateView < ResourceView
class Aws::Resource::ACM::CertificateView < OneStack::ResourceView
end
8 changes: 4 additions & 4 deletions aws/app/views/aws/resource/ec2/instance_view.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

class Aws::Resource::EC2::InstanceView < ResourceView
def edit
class Aws::Resource::EC2::InstanceView < OneStack::ResourceView
def edit # rubocop:disable Metrics/AbcSize
model.family = view_select(:instance_family, model.offers_by_family, model.family)
instance_types = model.instance_types(model.family)
model.size = view_select(:instance_type, instance_types, model.size)

model.name ||= ask('Instance name:', value: random_string(blueprint.name))
model.key_name = ask('Key pair:', value: model.key_name || '')
os = enum_select('OS', os_values.keys)
model.ami = os_images(os).sort_by{ |image| image.creation_date }.reverse.first.image_id
model.ami = os_images(os).max_by(&:creation_date).image_id
model.instance_count = ask('Instance count:', value: model.instance_count.to_s, convert: :integer)
end

Expand All @@ -22,7 +22,7 @@ def os_images(os)
def os_values
{
debian: { owner: '136693071363', name: 'debian-10-amd64-*' },
ubuntu: { owner: '099720109477', name: 'ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*' },
ubuntu: { owner: '099720109477', name: 'ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*' }
}.with_indifferent_access
end
end
Loading