diff options
| author | mo khan <mo@mokhan.ca> | 2021-05-09 21:17:31 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2021-05-09 21:17:31 -0600 |
| commit | ea979dbb9090dc4eedb685eef6728f13fa124fa5 (patch) | |
| tree | 04770d97460de747d180fe501d899d1a6f1ee221 /lib | |
| parent | 6c100339886de690be1fa20d30acb685f00a2484 (diff) | |
feat: detect `.terraform.lock.hcl` files
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/spandx/terraform/parsers/lock_file.rb | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/lib/spandx/terraform/parsers/lock_file.rb b/lib/spandx/terraform/parsers/lock_file.rb index 9f0260c..5d86a66 100644 --- a/lib/spandx/terraform/parsers/lock_file.rb +++ b/lib/spandx/terraform/parsers/lock_file.rb @@ -3,14 +3,25 @@ module Spandx module Terraform module Parsers - class LockFile - def initialize; end + class LockFile < ::Spandx::Core::Parser + def initialize + @parser = Spandx::Terraform::Parsers::Hcl.new + end + + def match?(pathname) + basename = pathname.basename + basename.fnmatch?('.terraform.lock.hcl') + end def parse(path) - parser = Spandx::Terraform::Parsers::Hcl.new - tree = parser.parse(IO.read(path)) - puts tree.inspect - [] + tree = @parser.parse(path.read) + tree[:blocks].map do |block| + ::Spandx::Core::Dependency.new( + name: block[:name], + version: block[:arguments].find { |x| x[:name] == 'version' }[:value], + path: path + ) + end end end end |
