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

Add support for Shared Folders #60

Closed
Gestas opened this issue Jun 29, 2020 · 1 comment · Fixed by #61
Closed

Add support for Shared Folders #60

Gestas opened this issue Jun 29, 2020 · 1 comment · Fixed by #61

Comments

@Gestas
Copy link
Contributor

Gestas commented Jun 29, 2020

Add support for Shared Folders using API_KEY = "SYNO.Core.Share". See #58 for motivation.

@Quentame they are using their (?weird?) POST format quite a bit with shares. There are 19 Shared Folder attributes that are only returned if they are specifically requested via params. See an example below. There are other API calls that use this as well. I think there needs to be a generic way to handle these. What do you think about supporting a list of additional parameters in each module? I can't quite figure out how to pass the parameter from the API module (/python-synology/synology_dsm/api/core/share.py) but the structure would look something like the example below.

If you are OK with this general approach I need some pointers on the changes required in synology_dsm.py so these additional parameters get passed to requests. I can't quite grok that flow yet.

Potential share.py with params -

class SynoShare(object):
    """Class containing Share data."""

    API_KEY = "SYNO.Core.Share"
    SHARE_PARAMS = {"additional": '"hidden", "encryption", "is_aclmode", '
                                  '"unite_permission", "is_support_acl", '
                                  '"is_sync_share", "is_force_readonly", '
                                  '"force_readonly_reason", "recyclebin", '
                                  '"is_share_moving", "is_cluster_share", '
                                  '"is_exfat_share", "is_cold_storage_share", '
                                  '"support_snapshot", "share_quota", '
                                  '"enable_share_compress", "enable_share_cow", '
                                  '"include_cold_storage_share", '
                                  '"is_cold_storage_share"',
                    "shareType": "all"}

    def __init__(self, raw_data):
        self._data = {}
        self.update(raw_data)

    def update(self, raw_data):
        """Updates share data."""
        if raw_data:
            self._data = raw_data
            if raw_data.get("data"):
                self._data = raw_data["data"]

    @property
    # Some changes required here to support SHARE_PARAMS. 
    def shares(self):
        """Gets all shares."""
        return self._data.get("shares", [])

    def share(self, share_name):
        """Returns a specific share."""
        for share in self.shares:
            if share["name"] == share_name:
                return share
        return {}

Shared Folders POST -

"postData": {
            "mimeType": "application/x-www-form-urlencoded",
            "params": [
              {
                "name": "additional",
                "value": "[\"hidden\",\"encryption\",\"is_aclmode\",\"unite_permission\",\"is_support_acl\",\"is_sync_share\",\"is_force_readonly\",\"force_readonly_reason\",\"recyclebin\",\"is_share_moving\",\"is_cluster_share\",\"is_exfat_share\",\"is_cold_storage_share\",\"support_snapshot\",\"share_quota\",\"enable_share_compress\",\"enable_share_cow\",\"include_cold_storage_share\",\"is_cold_storage_share\"]"
              },
              {
                "name": "shareType",
                "value": "\"all\""
              },
              {
                "name": "api",
                "value": "SYNO.Core.Share"
              },
              {
                "name": "method",
                "value": "list"
              },
              {
                "name": "version",
                "value": "1"
              }
            ],
            "text": "additional=%5B%22hidden%22%2C%22encryption%22%2C%22is_aclmode%22%2C%22unite_permission%22%2C%22is_support_acl%22%2C%22is_sync_share%22%2C%22is_force_readonly%22%2C%22force_readonly_reason%22%2C%22recyclebin%22%2C%22is_share_moving%22%2C%22is_cluster_share%22%2C%22is_exfat_share%22%2C%22is_cold_storage_share%22%2C%22support_snapshot%22%2C%22share_quota%22%2C%22enable_share_compress%22%2C%22enable_share_cow%22%2C%22include_cold_storage_share%22%2C%22is_cold_storage_share%22%5D&shareType=%22all%22&api=SYNO.Core.Share&method=list&version=1"
          }
@Gestas
Copy link
Contributor Author

Gestas commented Jun 29, 2020

Pull request submitted for Shared Folder support without extended parameters - #61

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 a pull request may close this issue.

1 participant