Method: OpenC3::TargetFile.create

Defined in:
lib/openc3/utilities/target_file.rb

.create(scope, name, text, content_type: 'text/plain') ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/openc3/utilities/target_file.rb', line 116

def self.create(scope, name, text, content_type: 'text/plain')
  return false unless text
  if ENV['OPENC3_LOCAL_MODE']
    OpenC3::LocalMode.put_target_file("#{scope}/targets_modified/#{name}", text, scope: scope)
  end
  client = Bucket.getClient()
  client.put_object(
    # Use targets_modified to save modifications
    # This keeps the original target clean (read-only)
    bucket: ENV['OPENC3_CONFIG_BUCKET'],
    key: "#{scope}/targets_modified/#{name}",
    body: text,
    content_type: content_type,
  )
  # Wait for the object to exist
  if client.check_object(
    bucket: ENV['OPENC3_CONFIG_BUCKET'],
    key: "#{scope}/targets_modified/#{name}",
  )
    true
  else
    false
  end
end