MCPcopy Create free account
hub / github.com/StackStorm/st2 / UserKeyReference

Class UserKeyReference

st2common/st2common/models/system/keyvalue.py:32–107  ·  view source on GitHub ↗

Holds a reference to key given name and prefix. For example, if key name is foo and prefix is bob, this returns a string of form "bob.foo". This assumes '.' is the PREFIX_SEPARATOR.

Source from the content-addressed store, hash-verified

30
31
32class UserKeyReference(object):
33 """
34 Holds a reference to key given name and prefix. For example, if key name is foo and prefix
35 is bob, this returns a string of form "bob.foo". This assumes '.' is the PREFIX_SEPARATOR.
36 """
37
38 def __init__(self, user, name):
39 self._user = user
40 self._name = name
41 self.ref = "%s%s%s" % (self._user, USER_SEPARATOR, self._name)
42
43 def __str__(self):
44 return self.ref
45
46 @staticmethod
47 def to_string_reference(user, name):
48 """
49 Given a key ``name`` and ``user``, this method returns a new name (string ref)
50 to address the key value pair in the context of that user.
51
52 :param user: User to whom key belongs.
53 :type name: ``str``
54
55 :param name: Original name of the key.
56 :type name: ``str``
57
58 :rtype: ``str``
59 """
60 if not user or not name:
61 raise ValueError('Both "user" and "name" must be valid to generate ref.')
62 return UserKeyReference(user=user, name=name).ref
63
64 @staticmethod
65 def from_string_reference(ref):
66 """
67 Given a user key ``reference``, this method returns the user and actual name of the key.
68
69 :param ref: Reference to user key.
70 :type ref: ``str``
71
72 :rtype: ``tuple`` of ``str`` and ``str``
73 """
74 user = UserKeyReference.get_user(ref)
75 name = UserKeyReference.get_name(ref)
76
77 return (user, name)
78
79 @staticmethod
80 def get_user(ref):
81 """
82 Given a user key ``reference``, this method returns the user to whom the key belongs.
83
84 :param ref: Reference to user key.
85 :type ref: ``str``
86
87 :rtype: ``str``
88 """
89 try:

Callers 3

_getMethod · 0.90
get_key_referenceFunction · 0.90
to_string_referenceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected