Skip to content

Commit

Permalink
Add codepipeline resource
Browse files Browse the repository at this point in the history
  • Loading branch information
alpineriveredge committed May 31, 2024
1 parent 2d71e7d commit 6082b18
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 5 deletions.
6 changes: 6 additions & 0 deletions doc/_resource_types/codedeploy.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
### exist

```ruby
describe codedeploy('my-codedeploy') do
it { should exist }
end
```
7 changes: 7 additions & 0 deletions doc/_resource_types/codepipeline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### exist

```ruby
describe codepipeline('my-codepipeline') do
it { should exist }
end
```
22 changes: 21 additions & 1 deletion doc/resource_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
| [codebuild](#codebuild)
| [codedeploy](#codedeploy)
| [codedeploy_deployment_group](#codedeploy_deployment_group)
| [codepipeline](#codepipeline)
| [cognito_identity_pool](#cognito_identity_pool)
| [cognito_user_pool](#cognito_user_pool)
| [customer_gateway](#customer_gateway)
Expand Down Expand Up @@ -759,6 +760,12 @@ Codedeploy resource type.

### exist

```ruby
describe codedeploy('my-codedeploy') do
it { should exist }
end
```

### its(:application_id), its(:application_name), its(:create_time), its(:linked_to_git_hub), its(:git_hub_account_name), its(:compute_platform)
## <a name="codedeploy_deployment_group">codedeploy_deployment_group</a>

Expand All @@ -784,6 +791,19 @@ end
```

### its(:application_name), its(:deployment_group_id), its(:deployment_group_name), its(:deployment_config_name), its(:on_premises_instance_tag_filters), its(:service_role_arn), its(:target_revision), its(:trigger_configurations), its(:alarm_configuration), its(:deployment_style), its(:outdated_instances_strategy), its(:load_balancer_info), its(:last_successful_deployment), its(:last_attempted_deployment), its(:ec2_tag_set), its(:on_premises_tag_set), its(:compute_platform), its(:ecs_services), its(:termination_hook_enabled)
## <a name="codepipeline">codepipeline</a>

Codepipeline resource type.

### exist

```ruby
describe codepipeline('my-codepipeline') do
it { should exist }
end
```

### its(:name), its(:role_arn), its(:artifact_stores), its(:version), its(:execution_mode), its(:pipeline_type), its(:variables), its(:triggers)
## <a name="cognito_identity_pool">cognito_identity_pool</a>

CognitoIdentityPool resource type.
Expand Down Expand Up @@ -839,7 +859,7 @@ end
```


### its(:bgp_asn), its(:customer_gateway_id), its(:ip_address), its(:certificate_arn), its(:state), its(:type), its(:device_name), its(:tags)
### its(:bgp_asn), its(:customer_gateway_id), its(:ip_address), its(:certificate_arn), its(:state), its(:type), its(:device_name), its(:tags), its(:bgp_asn_extended)
## <a name="directconnect_virtual_interface">directconnect_virtual_interface</a>

DirectconnectVirtualInterface resource type.
Expand Down
1 change: 1 addition & 0 deletions lib/awspec/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
require 'awspec/generator/spec/rds_db_cluster'
require 'awspec/generator/spec/rds_global_cluster'
require 'awspec/generator/spec/managed_prefix_list'
require 'awspec/generator/spec/codepipeline'

# Doc
require 'awspec/generator/doc/type'
Expand Down
19 changes: 19 additions & 0 deletions lib/awspec/generator/doc/type/codepipeline.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Awspec::Generator
module Doc
module Type
class Codepipeline < Base
def initialize
super
@type_name = 'Codepipeline'
@type = Awspec::Type::Codepipeline.new('my-codepipeline')
@ret = @type.resource_via_client
@matchers = []
@ignore_matchers = []
@describes = []
end
end
end
end
end
29 changes: 29 additions & 0 deletions lib/awspec/generator/spec/codepipeline.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module Awspec::Generator
module Spec
class Codepipeline
include Awspec::Helper::Finder
def generate_all
pipelines = select_all_codepipelines
raise 'Not Found CodePipeline' if pipelines.empty?

ERB.new(codepipeline_spec_template, nil, '-').result(binding).chomp
end

def codepipeline_spec_template
<<-'EOF'
<% pipelines.each do |pipeline| %>
describe codepipeline('<%= pipeline.name %>') do
it { should exist }
its(:name) { should eq '<%= pipeline.name %>' }
its(:version) { should eq <%= pipeline.version %> }
its(:pipeline_type) { should eq '<%= pipeline.pipeline_type %>' }
its(:execution_mode) { should eq '<%= pipeline.execution_mode %>' }
end
<% end %>
EOF
end
end
end
end
5 changes: 4 additions & 1 deletion lib/awspec/helper/finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
require 'awspec/helper/finder/msk'
require 'awspec/helper/finder/cognito_identity_pool'
require 'awspec/helper/finder/transfer'
require 'awspec/helper/finder/codepipeline'

require 'awspec/helper/finder/account_attributes'

Expand Down Expand Up @@ -117,6 +118,7 @@ module Finder
include Awspec::Helper::Finder::Msk
include Awspec::Helper::Finder::CognitoIdentityPool
include Awspec::Helper::Finder::Transfer
include Awspec::Helper::Finder::Codepipeline

CLIENTS = {
ec2_client: Aws::EC2::Client,
Expand Down Expand Up @@ -165,7 +167,8 @@ module Finder
msk_client: Aws::Kafka::Client,
cognito_identity_client: Aws::CognitoIdentity::Client,
cognito_identity_provider_client: Aws::CognitoIdentityProvider::Client,
transfer_client: Aws::Transfer::Client
transfer_client: Aws::Transfer::Client,
codepipeline_client: Aws::CodePipeline::Client
}

CLIENT_OPTIONS = {
Expand Down
25 changes: 25 additions & 0 deletions lib/awspec/helper/finder/codepipeline.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Awspec::Helper
module Finder
module Codepipeline
def find_codepipeline(id)
res = codepipeline_client.get_pipeline({ name: id })
res.pipeline
end

def select_all_codepipelines
req = {}
pipelines = []
loop do
res = codepipeline_client.list_pipelines(req)
pipelines.push(*res.pipelines)
break if res.next_token.nil?

req[:next_token] = res.next_token
end
pipelines
end
end
end
end
2 changes: 1 addition & 1 deletion lib/awspec/helper/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Type
internet_gateway acm cloudwatch_logs dynamodb_table eip sqs ssm_parameter cloudformation_stack
codebuild sns_topic redshift redshift_cluster_parameter_group codedeploy codedeploy_deployment_group
secretsmanager msk transit_gateway cognito_identity_pool cognito_user_pool vpc_endpoints
transfer_server managed_prefix_list
transfer_server managed_prefix_list codepipeline
]

ACCOUNT_ATTRIBUTES = %w[
Expand Down
2 changes: 0 additions & 2 deletions lib/awspec/stub/cloudfront_distribution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
status: 'Deployed',
last_modified_time: Time.new(2015, 1, 2, 10, 00, 00, '+00:00'),
domain_name: 'abcdefghijklmn.cloudfront.net',
staging: false,
aliases: {
quantity: 0,
items: []
Expand Down Expand Up @@ -117,7 +116,6 @@
status: 'Deployed',
last_modified_time: Time.new(2016, 3, 2, 10, 00, 00, '+00:00'),
domain_name: '123456789zyxw.cloudfront.net',
staging: false,
aliases: {
quantity: 1,
items: ['cf-s3-origin-hosting.dev.example.com']
Expand Down
104 changes: 104 additions & 0 deletions lib/awspec/stub/codepipeline.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# frozen_string_literal: true

Aws.config[:codepipeline] = {
stub_responses: {
get_pipeline: {
pipeline: {
name: 'my-codepipeline',
role_arn: 'arn:aws:iam::123456789012:role/service-role/AWSCodePipelineServiceRole-my-codepipeline',
artifact_store: {
type: 'S3',
location: 'codepipeline-ap-northeast-1-12345678901'
},
stages: [
{
name: 'Source',
actions: [
{
name: 'Source',
action_type_id: {
category: 'Source',
owner: 'AWS',
provider: 'S3',
version: '1'
},
run_order: 1,
configuration: {
'PollForSourceChanges' => 'false',
'S3Bucket' => 'example-bucket',
'S3ObjectKey' => 'test.zip'
},
output_artifacts: [
{
name: 'SourceArtifact'
}
],
input_artifacts: [],
region: 'ap-northeast-1',
namespace: 'SourceVariables'
}
]
},
{
name: 'Build',
actions: [
{
name: 'Build',
action_type_id: {
category: 'Build',
owner: 'AWS',
provider: 'CodeBuild',
version: '1'
},
run_order: 1,
configuration: {
'ProjectName' => 'my-codebuild1'
},
output_artifacts: [
{
name: 'BuildArtifact'
}
],
input_artifacts: [
{
name: 'SourceArtifact'
}
],
region: 'ap-northeast-1',
namespace: 'BuildVariables'
}
]
}
],
version: 1,
execution_mode: 'QUEUED',
pipeline_type: 'V2'
},
metadata: {
pipeline_arn: 'arn:aws:codepipeline:ap-northeast-1:123456789012:my-codepipeline',
created: Time.local(2024),
updated: Time.local(2024)
}
},
list_pipelines: {
pipelines: [
{
name: 'my-codepipeline1',
version: 1,
pipeline_type: 'V2',
execution_mode: 'QUEUED',
created: Time.local(2024),
updated: Time.local(2024)
},
{
name: 'my-codepipeline2',
version: 1,
pipeline_type: 'V2',
execution_mode: 'QUEUED',
created: Time.local(2024),
updated: Time.local(2024)
}
]
}
}
}
13 changes: 13 additions & 0 deletions lib/awspec/type/codepipeline.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Awspec::Type
class Codepipeline < ResourceBase
def resource_via_client
@resource_via_client ||= find_codepipeline(@display_name)
end

def id
@id ||= resource_via_client if resource_via_client.name
end
end
end
31 changes: 31 additions & 0 deletions spec/generator/spec/codepipeline_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'Awspec::Generator::Spec::Codepipeline' do
before do
Awspec::Stub.load 'codepipeline'
end
let(:codepipeline) { Awspec::Generator::Spec::Codepipeline.new }
it 'generate_all generate spec' do
spec = <<-'EOF'
describe codepipeline('my-codepipeline1') do
it { should exist }
its(:name) { should eq 'my-codepipeline1' }
its(:version) { should eq 1 }
its(:pipeline_type) { should eq 'V2' }
its(:execution_mode) { should eq 'QUEUED' }
end
describe codepipeline('my-codepipeline2') do
it { should exist }
its(:name) { should eq 'my-codepipeline2' }
its(:version) { should eq 1 }
its(:pipeline_type) { should eq 'V2' }
its(:execution_mode) { should eq 'QUEUED' }
end
EOF
expect(codepipeline.generate_all.to_s.gsub(/\n/, "\n")).to eq spec
end
end
15 changes: 15 additions & 0 deletions spec/type/codepipeline_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require 'spec_helper'
Awspec::Stub.load 'codepipeline'

describe codepipeline('my-codepipeline') do
it { should exist }
its(:name) { should eq 'my-codepipeline' }
its(:role_arn) { should eq 'arn:aws:iam::123456789012:role/service-role/AWSCodePipelineServiceRole-my-codepipeline' }
its('artifact_store.type') { should eq 'S3' }
its('artifact_store.location') { should eq 'codepipeline-ap-northeast-1-12345678901' }
its(:version) { should eq 1 }
its(:execution_mode) { should eq 'QUEUED' }
its(:pipeline_type) { should eq 'V2' }
end

0 comments on commit 6082b18

Please sign in to comment.