Skip to content

Commit d00cd64

Browse files
committed
revert product subscription cleanup
1 parent 0e395f6 commit d00cd64

2 files changed

Lines changed: 4 additions & 66 deletions

File tree

src/services/product-publisher.ts

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
146105
async 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-
202140
function parseProductGroupDescriptor(
203141
productGroup: Record<string, unknown>,
204142
context: ApimServiceContext

tests/unit/services/product-publisher.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ describe('product-publisher', () => {
283283
expect(result.error?.message).toBe('Unexpected store error');
284284
});
285285

286-
it('deletes auto-generated product subscriptions after product publish', async () => {
286+
it('does not delete auto-generated product subscriptions after product publish', async () => {
287287
const client = createMockClient();
288288
const store = createMockStore();
289289
const autoGeneratedId = generatedSubscriptionId('c');
@@ -305,7 +305,7 @@ describe('product-publisher', () => {
305305
const result = await publishProduct(client, store, testContext, productDescriptor, testConfig);
306306

307307
expect(result.status).toBe('success');
308-
expect(client.deleteResource).toHaveBeenCalledWith(
308+
expect(client.deleteResource).not.toHaveBeenCalledWith(
309309
testContext,
310310
expect.objectContaining({
311311
type: ResourceType.Subscription,
@@ -314,7 +314,7 @@ describe('product-publisher', () => {
314314
);
315315
});
316316

317-
it('deletes product-scoped subscriptions on first product creation regardless of displayName', async () => {
317+
it('does not delete product-scoped subscriptions on first product creation', async () => {
318318
const client = createMockClient();
319319
const store = createMockStore();
320320
client.getResource.mockResolvedValue(undefined);
@@ -335,7 +335,7 @@ describe('product-publisher', () => {
335335
const result = await publishProduct(client, store, testContext, productDescriptor, testConfig);
336336

337337
expect(result.status).toBe('success');
338-
expect(client.deleteResource).toHaveBeenCalledWith(
338+
expect(client.deleteResource).not.toHaveBeenCalledWith(
339339
testContext,
340340
expect.objectContaining({
341341
type: ResourceType.Subscription,

0 commit comments

Comments
 (0)