st2 icon indicating copy to clipboard operation
st2 copied to clipboard

Fixed a bug where key value pair was not returning data correctly when get_by_name function is called.

Open bharath-orchestral opened this issue 3 years ago • 6 comments

Bug: Calling 'get_by_name' on client for getting key details was not returning any results despite key being stored. Following is the sample code for replicating the bug

from st2common.runners.base_action import Action
from st2client.client import Client

class actionContext(Action):
    def run(self):

        client = Client(base_url='http://localhost')
        result = client.keys.get_by_name(name='test_key',scope='user')
        self.logger.debug(result)
        return result

Resolution: 'keys' property in Client is of type 'ResourceManager'. We created a new class 'KeyValuePairResourceManager' which inherits from 'ResourceManager'. We assigned 'KeyValuePairResourceManager' to 'keys' property. We have created get_by_name in this class. KeyValuePairResourceManager's get_by_name calls "/keys/{keyname}" url while the old function used to call '/keys' url. We looked into test cases for classes which inherit from 'ResourceManager' but did not find any. There are test cases for functions in 'ResourceManager' but not for classes inheriting from it. But we wrote a unit test case which tests KeyValuePairResourceManager's get_by_name function

bharath-orchestral avatar Jul 19 '22 03:07 bharath-orchestral

Resubmitted the PR with correct credentials.

bharath-orchestral avatar Jul 19 '22 03:07 bharath-orchestral

Can anyone help me on how to add changes to CHANGELOG.rst? Do I need to run some command like make lint?

bharath-orchestral avatar Jul 19 '22 03:07 bharath-orchestral

@bharath-orchestral Thanks for working on this!

Here is the changelog: https://github.com/StackStorm/st2/blob/master/CHANGELOG.rst There isn't a command that auto-generates a changelog entry (though I wish we had that). Here is an example of a adding a changelog entry: https://github.com/StackStorm/st2/commit/8e908a5435a5a70a80d7fb4839e2fb8a663b1a6c

For this PR, you will need to put your changelog entry under In Development (at the top of the file) at the end of the list of Fixed issues.

cognifloyd avatar Jul 19 '22 06:07 cognifloyd

To run the black formatter you can use make black.

cognifloyd avatar Jul 19 '22 06:07 cognifloyd

Deleting that init.py file also removed the folders it was in, so now there are failures in some unit tests. Could you restore that please? Or a .gitkeep file would probably work

cognifloyd avatar Jul 25 '22 14:07 cognifloyd

I added that init.py in that folder but for some reason orquesta CI/ Integration Tests are failing. @cognifloyd Do you know the reason for this?

bharath-orchestral avatar Jul 25 '22 15:07 bharath-orchestral