Commit 51fa201b authored by Alexander Turinske's avatar Alexander Turinske

Conditionally render policy alert editor

- check if any agents have been installed and configured
- show the policy alert picker if an agent has been added,
  do now show it if no agent has been added
- create help urls to guide the user
parent 50b64375
<script> <script>
import { GlAlert, GlButton, GlSprintf } from '@gitlab/ui'; import { GlAlert, GlButton, GlLink, GlSprintf } from '@gitlab/ui';
import getAgentCount from '../../graphql/queries/get_agent_count.query.graphql';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
export default { export default {
...@@ -7,6 +8,9 @@ export default { ...@@ -7,6 +8,9 @@ export default {
ACTION: s__( ACTION: s__(
'NetworkPolicies|%{labelStart}And%{labelEnd} %{spanStart}send an Alert to GitLab.%{spanEnd}', 'NetworkPolicies|%{labelStart}And%{labelEnd} %{spanStart}send an Alert to GitLab.%{spanEnd}',
), ),
AGENT_REQUIRED: s__(
'NetworkPolicies|Please %{installLinkStart}install%{installLinkEnd} and %{configureLinkStart}configure a Kubernetes Agent for this project%{configureLinkEnd} to enable alerts.',
),
BUTTON_LABEL: s__('NetworkPolicies|+ Add alert'), BUTTON_LABEL: s__('NetworkPolicies|+ Add alert'),
HIGH_VOLUME_WARNING: s__( HIGH_VOLUME_WARNING: s__(
`NetworkPolicies|Alerts are intended to be selectively used for a limited number of events that are potentially concerning and warrant a manual review. Alerts should not be used as a substitute for a SIEM or a logging tool. High volume alerts are likely to be dropped so as to preserve the stability of GitLab's integration with Kubernetes.`, `NetworkPolicies|Alerts are intended to be selectively used for a limited number of events that are potentially concerning and warrant a manual review. Alerts should not be used as a substitute for a SIEM or a logging tool. High volume alerts are likely to be dropped so as to preserve the stability of GitLab's integration with Kubernetes.`,
...@@ -15,14 +19,34 @@ export default { ...@@ -15,14 +19,34 @@ export default {
components: { components: {
GlAlert, GlAlert,
GlButton, GlButton,
GlLink,
GlSprintf, GlSprintf,
}, },
inject: ['configureAgentHelpPath', 'createAgentHelpPath', 'projectPath'],
props: { props: {
policyAlert: { policyAlert: {
type: Boolean, type: Boolean,
required: true, required: true,
}, },
}, },
apollo: {
isAgentInstalled: {
query: getAgentCount,
variables() {
return {
projectPath: this.projectPath,
};
},
update(data) {
return Boolean(data?.project?.clusterAgents?.count);
},
},
},
data() {
return {
isAgentInstalled: false,
};
},
}; };
</script> </script>
...@@ -31,15 +55,30 @@ export default { ...@@ -31,15 +55,30 @@ export default {
<gl-alert v-if="policyAlert" variant="warning" :dismissible="false" class="gl-mt-5"> <gl-alert v-if="policyAlert" variant="warning" :dismissible="false" class="gl-mt-5">
{{ $options.i18n.HIGH_VOLUME_WARNING }} {{ $options.i18n.HIGH_VOLUME_WARNING }}
</gl-alert> </gl-alert>
<gl-alert v-if="!isAgentInstalled" variant="danger" :dismissible="false" class="gl-mt-5">
<gl-sprintf :message="$options.i18n.AGENT_REQUIRED">
<template #installLink="{ content }">
<gl-link :href="createAgentHelpPath" target="_blank">
{{ content }}
</gl-link>
</template>
<template #configureLink="{ content }">
<gl-link :href="configureAgentHelpPath" target="_blank">
{{ content }}
</gl-link>
</template>
</gl-sprintf>
</gl-alert>
<div <div
class="gl-bg-gray-10 gl-border-solid gl-border-1 gl-border-gray-100 gl-rounded-base gl-p-5" class="gl-bg-gray-10 gl-border-solid gl-border-1 gl-border-gray-100 gl-rounded-base gl-p-5"
:class="{ 'gl-mt-5': !policyAlert }" :class="{ 'gl-mt-5': !policyAlert && isAgentInstalled }"
> >
<gl-button <gl-button
v-if="!policyAlert" v-if="!policyAlert"
variant="link" variant="link"
category="primary" category="primary"
data-testid="add-alert" data-testid="add-alert"
:disabled="!isAgentInstalled"
@click="$emit('update-alert', !policyAlert)" @click="$emit('update-alert', !policyAlert)"
> >
{{ $options.i18n.BUTTON_LABEL }} {{ $options.i18n.BUTTON_LABEL }}
...@@ -51,9 +90,9 @@ export default { ...@@ -51,9 +90,9 @@ export default {
<span> <span>
<gl-sprintf :message="$options.i18n.ACTION"> <gl-sprintf :message="$options.i18n.ACTION">
<template #label="{ content }"> <template #label="{ content }">
<label for="actionType" class="text-uppercase gl-font-lg gl-mr-4 gl-mb-0">{{ <label for="actionType" class="text-uppercase gl-font-lg gl-mr-4 gl-mb-0">
content {{ content }}
}}</label> </label>
</template> </template>
<template #span="{ content }"> <template #span="{ content }">
<span>{{ content }}</span> <span>{{ content }}</span>
......
query getAgentCount($projectPath: ID!) {
project(fullPath: $projectPath) {
clusterAgents {
count
}
}
}
import Vue from 'vue'; import Vue from 'vue';
import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql';
import PolicyEditorApp from './components/policy_editor/policy_editor.vue'; import PolicyEditorApp from './components/policy_editor/policy_editor.vue';
import createStore from './store'; import createStore from './store';
Vue.use(VueApollo);
const apolloProvider = new VueApollo({
defaultClient: createDefaultClient(),
});
export default () => { export default () => {
const el = document.querySelector('#js-policy-builder-app'); const el = document.querySelector('#js-policy-builder-app');
const { const {
environmentsEndpoint, environmentsEndpoint,
configureAgentHelpPath,
createAgentHelpPath,
networkPoliciesEndpoint, networkPoliciesEndpoint,
threatMonitoringPath, threatMonitoringPath,
policy, policy,
projectPath,
environmentId, environmentId,
} = el.dataset; } = el.dataset;
...@@ -31,6 +42,12 @@ export default () => { ...@@ -31,6 +42,12 @@ export default () => {
return new Vue({ return new Vue({
el, el,
apolloProvider,
provide: {
configureAgentHelpPath,
createAgentHelpPath,
projectPath,
},
store, store,
render(createElement) { render(createElement) {
return createElement(PolicyEditorApp, { props }); return createElement(PolicyEditorApp, { props });
......
...@@ -3,8 +3,11 @@ ...@@ -3,8 +3,11 @@
- page_title s_("NetworkPolicies|Policy editor") - page_title s_("NetworkPolicies|Policy editor")
#js-policy-builder-app{ data: { network_policies_endpoint: project_security_network_policies_path(@project), #js-policy-builder-app{ data: { network_policies_endpoint: project_security_network_policies_path(@project),
configure_agent_help_path: help_page_url('user/clusters/agent/repository.html'),
create_agent_help_path: help_page_url('user/clusters/agent/index.md', anchor: 'create-an-agent-record-in-gitlab'),
environments_endpoint: project_environments_path(@project), environments_endpoint: project_environments_path(@project),
threat_monitoring_path: project_threat_monitoring_path(@project), threat_monitoring_path: project_threat_monitoring_path(@project),
policy: @policy.to_json, policy: @policy.to_json,
project_path: @project.full_path,
environment_id: @environment.id, environment_id: @environment.id,
} } } }
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
- page_title s_("NetworkPolicies|Policy editor") - page_title s_("NetworkPolicies|Policy editor")
#js-policy-builder-app{ data: { network_policies_endpoint: project_security_network_policies_path(@project), #js-policy-builder-app{ data: { network_policies_endpoint: project_security_network_policies_path(@project),
configure_agent_help_path: help_page_url('user/clusters/agent/repository.html'),
create_agent_help_path: help_page_url('user/clusters/agent/index.md', anchor: 'create-an-agent-record-in-gitlab'),
environments_endpoint: project_environments_path(@project), environments_endpoint: project_environments_path(@project),
project_path: @project.full_path,
threat_monitoring_path: project_threat_monitoring_path(@project), threat_monitoring_path: project_threat_monitoring_path(@project),
} } } }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment