Class: Fastlane::Actions::MaestroOrchestrationApiRequestAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_api_request_action.rb

Class Method Summary collapse

Class Method Details

.available_options ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_api_request_action.rb', line 59

def self.available_options
  [
    s3_path_option,
    version_option,
    device_option,
    theme_option,
    hmac_secret_option,
    url_option
  ]
end

.description ⇒ Object



55
56
57
# File 'lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_api_request_action.rb', line 55

def self.description
  "Sends an API request with a signed payload."
end

.device_option ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_api_request_action.rb', line 91

def self.device_option
  FastlaneCore::ConfigItem.new(
    key: :device,
    env_name: "MAESTRO_SCREENSHOTS_DEVICE",
    description: "Device type: android or ios",
    type: String,
    optional: false,
    verify_block: proc do |value|
      UI.user_error!("You must specify a device type (android or ios).") unless %w[android ios].include?(value.downcase)
    end
  )
end

.hmac_secret_option ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_api_request_action.rb', line 114

def self.hmac_secret_option
  FastlaneCore::ConfigItem.new(
    key: :hmac_secret,
    env_name: "MAESTRO_SCREENSHOTS_HMAC_SECRET",
    description: "The HMAC secret used to sign the payload",
    optional: false,
    verify_block: proc do |value|
      UI.user_error!("You must provide a valid HMAC secret using the `hmac_secret` parameter.") unless value && !value.strip.empty?
    end
  )
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_api_request_action.rb', line 139

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_api_request_action.rb', line 12

def self.run(params)
  required_params = [:s3_path, :version, :device, :hmac_secret, :url]
  missing_params = required_params.select { |param| params[param].nil? }

  if missing_params.any?
    missing_params.each do |param|
      UI.error("Missing parameter: #{param}")
    end
    raise "Missing required parameters: #{missing_params.join(', ')}"
  end

  base_path = "#{params[:s3_path]}/ver:#{params[:version]}"
  base_path += "/theme:#{params[:theme]}" if params[:theme]
  base_path += "/device:#{params[:device]}"

  payload = {
    message: "Screenshots uploaded",
    version: params[:version],
    folder_path: base_path
  }
  payload_json = payload.to_json

  signature = "sha256=#{OpenSSL::HMAC.hexdigest('SHA256', params[:hmac_secret], payload_json)}"

  uri = URI.parse(params[:url])
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = (uri.scheme == "https")

  request = Net::HTTP::Post.new(uri.path, {
    "Content-Type" => "application/json",
    "X-Action-Signature" => signature
  })
  request.body = payload_json

  response = http.request(request)

  if response.kind_of?(Net::HTTPSuccess)
    UI.success("API request successful: #{response.code} - #{response.body}")
  else
    UI.user_error!("API request failed: #{response.code} - #{response.body}")
  end
end

.s3_path_option ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_api_request_action.rb', line 70

def self.s3_path_option
  FastlaneCore::ConfigItem.new(
    key: :s3_path,
    env_name: "MAESTRO_SCREENSHOTS_S3_PATH",
    description: "The base S3 path (after the bucket name) where files will be uploaded: $bucket/$s3_path",
    optional: false
  )
end

.theme_option ⇒ Object



104
105
106
107
108
109
110
111
112
# File 'lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_api_request_action.rb', line 104

def self.theme_option
  FastlaneCore::ConfigItem.new(
    key: :theme,
    env_name: "MAESTRO_SCREENSHOTS_APPLICATION_THEME",
    description: "Optional theme parameter (e.g., dark or light)",
    default_value: nil,
    optional: true
  )
end

.url_option ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_api_request_action.rb', line 126

def self.url_option
  FastlaneCore::ConfigItem.new(
    key: :url,
    env_name: "MAESTRO_SCREENSHOTS_WEBHOOK_URL",
    description: "The URL to send the API request to",
    optional: false,
    verify_block: proc do |value|
      UI.user_error!("You must provide a valid URL using the `url` parameter.") unless value && !value.strip.empty?
      UI.user_error!("The provided URL is invalid: #{value}") unless value.match?(URI::DEFAULT_PARSER.make_regexp)
    end
  )
end

.version_option ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_api_request_action.rb', line 79

def self.version_option
  FastlaneCore::ConfigItem.new(
    key: :version,
    env_name: "MAESTRO_SCREENSHOTS_APP_VERSION",
    description: "Version of the app that screenshots are taken from",
    optional: false,
    verify_block: proc do |value|
      UI.user_error!("You must provide a version using the `version` parameter.") unless value && !value.strip.empty?
    end
  )
end