Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
# Copyright (c) 2013 TrilioData, Inc.
"""
Trusts Interface (1.1 extension).
"""
import json
from workloadmgrclient import base

try:
    from urllib import urlencode
except Exception:
    from urllib.parse import urlencode


class Trust(base.Resource):
    """A trust describes the trust between the user and triliovault service account """

    def __repr__(self):
        return "<Trust: %s>" % self.trust_id

    def delete(self):
        """Delete this trust."""
        return self.manager.delete(self)


class TrustManager(base.ManagerWithFind):
    """Manage :class:`Trust` resources."""

    resource_class = Trust

    def create(self, role_name, is_cloud_trust=False):
        """Create a trust. """

        body = {"trusts": {"role_name": role_name, "is_cloud_trust": is_cloud_trust}}
        return self._create("/trusts", body, "trust", return_raw=True)

    def get(self, trust_id, query_string=None):
        """Show details of a trust.

        """
        resp, body = self.api.client.get("/trusts/%s" % trust_id)
        return body["trust"]

    def list(self, get_hidden=False, is_cloud_admin=False):
        """Get a list of all trusts.

        :rtype: list of :class:`Setting`
        """
        url = "/trusts"
        params = {}
        if get_hidden:
            params.update({"get_hidden": json.dumps(get_hidden)})
        if is_cloud_admin:
            params.update({"is_cloud_admin": json.dumps(is_cloud_admin)})
        if params:
            query_str = urlencode(params)
            url = url + "?" + query_str
        resp, body = self.api.client.get(url)
        return body["trust"]

    def delete(self, trust_id):
        """Delete a trust.
        """
        self._delete("/trusts/%s" % base.getid(trust_id))

    def validate_scheduler_trust(self, workload_id):
        """ Validate scheduler trust for a given workload
        """
        resp, body = self.api.client.get("/trusts/validate/%s" % workload_id)
        res = {"scheduler_enabled": False, "trust": None, "is_valid": False}
        if body:
            res.update(body)
        return res