Skip to content
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

Merged
merged 5 commits into from
Dec 2, 2022
Merged

Stash api #300

merged 5 commits into from
Dec 2, 2022

Conversation

jmthomas
Copy link
Member

@jmthomas jmthomas commented Dec 1, 2022

closes #293

@jmthomas jmthomas requested a review from ryanmelt December 1, 2022 18:39
stash_set('key2', 2)
check_expression("'#{stash_all().to_s}' == '{\"key1\"=>1, \"key2\"=>2}'")
stash_delete('key2')
check_expression("#{stash_get('key2').nil?} == true")
Copy link
Member

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'

Copy link
Member

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])
Copy link
Member

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.

Copy link
Member Author

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 ...

Copy link
Member

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
Copy link
Member

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.

Copy link
Member Author

@jmthomas jmthomas Dec 2, 2022

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.

authorize(permission: 'script_view', scope: scope, token: token)
result = StashModel.get(name: key, scope: scope)
if result
Marshal.load(result['value'])
Copy link
Member

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.


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"]) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Marshal.

@jmthomas jmthomas merged commit 5a2ff55 into main Dec 2, 2022
@jmthomas jmthomas deleted the stash_api branch December 2, 2022 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stash API
2 participants