-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove HCL-parsing in favour of API-provided JSON
This is written assuming #6017 is merged as-is. It’s trivial to change the property name if needed!
- Loading branch information
Showing
6 changed files
with
73 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,17 +17,17 @@ export default Ability.extend({ | |
|
||
rulesForActiveNamespace: computed( | ||
'activeNamespace', | ||
'token.selfTokenPolicies.@each.namespace' /* FIXME not quite */, | ||
'token.selfTokenPolicies.@each.Namespaces' /* FIXME not quite */, | ||
function() { | ||
const activeNamespace = this.activeNamespace; | ||
|
||
return (this.get('token.selfTokenPolicies') || []).toArray().reduce((rules, policy) => { | ||
const policyNamespaces = getWithDefault(policy, 'rulesJson.namespace', {}); | ||
const policyNamespaces = getWithDefault(policy, 'rulesJSON.Namespaces', []); | ||
|
||
const matchingNamespace = this._findMatchingNamespace(policyNamespaces, activeNamespace); | ||
|
||
if (matchingNamespace) { | ||
rules.push(policyNamespaces[matchingNamespace]); | ||
rules.push(policyNamespaces.find(namespace => namespace.Name === matchingNamespace)); | ||
} | ||
|
||
return rules; | ||
|
@@ -40,20 +40,21 @@ export default Ability.extend({ | |
'[email protected]', | ||
function() { | ||
return this.rulesForActiveNamespace.some(rules => { | ||
const policy = rules.policy; | ||
const capabilities = getWithDefault(rules, 'capabilities', []); | ||
const policy = rules.Policy; | ||
const capabilities = getWithDefault(rules, 'Capabilities', []); | ||
|
||
return policy == 'write' || capabilities.includes('submit-job'); | ||
}); | ||
} | ||
), | ||
|
||
_findMatchingNamespace(policyNamespaces, activeNamespace) { | ||
if (policyNamespaces[activeNamespace]) { | ||
const namespaceNames = policyNamespaces.mapBy('Name'); | ||
|
||
if (namespaceNames.includes(activeNamespace)) { | ||
return activeNamespace; | ||
} | ||
|
||
const namespaceNames = Object.keys(policyNamespaces); | ||
const globNamespaceNames = namespaceNames.filter(namespaceName => namespaceName.includes('*')); | ||
|
||
const matchingNamespaceName = globNamespaceNames.reduce( | ||
|
@@ -80,7 +81,7 @@ export default Ability.extend({ | |
|
||
if (matchingNamespaceName) { | ||
return matchingNamespaceName; | ||
} else if (policyNamespaces.default) { | ||
} else if (namespaceNames.includes('default')) { | ||
return 'default'; | ||
} | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,9 @@ | ||
import Model from 'ember-data/model'; | ||
import attr from 'ember-data/attr'; | ||
import { computed } from '@ember/object'; | ||
import hclToJson from 'hcl-to-json'; | ||
|
||
export default Model.extend({ | ||
name: attr('string'), | ||
description: attr('string'), | ||
rules: attr('string'), | ||
|
||
// FIXME remove if/when API can return rules in JSON | ||
rulesJson: computed('rules', function() { | ||
try { | ||
return hclToJson(this.get('rules')); | ||
} catch (e) { | ||
return null; | ||
} | ||
}), | ||
rulesJSON: attr(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters