open-nomad/ui/app/abilities/agent.js
2023-04-10 15:36:59 +00:00

28 lines
717 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import AbstractAbility from './abstract';
import { computed, get } from '@ember/object';
import { or } from '@ember/object/computed';
export default class Client extends AbstractAbility {
@or(
'bypassAuthorization',
'selfTokenIsManagement',
'policiesIncludeAgentReadOrWrite'
)
canRead;
@computed('token.selfTokenPolicies.[]')
get policiesIncludeAgentReadOrWrite() {
const policies = (get(this, 'token.selfTokenPolicies') || [])
.toArray()
.map((policy) => get(policy, 'rulesJSON.Agent.Policy'))
.compact();
return policies.some((policy) => policy === 'read' || policy === 'write');
}
}