Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Memri
pymemri
Commits
984b8653
Commit
984b8653
authored
3 years ago
by
Eelco van der Wel
Browse files
Options
Download
Email Patches
Plain Diff
state=status
parent
d755d314
Pipeline
#3413
failed with stage
in 2 minutes and 59 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
nbs/plugin.schema.ipynb
+4
-4
nbs/plugin.schema.ipynb
pymemri/client_simulator/password_simulator.py
+7
-7
pymemri/client_simulator/password_simulator.py
pymemri/plugin/schema.py
+4
-4
pymemri/plugin/schema.py
with
15 additions
and
15 deletions
+15
-15
nbs/plugin.schema.ipynb
+
4
-
4
View file @
984b8653
...
...
@@ -59,7 +59,7 @@
"# export\n",
"# hide\n",
"class PluginRun(Item):\n",
" properties = Item.properties + [\"containerImage\", \"pluginModule\", \"pluginName\", \"stat
e
\", \"targetItemId\",\n",
" properties = Item.properties + [\"containerImage\", \"pluginModule\", \"pluginName\", \"stat
us
\", \"targetItemId\",\n",
" \"oAuthUrl\", \"error\", \"settings\"]\n",
" edges = Item.edges + [\"view\", \"persistentState\", \"account\"]\n",
"\n",
...
...
@@ -83,10 +83,10 @@
" id_ = \"\".join([random.choice(string.hexdigits) for i in range(32)]) if targetItemId is None else targetItemId\n",
" self.targetItemId=id_\n",
" self.id=id_\n",
" self.stat
e
= stat
e # for stateful plugin
s\n",
" self.stat
us
= stat
u
s\n",
" self.settings = settings\n",
" self.oAuthUrl = oAuthUrl
# for authenticated plugins
\n",
" self.error = error
# universa
\n",
" self.oAuthUrl = oAuthUrl\n",
" self.error = error\n",
" self.account = account if account is not None else []\n",
" self.persistentState = persistentState if persistentState is not None else []\n",
" self.view = view if view is not None else []"
...
...
%% Cell type:code id:5b788afc tags:
```
python
# default_exp plugin.schema
```
%% Cell type:code id:f8766d7d tags:
```
python
# export
# hide
import
random
,
string
from
pymemri.data.itembase
import
Item
```
%% Cell type:code id:f36dd7c1 tags:
```
python
# export
# hide
class
Account
(
Item
):
properties
=
Item
.
properties
+
[
'service'
,
"identifier"
,
"secret"
,
"code"
,
"refreshToken"
,
"errorMessage"
]
edges
=
Item
.
edges
def
__init__
(
self
,
service
=
None
,
identifier
=
None
,
secret
=
None
,
code
=
None
,
refreshToken
=
None
,
errorMessage
=
None
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
self
.
service
=
service
self
.
identifier
=
identifier
self
.
secret
=
secret
self
.
refreshToken
=
refreshToken
self
.
code
=
code
self
.
errorMessage
=
errorMessage
```
%% Cell type:code id:21341d97 tags:
```
python
# export
# hide
class
PluginRun
(
Item
):
properties
=
Item
.
properties
+
[
"containerImage"
,
"pluginModule"
,
"pluginName"
,
"stat
e
"
,
"targetItemId"
,
properties
=
Item
.
properties
+
[
"containerImage"
,
"pluginModule"
,
"pluginName"
,
"stat
us
"
,
"targetItemId"
,
"oAuthUrl"
,
"error"
,
"settings"
]
edges
=
Item
.
edges
+
[
"view"
,
"persistentState"
,
"account"
]
def
__init__
(
self
,
containerImage
,
pluginModule
,
pluginName
,
state
=
None
,
settings
=
None
,
view
=
None
,
targetItemId
=
None
,
oAuthUrl
=
None
,
error
=
None
,
persistentState
=
None
,
account
=
None
,
**
kwargs
):
"""
PluginRun defines a the run of plugin `plugin_module.plugin_name`,
with an optional `settings` string.
Args:
plugin_module (str): module of the plugin.
plugin_name (str): class name of the plugin.
settings (str, optional): Optional plugin configuration. For example,
this could be a `json.dumps` of a configuration dict. Defaults to None.
"""
super
().
__init__
(
**
kwargs
)
self
.
pluginModule
=
pluginModule
self
.
pluginName
=
pluginName
self
.
containerImage
=
containerImage
id_
=
""
.
join
([
random
.
choice
(
string
.
hexdigits
)
for
i
in
range
(
32
)])
if
targetItemId
is
None
else
targetItemId
self
.
targetItemId
=
id_
self
.
id
=
id_
self
.
stat
e
=
stat
e
# for stateful plugin
s
self
.
stat
us
=
stat
u
s
self
.
settings
=
settings
self
.
oAuthUrl
=
oAuthUrl
# for authenticated plugins
self
.
error
=
error
# universa
self
.
oAuthUrl
=
oAuthUrl
self
.
error
=
error
self
.
account
=
account
if
account
is
not
None
else
[]
self
.
persistentState
=
persistentState
if
persistentState
is
not
None
else
[]
self
.
view
=
view
if
view
is
not
None
else
[]
```
%% Cell type:code id:1e94eca2 tags:
```
python
run
=
PluginRun
(
"image"
,
"module"
,
"name"
,
account
=
[
Account
()])
```
%% Cell type:code id:a8f74669 tags:
```
python
# export
# hide
class
PersistentState
(
Item
):
""" Persistent state variables saved for plugin such as views, accounts, the last state to resume from etc. """
properties
=
Item
.
properties
+
[
"pluginId"
,
"state"
]
edges
=
Item
.
edges
+
[
"account"
,
"view"
]
def
__init__
(
self
,
pluginName
=
None
,
state
=
None
,
account
=
None
,
view
=
None
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
self
.
pluginName
=
pluginName
self
.
state
=
state
self
.
account
=
account
if
account
is
not
None
else
[]
self
.
view
=
view
if
view
is
not
None
else
[]
def
get_state
(
self
):
return
self
.
state
def
set_state
(
self
,
client
,
state_str
):
self
.
state
=
state_str
client
.
update_item
(
self
)
def
get_account
(
self
):
if
len
(
self
.
account
)
==
0
:
return
None
else
:
return
self
.
account
[
0
]
def
set_account
(
self
,
client
,
account
):
if
len
(
self
.
account
)
==
0
:
if
not
account
.
id
:
client
.
create
(
account
)
self
.
add_edge
(
'account'
,
account
)
self
.
update
(
client
)
else
:
existing_account
=
self
.
account
[
0
]
for
prop
in
account
.
properties
:
value
=
getattr
(
account
,
prop
,
None
)
if
value
and
hasattr
(
existing_account
,
prop
):
setattr
(
existing_account
,
prop
,
value
)
existing_account
.
update
(
client
)
def
get_view_by_name
(
self
,
view_name
):
for
cvu
in
self
.
view
:
if
cvu
.
name
==
view_name
:
return
cvu
def
set_views
(
self
,
client
,
views
=
None
):
for
view
in
views
:
client
.
create
(
view
)
self
.
add_edge
(
'view'
,
view
)
self
.
update
(
client
)
return
True
```
...
...
This diff is collapsed.
Click to expand it.
pymemri/client_simulator/password_simulator.py
+
7
-
7
View file @
984b8653
...
...
@@ -22,25 +22,25 @@ def run_password_simulator(
time
.
sleep
(
SLEEP_INTERVAL
)
pluginRun
=
client
.
get
(
run_id
)
if
pluginRun
.
stat
e
==
"userActionNeeded"
:
if
pluginRun
.
stat
us
==
"userActionNeeded"
:
username
,
password
=
input_credentials
()
pluginRun
.
identifier
=
username
pluginRun
.
secret
=
password
pluginRun
.
stat
e
=
"ready"
pluginRun
.
stat
us
=
"ready"
client
.
update
(
pluginRun
)
elif
pluginRun
.
stat
e
==
"started"
:
elif
pluginRun
.
stat
us
==
"started"
:
print
(
"plugin starting..."
)
elif
pluginRun
.
stat
e
==
"ready"
:
elif
pluginRun
.
stat
us
==
"ready"
:
print
(
"no user action needed."
)
elif
pluginRun
.
stat
e
==
"error"
:
elif
pluginRun
.
stat
us
==
"error"
:
print
(
"error occurred in plugin."
)
break
elif
pluginRun
.
stat
e
==
"done"
:
elif
pluginRun
.
stat
us
==
"done"
:
break
else
:
print
(
f
"unknown plugin state
{
pluginRun
.
state
}
."
)
\ No newline at end of file
print
(
f
"unknown plugin state
{
pluginRun
.
status
}
."
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
pymemri/plugin/schema.py
+
4
-
4
View file @
984b8653
...
...
@@ -29,7 +29,7 @@ class Account(Item):
# Cell
# hide
class
PluginRun
(
Item
):
properties
=
Item
.
properties
+
[
"containerImage"
,
"pluginModule"
,
"pluginName"
,
"stat
e
"
,
"targetItemId"
,
properties
=
Item
.
properties
+
[
"containerImage"
,
"pluginModule"
,
"pluginName"
,
"stat
us
"
,
"targetItemId"
,
"oAuthUrl"
,
"error"
,
"settings"
]
edges
=
Item
.
edges
+
[
"view"
,
"persistentState"
,
"account"
]
...
...
@@ -53,10 +53,10 @@ class PluginRun(Item):
id_
=
""
.
join
([
random
.
choice
(
string
.
hexdigits
)
for
i
in
range
(
32
)])
if
targetItemId
is
None
else
targetItemId
self
.
targetItemId
=
id_
self
.
id
=
id_
self
.
stat
e
=
stat
e
# for stateful plugin
s
self
.
stat
us
=
stat
u
s
self
.
settings
=
settings
self
.
oAuthUrl
=
oAuthUrl
# for authenticated plugins
self
.
error
=
error
# universa
self
.
oAuthUrl
=
oAuthUrl
self
.
error
=
error
self
.
account
=
account
if
account
is
not
None
else
[]
self
.
persistentState
=
persistentState
if
persistentState
is
not
None
else
[]
self
.
view
=
view
if
view
is
not
None
else
[]
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets