<commit_before>require 'maestro_agent'
require 'rubygems'
require File.expand_path('../rightscale_api_helper', __FILE__)

module MaestroDev
  class RightScaleWorker < Maestro::MaestroWorker

    # FIXME - convert everything over to allowing RightScale Refresh Tokens instead of username/password
    def validate_base_fields(missing_fields)
      if get_field('account_id').nil?
        missing_fields << 'account_id'
      end
      if get_field('refresh_token').nil? && get_field('username').nil? && get_field('password').nil?
        # missing everything, we'll mark all the fields
        missing_fields << '(username and password) or refresh_token'
      elsif get_field('refresh_token').nil?
        # if not refresh token, but either username/password we'll specify which one
        if get_field('username').nil?
          missing_fields << 'username'
        elsif
          missing_fields << 'password'
        end
      end
    end

    def validate_server_fields
      missing_fields = []
      if get_field('server_id').nil? and ((get_field('nickname').nil? or (get_field('deployment_id').nil? and get_field('deployment_name').nil?)))
        missing_fields << '(nickname and deployment_id) or (nickname and deployment_name) or server_id'
      end
      validate_base_fields(missing_fields)

      set_error("Invalid fields, must provide #{missing_fields.join(", ")}") unless missing_fields.empty?
    end

    def validate_wait_fields
      missing_fields = []
      if get_field('server_id').nil? and ((get_field('nickname').nil? or (get_field('deployment_id').nil? and get_field('deployment_name').nil?)))
        missing_fields << '(nickname and deployment_id) or (nickname and deployment_name) or server_id'
      end
      if get_field('state').nil?
        missing_fields << 'state'
      end
      validate_base_fields(missing_fields)

      set_error("Invalid fields, must provide #{missing_fields.join(", ")}") unless missing_fields.empty?
    end<commit_msg>MAESTRO-2791 fixed empty elsif and tweaked validate function to by more DRY<commit_after>require 'maestro_agent'
require 'rubygems'
require File.expand_path('../rightscale_api_helper', __FILE__)

module MaestroDev
  class RightScaleWorker < Maestro::MaestroWorker

    # FIXME - convert everything over to allowing RightScale Refresh Tokens instead of username/password
    def validate_base_fields(missing_fields)
      if get_field('account_id').nil?
        missing_fields << 'account_id'
      end
      if get_field('refresh_token').nil? && get_field('username').nil? && get_field('password').nil?
        # missing everything, we'll mark all the fields
        missing_fields << '(username and password) or refresh_token'
      elsif get_field('refresh_token').nil?
        # if not refresh token, but either username/password we'll specify which one
        if get_field('username').nil?
          missing_fields << 'username'
        else
          missing_fields << 'password'
        end
      end
    end

    def validate_server_fields(missing_fields = [])
      if get_field('server_id').nil? and ((get_field('nickname').nil? or (get_field('deployment_id').nil? and get_field('deployment_name').nil?)))
        missing_fields << '(nickname and deployment_id) or (nickname and deployment_name) or server_id'
      end
      validate_base_fields(missing_fields)

      set_error("Invalid fields, must provide #{missing_fields.join(", ")}") unless missing_fields.empty?
    end

    def validate_wait_fields
      missing_fields = []
      if get_field('state').nil?
        missing_fields << 'state'
      end
      validate_server_fields(missing_fields)

      set_error("Invalid fields, must provide #{missing_fields.join(", ")}") unless missing_fields.empty?
    end
{'fraction_non_alphanumeric': 0.10603242094073877, 'fraction_numerical': 0.0010629816635663034, 'mean_word_length': 3.681592039800995, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2819226', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1068, 'n_words': 266}