From 2d1aafd549c483c956dea96a0b3aa2fc70683a86 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Tue, 12 May 2015 14:07:08 -0500 Subject: [PATCH] contrib: aws api coverage report script quick 'n' dirty - might have some bugs, but it'll get us started --- contrib/api-coverage/aws_api_coverage.rb | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 contrib/api-coverage/aws_api_coverage.rb diff --git a/contrib/api-coverage/aws_api_coverage.rb b/contrib/api-coverage/aws_api_coverage.rb new file mode 100644 index 000000000..2d84b2656 --- /dev/null +++ b/contrib/api-coverage/aws_api_coverage.rb @@ -0,0 +1,49 @@ +# +# This script generates CSV output reporting on the API Coverage of Terraform's +# AWS Provider. +# +# In addition to Ruby, it depends on a properly configured Go development +# environment with both terraform and aws-sdk-go present. +# + +require 'csv' +require 'json' +require 'pathname' + +module APIs + module Terraform + def self.path + @path ||= Pathname(`go list -f '{{.Dir}}' github.com/hashicorp/terraform`.chomp) + end + + def self.called?(api, op) + `git -C "#{path}" grep "#{api}.*#{op}" -- builtin/providers/aws | wc -l`.chomp.to_i > 0 + end + end + + module AWS + def self.path + @path ||= Pathname(`go list -f '{{.Dir}}' github.com/awslabs/aws-sdk-go/aws`.chomp).parent + end + + def self.api_json_files + Pathname.glob(path.join('**', '*.normal.json')) + end + + def self.each + api_json_files.each do |api_json_file| + json = JSON.parse(api_json_file.read) + api = api_json_file.dirname.basename + json["operations"].keys.each do |op| + yield api, op + end + end + end + end +end + +csv = CSV.new($stdout) +csv << ["API", "Operation", "Called in Terraform?"] +APIs::AWS.each do |api, op| + csv << [api, op, APIs::Terraform.called?(api, op)] +end