-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stash api #300
Conversation
stash_set('key2', 2) | ||
check_expression("'#{stash_all().to_s}' == '{\"key1\"=>1, \"key2\"=>2}'") | ||
stash_delete('key2') | ||
check_expression("#{stash_get('key2').nil?} == true") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add some examples of complex data types, not just strings and integers.
|
||
require 'spec_helper' | ||
require 'openc3/api/stash_api' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add complex data types tests. Arrays, hashes, and nested versions.
if (hash['start'] && hash['stop']) | ||
hash['start'] = Time.parse(hash['start']).to_i | ||
hash['stop'] = Time.parse(hash['stop']).to_i | ||
json = @model_class.range(**hash.symbolize_keys, scope: params[:scope]) | ||
json = @model_class.range(start: ['start'], stop: ['stop'], limit: limit, scope: params[:scope]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Range takes start stop and limit ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you meant hash['start'], hash['stop'], not just ['start']
message: e.message, | ||
type: e.class, | ||
}, | ||
status: 409 # Conflict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be 409. We're using that for Hazardous Error and probably should be exclusive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right ... I wanted something to indicate the overlap because that is going to be a common error if you try to create two metadata entries back to back. Actually I see other controllers using 409 so I think that's a more common existing error. I think it's ok for Hazardous to remain 409 as it's unique to the commanding logic.
openc3/lib/openc3/api/stash_api.rb
Outdated
authorize(permission: 'script_view', scope: scope, token: token) | ||
result = StashModel.get(name: key, scope: scope) | ||
if result | ||
Marshal.load(result['value']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use Marshal. Use JSON. Marshal can only be used with Ruby code.
openc3/lib/openc3/api/stash_api.rb
Outdated
|
||
def stash_all(scope: $openc3_scope, token: $openc3_token) | ||
authorize(permission: 'script_view', scope: scope, token: token) | ||
StashModel.all(scope: scope).transform_values { |hash| Marshal.load(hash["value"]) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No Marshal.
closes #293