Skip to content

Commit

Permalink
Merge pull request #478 from NickLaMuro/state-var-hash-purging-improv…
Browse files Browse the repository at this point in the history
…ements

[StateVarHash] Prevent purging
  • Loading branch information
Fryguy committed Oct 6, 2021
2 parents 987bff3 + cb7056d commit ba2c6da
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/miq_automation_engine/engine/miq_ae_engine/state_var_hash.rb
Expand Up @@ -10,8 +10,7 @@ def []=(name, value)
end

def encode_with(coder)
coder[SERIALIZE_KEY] =
blank? ? 0 : BinaryBlob.new.tap { |bb| bb.store_data("YAML", to_h) }.id
coder[SERIALIZE_KEY] = blank? ? 0 : generate_binary_blob
end

def init_with(coder)
Expand All @@ -34,6 +33,17 @@ def init_with(coder)

private

# returns `id` of new blob
def generate_binary_blob
blob = BinaryBlob.new
blob.resource_id = - Time.now.utc.to_i # make it negtive so this isn't a valid ID
blob.resource_type = "StateVarHash"

blob.store_data("YAML", to_h)

blob.id
end

def validate_state_var_name!(name)
if STATE_VAR_NAME_CLASSES.none? { |klass| name.kind_of?(klass) }
raise "State Var key (#{name.class.name})[#{name.inspect}] must be of type: #{STATE_VAR_NAME_CLASSES.join(', ')}"
Expand Down

0 comments on commit ba2c6da

Please sign in to comment.