6.4.7 ストアド・オブジェクトへのアクセスの管理

oml.grantおよびoml.revoke関数は、スクリプト・リポジトリ内のデータストアまたはユーザー定義Python関数に対する読取り権限を付与または取り消します。

oml.grant関数は、データストアまたはOML4Pyスクリプト・リポジトリ内のユーザー定義Python関数への読取り権限を別のユーザーに付与します。oml.revoke関数は、その権限を取り消します。

これらの関数の構文は次のとおりです。

oml.grant(name, typ='datastore', user=None)
oml.revoke(name, typ='datastore', user=None)

name引数は、スクリプト・リポジトリ内のユーザー定義Python関数の名前またはデータストアの名前を指定する文字列です。

typパラメータを指定する必要があります。引数は、‘datastore’または‘pyqscript’である文字列です。

user引数は、指定したデータストアまたはユーザー定義Python関数への読取り権限を付与するユーザーまたはそれを取り消すユーザーを指定する文字列、あるいはNone (デフォルト)です。Noneを指定すると、すべてのユーザーに対して読取り権限が付与されるか、取り消されます。

例6-19 データストアへのアクセス権の付与および取消し

この例では、すべてのユーザーに読取り権限が付与されているデータストアを表示します。ds_pymodelデータストアから読取り権限を取り消し、パブリック読取り権限を持つデータストアを再度表示します。次に、ユーザーSHに読取り権限を付与し、最後に、読取り権限が付与されているデータストアをもう一度表示します。この例で使用しているデータストアの作成については、例6-14を参照してください。

import oml

# Show datastores to which other users have been granted read privilege.
oml.ds.dir(dstype="grant")

# Revoke the read privilege from every user.
oml.revoke(name="ds_pymodel", typ="datastore", user=None)

# Again show datastores to which read privilege has been granted.
oml.ds.dir(dstype="grant")

# Grant the read privilege to the user SH.
oml.grant(name="ds_pymodel", typ="datastore", user="SH")

oml.ds.dir(dstype="grant")

この例のリスト

>>> import oml
>>> 
>>> # Show datastores to which other users have been granted read privilege.
... oml.ds.dir(dstype="grant")
  datastore_name grantee
0     ds_pymodel  PUBLIC
>>>
>>> # Revoke the read privilege from every user.
... oml.revoke(name="ds_pymodel", typ="datastore", user=None)
>>>
>>> # Again show datastores to which read privilege has been granted to other users.
... oml.ds.dir(dstype="grant")
Empty DataFrame
Columns: [datastore_name, grantee]
Index: []
>>>
>>> # Grant the read privilege to the user SH.
... oml.grant(name="ds_pymodel", typ="datastore", user="SH")
>>> 
>>> oml.ds.dir(dstype="grant")
  datastore_name grantee
0     ds_pymodel      SH

例6-20 ユーザー定義Python関数へのアクセス権の付与と取消し

この例では、MYLMユーザー定義Python関数への読取り権限をユーザーSHに付与し、その権限を取り消します。この例で使用されているユーザー定義Python関数の作成については、例10-11を参照してください。

# List the user-defined Python functions available only to the current user.
oml.script.dir(sctype='user')

# Grant the read privilege to the MYLM user-defined Python function to the user SH.
oml.grant(name="MYLM", typ="pyqscript", user="SH")

# List the user-defined Python functions to which read privilege has been granted.
oml.script.dir(sctype="grant")

# Revoke the read privilege to the MYLM user-defined Python function from the user SH.
oml.revoke(name="MYLM", typ="pyqscript", user="SH")

# List the granted user-defined Python functions again to see if the revocation was successful.
oml.script.dir(sctype="grant")

この例のリスト

>>> # List the user-defined Python functions available only to the current user.
oml.script.dir(sctype='user')
   name                                             script
0  MYLM  def build_lm1(dat):\n  from sklearn import lin...
>>>
>>># Grant the read privilege to the MYLM user-defined Python function to the user SH.
...oml.grant(name="MYLM", typ="pyqscript", user="SH")
>>>
>>> # List the user-defined Python functions to which read privilege has been granted.
... oml.script.dir(sctype="grant")
   name grantee
0  MYLM      SH
>>>
>>> # Revoke the read privilege to the MYLM user-defined Python function from the user SH.
... oml.revoke(name="MYLM", typ="pyqscript", user="SH")
>>>
>>> # List the granted user-defined Python functions again to see if the revocation was successful.
... oml.script.dir(sctype="grant")
Empty DataFrame
Columns: [name, grantee]
Index: []