Skip to content

Commit

Permalink
Allow user to specify cm key to use as LD key (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
alewitt2 authored and adamkingit committed Oct 24, 2019
1 parent fa8a17b commit 04b952a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ metadata:
spec:
sdk-key: oneOf [launch_darkly_sdk_key string, valueFrom.secretKeyRef]
identity: "<ConfigMap name>"
identity-key: "<key from identity to use as LD user key>"
```
### Required Fields
Expand Down Expand Up @@ -101,6 +102,17 @@ Optional field details:
to use as your identity, specifying this will parse the JSON and use all the items
in the JSON as part of the identity.

#### Identity-Key

`.spec.identity-key`

If you need to specify a specific key to use as the user key in LaunchDarkly, this
allows you to identify the key in the identity ConfigMap to use.

- Schema:
- type: string
- default: ffsld's namespace uid

### Managed Resource Labels

#### Reconcile
Expand Down
29 changes: 22 additions & 7 deletions src/FeatureFlagSetLDController.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,20 @@ module.exports = class FeatureFlagSetLDController extends BaseController {
objectPath.set(clients, [sdkkey, 'connections', this.namespace, this.name], {});
}


let namespaceID = await this.kubeResourceMeta.request({ uri: `/api/v1/namespaces/${this.namespace}`, json: true });
namespaceID = objectPath.get(namespaceID, 'metadata.uid');
let identity = await this.assembleIdentity();
let user = { key: namespaceID, custom: identity };
let identityKey = objectPath.get(this.data, ['object', 'spec', 'identity-key']);

let userID = objectPath.get(identity, [identityKey]);
if (!userID) {
if (identityKey) {
let msg = `Key '${identityKey}' not found in identity ConfigMap.. defaulting to Namespace UID.`;
this.log.warn(msg);
this.updateRazeeLogs('warn', { controller: 'FeatureFlagSetLD', warn: msg });
}
let namespace = await this.kubeResourceMeta.request({ uri: `/api/v1/namespaces/${this.namespace}`, json: true });
userID = objectPath.get(namespace, 'metadata.uid');
}
let user = { key: userID, custom: identity };
client.identify(user);
let variation = await client.allFlagsState(user);

Expand Down Expand Up @@ -146,16 +155,22 @@ module.exports = class FeatureFlagSetLDController extends BaseController {
if (identityData) {
switch (type) {
case 'number':
identityData = {[key]: Number(identityData)};
identityData = {
[key]: Number(identityData)
};
break;
case 'boolean':
identityData = {[key]: Boolean(identityData)};
identityData = {
[key]: Boolean(identityData)
};
break;
case 'json':
identityData = JSON.parse(identityData);
break;
default:
identityData = {[key]: identityData};
identityData = {
[key]: identityData
};
break;
}
}
Expand Down

0 comments on commit 04b952a

Please sign in to comment.