33 * or more contributor license agreements. Licensed under the Elastic License; 
44 * you may not use this file except in compliance with the Elastic License. 
55 */ 
6+ 
7+ import  Boom  from  'boom' ; 
68import  *  as  t  from  'io-ts' ; 
79import  {  pick  }  from  'lodash' ; 
10+ import  {  INVALID_LICENSE  }  from  '../../../common/custom_link' ; 
11+ import  {  ILicense  }  from  '../../../../licensing/common/types' ; 
812import  {  FILTER_OPTIONS  }  from  '../../../common/custom_link/custom_link_filter_options' ; 
13+ import  {  notifyFeatureUsage  }  from  '../../feature' ; 
914import  {  setupRequest  }  from  '../../lib/helpers/setup_request' ; 
1015import  {  createOrUpdateCustomLink  }  from  '../../lib/settings/custom_link/create_or_update_custom_link' ; 
1116import  { 
@@ -17,6 +22,10 @@ import { getTransaction } from '../../lib/settings/custom_link/get_transaction';
1722import  {  listCustomLinks  }  from  '../../lib/settings/custom_link/list_custom_links' ; 
1823import  {  createRoute  }  from  '../create_route' ; 
1924
25+ function  isActiveGoldLicense ( license : ILicense )  { 
26+   return  license . isActive  &&  license . hasAtLeast ( 'gold' ) ; 
27+ } 
28+ 
2029export  const  customLinkTransactionRoute  =  createRoute ( ( )  =>  ( { 
2130  path : '/api/apm/settings/custom_links/transaction' , 
2231  params : { 
@@ -37,6 +46,9 @@ export const listCustomLinksRoute = createRoute(() => ({
3746    query : filterOptionsRt , 
3847  } , 
3948  handler : async  ( {  context,  request } )  =>  { 
49+     if  ( ! isActiveGoldLicense ( context . licensing . license ) )  { 
50+       throw  Boom . forbidden ( INVALID_LICENSE ) ; 
51+     } 
4052    const  setup  =  await  setupRequest ( context ,  request ) ; 
4153    const  {  query }  =  context . params ; 
4254    // picks only the items listed in FILTER_OPTIONS 
@@ -55,9 +67,17 @@ export const createCustomLinkRoute = createRoute(() => ({
5567    tags : [ 'access:apm' ,  'access:apm_write' ] , 
5668  } , 
5769  handler : async  ( {  context,  request } )  =>  { 
70+     if  ( ! isActiveGoldLicense ( context . licensing . license ) )  { 
71+       throw  Boom . forbidden ( INVALID_LICENSE ) ; 
72+     } 
5873    const  setup  =  await  setupRequest ( context ,  request ) ; 
5974    const  customLink  =  context . params . body ; 
6075    const  res  =  await  createOrUpdateCustomLink ( {  customLink,  setup } ) ; 
76+ 
77+     notifyFeatureUsage ( { 
78+       licensingPlugin : context . licensing , 
79+       featureName : 'customLinks' , 
80+     } ) ; 
6181    return  res ; 
6282  } , 
6383} ) ) ; 
@@ -75,6 +95,9 @@ export const updateCustomLinkRoute = createRoute(() => ({
7595    tags : [ 'access:apm' ,  'access:apm_write' ] , 
7696  } , 
7797  handler : async  ( {  context,  request } )  =>  { 
98+     if  ( ! isActiveGoldLicense ( context . licensing . license ) )  { 
99+       throw  Boom . forbidden ( INVALID_LICENSE ) ; 
100+     } 
78101    const  setup  =  await  setupRequest ( context ,  request ) ; 
79102    const  {  id }  =  context . params . path ; 
80103    const  customLink  =  context . params . body ; 
@@ -99,6 +122,9 @@ export const deleteCustomLinkRoute = createRoute(() => ({
99122    tags : [ 'access:apm' ,  'access:apm_write' ] , 
100123  } , 
101124  handler : async  ( {  context,  request } )  =>  { 
125+     if  ( ! isActiveGoldLicense ( context . licensing . license ) )  { 
126+       throw  Boom . forbidden ( INVALID_LICENSE ) ; 
127+     } 
102128    const  setup  =  await  setupRequest ( context ,  request ) ; 
103129    const  {  id }  =  context . params . path ; 
104130    const  res  =  await  deleteCustomLink ( { 
0 commit comments