• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aws / aws-codedeploy-agent / 4600315001

pending completion
4600315001

push

github

GitHub
Updating latest version info for master branch

1129 of 2362 relevant lines covered (47.8%)

2.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

21.52
/lib/instance_agent/plugins/codedeploy/application_specification/linux_permission_info.rb
1
module InstanceAgent
1✔
2
  module Plugins
1✔
3
    module CodeDeployPlugin
1✔
4
      module ApplicationSpecification
1✔
5
        #Helper Class for storing data parsed from permissions list
6
        class LinuxPermissionInfo
1✔
7

8
          attr_reader :object, :pattern, :except, :type, :owner, :group, :mode, :acls, :context
1✔
9
          def initialize(object, opts = {})
1✔
10
            object = object.to_s
×
11
            if (object.empty?)
×
12
              raise AppSpecValidationException, 'The deployment failed because a permission listed in the application specification file has no object value. Update the permissions section of the AppSpec file, and then try again.'
×
13
            end
14
            @object = object
×
15
            @pattern = opts[:pattern] || "**"
×
16
            @except = opts[:except] || []
×
17
            @type = opts[:type] || ["file", "directory"]
×
18
            @owner = opts[:owner]
×
19
            @group = opts[:group]
×
20
            @mode = opts[:mode]
×
21
            @acls = opts[:acls]
×
22
            @context = opts[:context]
×
23
          end
24

25
          def validate_file_permission()
1✔
26
            if @type.include?("file")
×
27
              if !"**".eql?(@pattern)
×
28
                raise AppSpecValidationException, "The deployment failed because the application specification file includes an object (#{@object}) with an invalid pattern (#{@pattern}), such as a pattern for a file applied to a directory. Correct the permissions section of the AppSpec file, and then try again."
×
29
              end
30
              if !@except.empty?
×
31
                raise AppSpecValidationException, "The deployment failed because the except parameter for a pattern in the permissions section (#{@except}) for the object named #{@object} contains an invalid format. Update the AppSpec file, and then try again."
×
32
              end
33
            end
34
          end
35

36
          def validate_file_acl(object)
1✔
37
            if !@acls.nil?
×
38
              default_acl = @acls.get_default_ace
×
39
              if !default_acl.nil?
×
40
                raise "The deployment failed because the -d parameter has been specified to apply an acl setting to a file. This parameter is supported for directories only. Update the AppSpec file, and then try again."
×
41
              end
42
            end
43
          end
44

45
          def matches_pattern?(name)
1✔
46
            name = name.chomp(File::SEPARATOR)
×
47
            base_object = sanitize_dir_path(@object)
×
48
            if !base_object.end_with?(File::SEPARATOR)
×
49
              base_object = base_object + File::SEPARATOR
×
50
            end
51
            if name.start_with?(base_object)
×
52
              if ("**".eql?(@pattern))
×
53
                return true
×
54
              end
55
              rel_name = name[base_object.length..name.length]
×
56
              return matches_simple_glob(rel_name, @pattern)
×
57
            end
58
            false
×
59
          end
60

61
          def matches_except?(name)
1✔
62
            name = name.chomp(File::SEPARATOR)
×
63
            base_object = sanitize_dir_path(@object)
×
64
            if !base_object.end_with?(File::SEPARATOR)
×
65
              base_object = base_object + File::SEPARATOR
×
66
            end
67
            if name.start_with?(base_object)
×
68
              rel_name = name[base_object.length..name.length]
×
69
              @except.each do |item|
×
70
                if matches_simple_glob(rel_name, item)
×
71
                  return true
×
72
                end
73
              end
74
            end
75
            false
×
76
          end
77

78
          private
1✔
79
          def matches_simple_glob(name, pattern)
1✔
80
            if name.include?(File::SEPARATOR)
×
81
              return false
×
82
            end
83
            options = expand(pattern.chars.entries)
×
84
            name.chars.each do |char|
×
85
              new_options = []
×
86
              options.each do |option|
×
87
                if option[0].eql?("*")
×
88
                  new_options.concat(expand(option))
×
89
                elsif option[0].eql?(char)
×
90
                  option.shift
×
91
                  new_options.concat(expand(option))
×
92
                end
93
              end
94
              options = new_options
×
95
              if (options.include?(["*"]))
×
96
                return true
×
97
              end
98
            end
99
            options.include?([])
×
100
          end
101

102
          private
1✔
103
          def expand(option)
1✔
104
            previous_option = nil
×
105
            while "*".eql?(option[0]) do
×
106
              previous_option = Array.new(option)
×
107
              option.shift
×
108
            end
109
            previous_option.nil? ? [option] : [previous_option, option]
×
110
          end
111

112
          private
1✔
113
          def sanitize_dir_path(path)
1✔
114
            File.expand_path(path)
×
115
          end
116
        end
117

118
      end
119
    end
120
  end
121
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc