Class: SFRest::Stage

Inherits:
Object
  • Object
show all
Defined in:
lib/sfrest/stage.rb

Overview

Find Staging envs and stage a set of sites

Instance Method Summary collapse

Constructor Details

#initialize(conn) ⇒ Stage

Returns a new instance of Stage.

Parameters:



7
8
9
# File 'lib/sfrest/stage.rb', line 7

def initialize(conn)
  @conn = conn
end

Instance Method Details

#enhanced_stage(env: 'test', sites: [], email_site_status: false, wipe_target_environment: false, synchronize_all_users: true, wipe_stacks: [], skip_site_files: false, skip_site_files_overwrite: [], force_psu_hook: false) ⇒ Integer

Stage a site using the new method rubocop:disable Metrics/ParameterLists

Parameters:

  • to_env (String)

    the name of of target env. defaults to test

  • sites (Array) (defaults to: [])

    Array of site nids to stage

  • email_site_status (Boolean) (defaults to: false)

    send an email about the staging status of each site

  • wipe_target_environment (Boolean) (defaults to: false)

    recreate the target stage wiping all data

  • only (synchronize_all_users)

    stage the user accounts required for the related collections and groups

  • Stacks (Array)

    Array of stack ids to wipe

  • skip_site_files (Boolean) (defaults to: false)

    site skip file transfer during staging

  • skip_site_files_overwrite (Array) (defaults to: [])

    list of files to skip during staging

  • force_psu_hook (Boolean) (defaults to: false)

    Force post-staging-update hook to run even if VCS paths are the same

Returns:

  • (Integer)

    Id of the staging task created.

Raises:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sfrest/stage.rb', line 42

def enhanced_stage(env: 'test',
                   sites: [],
                   email_site_status: false,
                   wipe_target_environment: false,
                   synchronize_all_users: true,
                   wipe_stacks: [],
                   skip_site_files: false,
                   skip_site_files_overwrite: [],
                   force_psu_hook: false)
  raise InvalidApiVersion, staging_versions unless staging_versions.include? 2

  payload = { 'to_env' => env, 'sites' => sites,
              'detailed_status' => email_site_status,
              'wipe_target_environment' => wipe_target_environment,
              'synchronize_all_users' => synchronize_all_users,
              'wipe_stacks' => wipe_stacks,
              'skip_site_files' => skip_site_files,
              'skip_site_files_overwrite' => skip_site_files_overwrite,
              'force_psu_hook' => force_psu_hook }.to_json
  @conn.post('/api/v2/stage', payload)
end

#list_staging_environmentsObject

Query for available staging environments

Returns:

  • environments



68
69
70
71
# File 'lib/sfrest/stage.rb', line 68

def list_staging_environments
  current_path = "/api/v#{staging_versions.sample}/stage"
  @conn.get(current_path)
end

#stage(to_env = 'test', sites = nil, email_site_status = false, skip_gardener = false) ⇒ Integer

Stage a site rubocop: disable Style/OptionalBooleanParameter, Metrics/ParameterLists

Parameters:

  • to_env (String) (defaults to: 'test')

    the name of of target env. defaults to test

  • sites (Array) (defaults to: nil)

    Array of site nids to stage

  • email_site_status (Boolean) (defaults to: false)

    send an email about the staging status of each site

  • skip_gardener (Boolean) (defaults to: false)

    skip staging the gardener and only stage the sites

Returns:

  • (Integer)

    Id of the staging task created.

Raises:



19
20
21
22
23
24
25
26
# File 'lib/sfrest/stage.rb', line 19

def stage(to_env = 'test', sites = nil, email_site_status = false, skip_gardener = false)
  raise InvalidApiVersion, staging_versions unless staging_versions.include? 1

  payload = { 'to_env' => to_env, 'sites' => sites,
              'detailed_status' => email_site_status,
              'skip_gardener' => skip_gardener }.to_json
  @conn.post('/api/v1/stage', payload)
end

#staging_versionsArray

determine what version are available for staging

Returns:

  • (Array)

    Array of available api endpoints



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/sfrest/stage.rb', line 75

def staging_versions
  possible_versions = [1, 2]
  @versions ||= []
  possible_versions.each do |version|
    @conn.get "/api/v#{version}/stage"
    @versions.push version
  rescue SFRest::InvalidResponse
    nil
  end
  @versions
end