newrelic / nr1-community

An open-source library of useful components for building on New Relic One's programmability platform.
https://developer.newrelic.com
Apache License 2.0
11 stars 12 forks source link

Create UserSecretMutation to align with related NerdGraph feature #77

Open tangollama opened 4 years ago

tangollama commented 4 years ago

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).

Write Secret

mutation StoreUserToken($userId: ID!, $tokenName: String!, $userToken: SecureValue!) {
  nerdStorageVaultWriteSecret(
    scope: ACTOR
    scopeId: $userId
    name: $tokenName
    value: $userToken
  ) {
    status
  }
}

Delete Secret

mutation DeleteUserToken($userId: ID!, $tokenName: String!) {
  nerdStorageVaultWriteSecret(
    scope: ACTOR
    scopeId: $userId
    name: $tokenName
  ) {
    status
  }
}

UserSecretMutation

Save, delete, or update a user scoped secret.

Write Secret

//retrieve and use a stored secret
import { UserSecretMutation } from '@newrelic/nr1-community';

UserSecretMutation.mutate({
  actionType: UserSecretMutation.ACTION_TYPE.WRITE_SECRET,
  name: 'mysecret',
  value: 'mysecretvalue'
});

Note: Behind the scenes, it populates the required scopeId using an nr1 UserQuery to retrieve the user Id.

Delete Secret

//retrieve and use a stored secret
import { UserSecretMutation } from '@newrelic/nr1-community';

UserSecretMutation.mutate({
  actionType: UserSecretMutation.ACTION_TYPE.DELETE_SECRET,
  name: 'mysecret'
});

Note: Behind the scenes, it populates the required scopeId using an nr1 UserQuery to retrieve the user Id.

Props

prop REQUIRED type description
name TRUE string Name of the secret.
value Only for Write string value content.