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

Create UserSecretQuery to align with related NerdGraph feature #75

Open
tangollama opened this issue Sep 4, 2020 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@tangollama
Copy link
Contributor

tangollama commented Sep 4, 2020

Create a data fetching component that wraps a NerdGraph request like the following (currently only accessible in the Product schema, but to be released in some modified form later in the year).

{
  actor {
    nerdStorageVault {
      secret(name: "my-token")
    }
  }
}

UserSecretQuery

Query Storage Vault (i.e. secrets encrypted at rest) for user scoped secrets.

Retrieve a secret by name.

Declarative query

//retrieve and use a stored secret
import { UserSecretQuery } from '@newrelic/nr1-community';
//SomeOutsideDataComponent takes a token and makes an external call
import { SomeOutsideDataComponent } from './SomeOutsideDataComponent';

<UserSecretQuery secret="outside_token">
  {({ loading, error, data }) => {
    if (loading) {
      return <Spinner />;
    }
    if (error) {
      return 'Error!';
    }
    const { outside_token } = data;
    return <SomeOutsideDataComponent token={outside_token} />;
  }}
</UserSecretQuery>;

Imperative query

UserSecretQuery.query({
  secret: 'mytoken'
}).then(({ data }) => console.log(data));

Props

prop REQUIRED type description
children TRUE function Render prop function as a child.
secret TRUE string Name of secret for search
@tangollama tangollama added the enhancement New feature or request label Sep 4, 2020
@zstix
Copy link

zstix commented Dec 9, 2020

It would be awesome to provide a hook for this as well (once we upgrade React 🤞):

// get a specific secret (my_token)
const [token, loading] = useUserSecretQuery('my_token');

return loading
  ? <Spinner />
  : <div>Your secret: {token}</div>;
// get all secrets
const [secrets, loading] = useUserSecretQuery();

return loading
  ? <Spinner />
  : <ul>{secrets.map((secret, i) => <li key={i}>{secret}</li>)}</ul>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants