1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import {Client} from 'sentry/api';
- import {Applications, MethodType, PiiConfig, Rule, RuleType} from './types';
- function getSubmitFormatRule(rule: Rule): PiiConfig {
- if (rule.type === RuleType.PATTERN && rule.method === MethodType.REPLACE) {
- return {
- type: rule.type,
- pattern: rule.pattern,
- redaction: {
- method: rule.method,
- text: rule?.placeholder,
- },
- };
- }
- if (rule.type === RuleType.PATTERN) {
- return {
- type: rule.type,
- pattern: rule.pattern,
- redaction: {
- method: rule.method,
- },
- };
- }
- if (rule.method === MethodType.REPLACE) {
- return {
- type: rule.type,
- redaction: {
- method: rule.method,
- text: rule?.placeholder,
- },
- };
- }
- return {
- type: rule.type,
- redaction: {
- method: rule.method,
- },
- };
- }
- function submitRules(api: Client, endpoint: string, rules: Array<Rule>) {
- const applications: Applications = {};
- const submitFormatRules: Record<string, PiiConfig> = {};
- for (let i = 0; i < rules.length; i++) {
- const rule = rules[i];
- const ruleId = String(i);
- submitFormatRules[ruleId] = getSubmitFormatRule(rule);
- if (!applications[rule.source]) {
- applications[rule.source] = [];
- }
- if (!applications[rule.source].includes(ruleId)) {
- applications[rule.source].push(ruleId);
- }
- }
- const piiConfig = {rules: submitFormatRules, applications};
- return api.requestPromise(endpoint, {
- method: 'PUT',
- data: {relayPiiConfig: JSON.stringify(piiConfig)},
- });
- }
- export default submitRules;
|