Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "feat: IM-1016 add post deploy for azure and gcp (#90)" #92

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions application-templates/javascript/event/src/connector/actions.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
const CUSTOMER_CREATE_SUBSCRIPTION_KEY =
'myconnector-customerCreateSubscription';

export async function createGcpPubSubCustomerCreateSubscription(
export async function createCustomerCreateSubscription(
apiRoot,
topicName,
projectId
) {
const destination = {
type: 'GoogleCloudPubSub',
topic: topicName,
projectId,
};
await createSubscription(apiRoot, destination);
}
const {
body: { results: subscriptions },
} = await apiRoot
.subscriptions()
.get({
queryArgs: {
where: `key = "${CUSTOMER_CREATE_SUBSCRIPTION_KEY}"`,
},
})
.execute();

export async function createAzureServiceBusCustomerCreateSubscription(
apiRoot,
connectionString
) {
const destination = {
type: 'AzureServiceBus',
connectionString: connectionString,
};
await createSubscription(apiRoot, destination);
}
if (subscriptions.length > 0) {
const subscription = subscriptions[0];

await apiRoot
.subscriptions()
.withKey({ key: CUSTOMER_CREATE_SUBSCRIPTION_KEY })
.delete({
queryArgs: {
version: subscription.version,
},
})
.execute();
}

async function createSubscription(apiRoot, destination) {
await deleteCustomerCreateSubscription(apiRoot);
await apiRoot
.subscriptions()
.post({
body: {
key: CUSTOMER_CREATE_SUBSCRIPTION_KEY,
destination,
destination: {
type: 'GoogleCloudPubSub',
topic: topicName,
projectId,
},
messages: [
{
resourceTypeId: 'customer',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,22 @@ dotenv.config();

import { createApiRoot } from '../client/create.client.js';
import { assertError, assertString } from '../utils/assert.utils.js';
import {
createGcpPubSubCustomerCreateSubscription,
createAzureServiceBusCustomerCreateSubscription,
} from './actions.js';
import { createCustomerCreateSubscription } from './actions.js';

const CONNECT_GCP_TOPIC_NAME_KEY = 'CONNECT_GCP_TOPIC_NAME';
const CONNECT_GCP_PROJECT_ID_KEY = 'CONNECT_GCP_PROJECT_ID';
const CONNECT_PROVIDER_KEY = 'CONNECT_PROVIDER';
const CONNECT_AZURE_CONNECTION_STRING_KEY = 'CONNECT_AZURE_CONNECTION_STRING';

async function postDeploy(properties) {
const connectProvider = properties.get(CONNECT_PROVIDER_KEY);
assertString(connectProvider, CONNECT_PROVIDER_KEY);
const apiRoot = createApiRoot();
const topicName = properties.get(CONNECT_GCP_TOPIC_NAME_KEY);
const projectId = properties.get(CONNECT_GCP_PROJECT_ID_KEY);

switch (connectProvider) {
case 'AZURE': {
const connectionString = properties.get(
CONNECT_AZURE_CONNECTION_STRING_KEY
);
assertString(connectionString, CONNECT_AZURE_CONNECTION_STRING_KEY);
await createAzureServiceBusCustomerCreateSubscription(
apiRoot,
connectionString
);
break;
}
default: {
const topicName = properties.get(CONNECT_GCP_TOPIC_NAME_KEY);
const projectId = properties.get(CONNECT_GCP_PROJECT_ID_KEY);
assertString(topicName, CONNECT_GCP_TOPIC_NAME_KEY);
assertString(projectId, CONNECT_GCP_PROJECT_ID_KEY);
await createGcpPubSubCustomerCreateSubscription(
apiRoot,
topicName,
projectId
);
}
}
assertString(topicName, CONNECT_GCP_TOPIC_NAME_KEY);
assertString(projectId, CONNECT_GCP_PROJECT_ID_KEY);

const apiRoot = createApiRoot();
await createCustomerCreateSubscription(apiRoot, topicName, projectId);
}

async function run() {
try {
const properties = new Map(Object.entries(process.env));
Expand Down
58 changes: 29 additions & 29 deletions application-templates/typescript/event/src/connector/actions.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
import {
AzureServiceBusDestination,
Destination,
GoogleCloudPubSubDestination,
} from '@commercetools/platform-sdk';
import { ByProjectKeyRequestBuilder } from '@commercetools/platform-sdk/dist/declarations/src/generated/client/by-project-key-request-builder';

const CUSTOMER_CREATE_SUBSCRIPTION_KEY =
'myconnector-customerCreateSubscription';

export async function createGcpPubSubCustomerCreateSubscription(
export async function createCustomerCreateSubscription(
apiRoot: ByProjectKeyRequestBuilder,
topicName: string,
projectId: string
): Promise<void> {
const destination: GoogleCloudPubSubDestination = {
type: 'GoogleCloudPubSub',
topic: topicName,
projectId,
};
await createSubscription(apiRoot, destination);
}
const {
body: { results: subscriptions },
} = await apiRoot
.subscriptions()
.get({
queryArgs: {
where: `key = "${CUSTOMER_CREATE_SUBSCRIPTION_KEY}"`,
},
})
.execute();

export async function createAzureServiceBusCustomerCreateSubscription(
apiRoot: ByProjectKeyRequestBuilder,
connectionString: string
): Promise<void> {
const destination: AzureServiceBusDestination = {
type: 'AzureServiceBus',
connectionString: connectionString,
};
await createSubscription(apiRoot, destination);
}
if (subscriptions.length > 0) {
const subscription = subscriptions[0];

await apiRoot
.subscriptions()
.withKey({ key: CUSTOMER_CREATE_SUBSCRIPTION_KEY })
.delete({
queryArgs: {
version: subscription.version,
},
})
.execute();
}

async function createSubscription(
apiRoot: ByProjectKeyRequestBuilder,
destination: Destination
) {
await deleteCustomerCreateSubscription(apiRoot);
await apiRoot
.subscriptions()
.post({
body: {
key: CUSTOMER_CREATE_SUBSCRIPTION_KEY,
destination,
destination: {
type: 'GoogleCloudPubSub',
topic: topicName,
projectId,
},
messages: [
{
resourceTypeId: 'customer',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,20 @@ dotenv.config();

import { createApiRoot } from '../client/create.client';
import { assertError, assertString } from '../utils/assert.utils';
import {
createAzureServiceBusCustomerCreateSubscription,
createGcpPubSubCustomerCreateSubscription,
} from './actions';
import { createCustomerCreateSubscription } from './actions';

const CONNECT_GCP_TOPIC_NAME_KEY = 'CONNECT_GCP_TOPIC_NAME';
const CONNECT_GCP_PROJECT_ID_KEY = 'CONNECT_GCP_PROJECT_ID';
const CONNECT_PROVIDER_KEY = 'CONNECT_PROVIDER';
const CONNECT_AZURE_CONNECTION_STRING_KEY = 'CONNECT_AZURE_CONNECTION_STRING';

async function postDeploy(properties: Map<string, unknown>): Promise<void> {
const connectProvider = properties.get(CONNECT_PROVIDER_KEY);
assertString(connectProvider, CONNECT_PROVIDER_KEY);
const apiRoot = createApiRoot();
const topicName = properties.get(CONNECT_GCP_TOPIC_NAME_KEY);
const projectId = properties.get(CONNECT_GCP_PROJECT_ID_KEY);

switch (connectProvider) {
case 'AZURE': {
const connectionString = properties.get(
CONNECT_AZURE_CONNECTION_STRING_KEY
);
assertString(connectionString, CONNECT_AZURE_CONNECTION_STRING_KEY);
await createAzureServiceBusCustomerCreateSubscription(
apiRoot,
connectionString
);
break;
}
default: {
const topicName = properties.get(CONNECT_GCP_TOPIC_NAME_KEY);
const projectId = properties.get(CONNECT_GCP_PROJECT_ID_KEY);
assertString(topicName, CONNECT_GCP_TOPIC_NAME_KEY);
assertString(projectId, CONNECT_GCP_PROJECT_ID_KEY);
await createGcpPubSubCustomerCreateSubscription(
apiRoot,
topicName,
projectId
);
}
}
assertString(topicName, CONNECT_GCP_TOPIC_NAME_KEY);
assertString(projectId, CONNECT_GCP_PROJECT_ID_KEY);

const apiRoot = createApiRoot();
await createCustomerCreateSubscription(apiRoot, topicName, projectId);
}

async function run(): Promise<void> {
Expand Down
Loading