Class: HelixVersioningEngine::App

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/helix_versioning_engine/app.rb,
lib/helix_versioning_engine/app/specs.rb,
lib/helix_versioning_engine/app/login.rb,
lib/helix_versioning_engine/app/files.rb,
lib/helix_versioning_engine/app/users.rb,
lib/helix_versioning_engine/app/changes.rb,
lib/helix_versioning_engine/app/streams.rb,
lib/helix_versioning_engine/app/commands.rb,
lib/helix_versioning_engine/app/triggers.rb,
lib/helix_versioning_engine/app/counters.rb,
lib/helix_versioning_engine/app/protections.rb

Overview

Methods to manipulate protections table.

The 'protections' resource in our system is the complete list, so you don't fetch or manipulate any single 'protection'. It's all or nothing.

Class Attribute Summary (collapse)

Instance Method Summary (collapse)

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method, *args)

It's assumed that these are typically used to find the different spec types within typical requests.



66
67
68
69
70
71
72
73
74
# File 'lib/helix_versioning_engine/app.rb', line 66

def method_missing(method, *args)
  return unless method.to_s =~ /^normalize_(.*)/

  spec_type = Regexp.last_match[1]
  unless self.class.normalizers.key?(spec_type)
    self.class.normalizers[spec_type] = Util.normalizer(spec_type, offset)
  end
  self.class.normalizers[spec_type].call(*args)
end

Class Attribute Details

+ (Object) normalizers

Returns the value of attribute normalizers



61
62
63
# File 'lib/helix_versioning_engine/app.rb', line 61

def normalizers
  @normalizers
end

Instance Method Details

- (Object) check_whitelist(cmd, args)



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/helix_versioning_engine/app/commands.rb', line 47

def check_whitelist(cmd, args)
  # Make sure command is whitelisted
  cmd_whitelisted = HWSSettings.system.COMMAND_WHITELIST.any? do |wl|
    if wl.is_a?(String)
      wl == cmd
    elsif wl.is_a?(Array)
      wl.first == cmd
    end
  end

  unless cmd_whitelisted
    halt 403, { MessageCode: 15_360,
                MessageText: "#{cmd} not whitelisted in configuration",
                MessageSeverity: :ERROR }.to_json
  end

  # If command is whitelisted, double check that we do not have required
  # arguments
  required_args = HWSSettings.system.COMMAND_WHITELIST.find do |wl|
    if wl.is_a?(Array)
      wl.first == cmd
    end
  end

  if required_args
    unless required_args.drop(1).all? { |r| args.include?(r) }
      halt 403, { MessageCode: 15_360,
                  MessageText: "#{cmd} not used with all required arguments #{required_args.drop(1)}",
                  MessageSeverity: :ERROR }.to_json
    end
  end
end

- (Object) fetch_offset



49
50
51
52
53
54
55
56
# File 'lib/helix_versioning_engine/app.rb', line 49

def fetch_offset
  offset = nil
  open_p4_as_user do |p4|
    results = p4.run_info
    offset = Util.p4_date_offset(results[0]['serverDate'])
  end
  offset
end

- (Object) filter_params(params)

Basically a “blacklist” of things we know the frameworks going to add to the params array we don't want to pass on to the p4 command sets for spec input



79
80
81
82
83
# File 'lib/helix_versioning_engine/app.rb', line 79

def filter_params(params)
  params.select do |k, _v|
    k != 'spec_type' && k != 'id' && k != 'splat' && k != 'captures'
  end
end

- (Object) offset

Will fetch the system offset based on the server date.

If allow_env_p4_config is true, we don't cache. Each request could come in from a new server, and the different servers may have different offsets.



41
42
43
44
45
46
47
# File 'lib/helix_versioning_engine/app.rb', line 41

def offset
  if settings.allow_env_p4_config
    fetch_offset
  else
    @offset ||= fetch_offset
  end
end

- (Object) to_msg(message)



28
29
30
31
32
33
34
# File 'lib/helix_versioning_engine/app.rb', line 28

def to_msg(message)
  {
      MessageCode: message.msgid,
      MessageSeverity: message.severity,
      MessageText: message.to_s
  }
end