@contiamo/resource-role-assigner

This project allows our UIs to assign roles for a given user, group or API token (called a principal) on a given resource: like a Bundle in Labs or a Data Source in Pantheon.

Usage no npm install needed!

<script type="module">
  import contiamoResourceRoleAssigner from 'https://cdn.skypack.dev/@contiamo/resource-role-assigner';
</script>

README

Resource Role Assigner

This project allows our UIs to assign roles for a given user, group or API token (called a principal) on a given resource: like a Bundle in Labs or a Data Source in Pantheon.

In essence, this tool (expressed as a Modal window), allows a user to "make Peter an Admin of Catalog 123" in a user-friendly way.

Getting Started

  1. npm install @contiamo/resource-role-assigner
  2. Consider the following use-case from Pantheon
import React, { useState } from "react"
import ResourceRoleAssigner from "@contiamo/resource-role-assigner"

const MyComponent = ({ catalog, dataSource, me }) => {
    const [modalState, setModalState] = useState(false);
    const availableRoles: ["Reader", "Editor", "Viewer"] = ["Reader", "Editor", "Viewer];

    return (<ResourceRoleAssigner
        onClose={() => setModalState(false)}
        defaultRole="Editor"
        roles={availableRoles}
        resource={{
            name: catalog.name,
            permissionsUrl: `${getConfig("pantheon.backend")}/catalogs/${catalog.id}/dataSources/${dataSource.id}/permissions`,
            requestOptions: {
                headers: {
                    "x-double-cookie": Cookies.get("double-cookie"),
                },
                credentials: "include",
            },
        }}
        idp={{
            url: `${getConfig("auth")}/v2/${me.tenant.id}`,
            usersUrl: `${getConfig("auth")}/v2/tenants/${me.tenant.id}/users`,
            groupsUrl: `${getConfig( "auth")}/v2/tenants/${me.tenant.id}/realms/${catalog.id}/groups`,
        }}
    />)
}

Contributing

This project uses Operational Scripts and has a familiar tooling set up. To contribute to this project, simply:

  1. git clone this repo,
  2. cd resource-role-assigner
  3. npm install
  4. code . or vim or spin up your editor of choice.
  5. Go to town.

As usual, issues and pull requests are enabled in case any help is needed or discussions are to be had.

Happy coding!