@@ -99,50 +99,9 @@ async function cleanupAutoCreatedProductResources(
9999 context : ApimServiceContext ,
100100 productDescriptor : ResourceDescriptor
101101) : Promise < void > {
102- await cleanupProductSubscriptions ( client , context , productDescriptor ) ;
103102 await cleanupProductGroups ( client , context , productDescriptor ) ;
104103}
105104
106- async function cleanupProductSubscriptions (
107- client : IApimClient ,
108- context : ApimServiceContext ,
109- productDescriptor : ResourceDescriptor
110- ) : Promise < void > {
111- const productName = getNamePart ( productDescriptor . nameParts , 0 ) ;
112- const expectedScopeSuffix = `/products/${ productName } ` ;
113-
114- let deleted = 0 ;
115-
116- for await ( const subscription of client . listResources ( context , ResourceType . Subscription ) ) {
117- const descriptor = parseSubscriptionDescriptor ( subscription , context ) ;
118- if ( ! descriptor || descriptor . workspace !== productDescriptor . workspace ) {
119- continue ;
120- }
121-
122- const props = subscription . properties as Record < string , unknown > | undefined ;
123- const scope = typeof props ?. scope === 'string' ? props . scope : '' ;
124- if ( ! scope . endsWith ( expectedScopeSuffix ) ) {
125- continue ;
126- }
127-
128- try {
129- const removed = await client . deleteResource ( context , descriptor ) ;
130- if ( removed ) {
131- deleted ++ ;
132- logger . debug ( `Deleted APIM auto-created product subscription: ${ descriptor . nameParts [ 0 ] } ` ) ;
133- }
134- } catch ( error ) {
135- logger . warn (
136- `Failed to delete APIM auto-created product subscription ${ descriptor . nameParts [ 0 ] } : ${ String ( error ) } `
137- ) ;
138- }
139- }
140-
141- if ( deleted > 0 ) {
142- logger . info ( `Deleted ${ deleted } auto-created subscription(s) for product: ${ productName } ` ) ;
143- }
144- }
145-
146105async function cleanupProductGroups (
147106 client : IApimClient ,
148107 context : ApimServiceContext ,
@@ -178,27 +137,6 @@ async function cleanupProductGroups(
178137 }
179138}
180139
181- function parseSubscriptionDescriptor (
182- subscription : Record < string , unknown > ,
183- context : ApimServiceContext
184- ) : ResourceDescriptor | undefined {
185- if ( typeof subscription . id === 'string' ) {
186- const parsed = parseArmUri ( subscription . id , context ) ;
187- if ( parsed ?. type === ResourceType . Subscription ) {
188- return parsed ;
189- }
190- }
191-
192- if ( typeof subscription . name === 'string' && subscription . name . length > 0 ) {
193- return {
194- type : ResourceType . Subscription ,
195- nameParts : [ subscription . name ] ,
196- } ;
197- }
198-
199- return undefined ;
200- }
201-
202140function parseProductGroupDescriptor (
203141 productGroup : Record < string , unknown > ,
204142 context : ApimServiceContext
0 commit comments