|
|
@@ -18,88 +18,29 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
import Reflux from 'reflux';
|
|
|
import Api from '../../components/ApiCaller';
|
|
|
-import {servicesUrl, useSecret} from '../../config';
|
|
|
+import { servicesUrl, useSecret } from '../../config';
|
|
|
|
|
|
let ConnectionsActions = Reflux.createActions({
|
|
|
loadConnections: { children: ['completed', 'failed'] },
|
|
|
loadConnectionDetail: { children: ['completed', 'failed'] },
|
|
|
loadProviders: { children: ['completed', 'failed'] },
|
|
|
loadInstances: { children: ['completed', 'failed'] },
|
|
|
+ newEndpoint: { children: ['success', 'failed'] },
|
|
|
+ saveEndpoint: { children: ['success', 'failed'] },
|
|
|
+ editEndpoint: { children: ['success', 'failed'] },
|
|
|
+ saveEditEndpoint: { children: ['success', 'failed'] },
|
|
|
+ validateConnection: { children: ['success', 'failed'] },
|
|
|
+ deleteConnection: { children: ['completed', 'failed'] },
|
|
|
loadProviderType: {},
|
|
|
assignConnectionProvider: {},
|
|
|
updateProvider: {},
|
|
|
- deleteConnection: { children: ['completed', 'failed'] },
|
|
|
getSourceClouds: {},
|
|
|
getTargetClouds: {},
|
|
|
resetSelections: {},
|
|
|
- newConnection: { children: ['success', 'failed'] },
|
|
|
- saveEndpoint: { children: ['success', 'failed'] },
|
|
|
- editEndpoint: { children: ['success', 'failed'] },
|
|
|
- setConnection: {},
|
|
|
- validateConnection: { children: ['success', 'failed'] }
|
|
|
+ setConnection: {}
|
|
|
})
|
|
|
|
|
|
|
|
|
-ConnectionsActions.loadProviders.listen(() => {
|
|
|
- let projectId = Reflux.GlobalState.userStore.currentUser.project.id
|
|
|
- Api.sendAjaxRequest({
|
|
|
- url: `${servicesUrl.coriolis}/${projectId}/providers`,
|
|
|
- method: "GET"
|
|
|
- }).then(response => {
|
|
|
- ConnectionsActions.loadProviders.completed(response)
|
|
|
- }, ConnectionsActions.loadProviders.failed)
|
|
|
- .catch(ConnectionsActions.loadProviders.failed);
|
|
|
-})
|
|
|
-
|
|
|
-ConnectionsActions.saveEndpoint.listen((data, secretRef) => {
|
|
|
- let projectId = Reflux.GlobalState.userStore.currentUser.project.id
|
|
|
- let payload = null
|
|
|
- if (useSecret) {
|
|
|
- payload = {
|
|
|
- endpoint: {
|
|
|
- name: data.name,
|
|
|
- description: data.description,
|
|
|
- type: data.type,
|
|
|
- connection_info: {
|
|
|
- secret_ref: secretRef
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- payload = { endpoint: data }
|
|
|
- }
|
|
|
-
|
|
|
- Api.sendAjaxRequest({
|
|
|
- url: `${servicesUrl.coriolis}/${projectId}/endpoints`,
|
|
|
- method: "POST",
|
|
|
- data: payload
|
|
|
- }).then(ConnectionsActions.saveEndpoint.success, ConnectionsActions.saveEndpoint.failed)
|
|
|
- .catch(ConnectionsActions.saveEndpoint.failed);
|
|
|
-})
|
|
|
-
|
|
|
-ConnectionsActions.newConnection.listen((data) => {
|
|
|
- if (useSecret) {
|
|
|
- let barbicanPayload = {
|
|
|
- payload: JSON.stringify(data.connection_info),
|
|
|
- payload_content_type: "text/plain",
|
|
|
- content_types: {
|
|
|
- default: "text/plain"
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Api.sendAjaxRequest({
|
|
|
- url: servicesUrl.barbican + "/v1/secrets",
|
|
|
- method: "POST",
|
|
|
- data: barbicanPayload
|
|
|
- }).then((response) => {
|
|
|
- ConnectionsActions.newConnection.success(response, data)
|
|
|
- }, ConnectionsActions.newConnection.failed)
|
|
|
- .catch(ConnectionsActions.newConnection.failed);
|
|
|
- } else {
|
|
|
- ConnectionsActions.saveEndpoint(data)
|
|
|
- }
|
|
|
-});
|
|
|
-
|
|
|
ConnectionsActions.loadConnections.listen(() => {
|
|
|
let projectId = Reflux.GlobalState.userStore.currentUser.project.id
|
|
|
if (projectId) {
|
|
|
@@ -116,28 +57,18 @@ ConnectionsActions.loadConnections.shouldEmit = () => {
|
|
|
return typeof projectId !== "undefined"
|
|
|
}
|
|
|
|
|
|
-ConnectionsActions.deleteConnection.listen((connection) => {
|
|
|
+ConnectionsActions.loadProviders.listen(() => {
|
|
|
let projectId = Reflux.GlobalState.userStore.currentUser.project.id
|
|
|
-
|
|
|
Api.sendAjaxRequest({
|
|
|
- url: `${servicesUrl.coriolis}/${projectId}/endpoints/${connection.id}`,
|
|
|
- method: "DELETE"
|
|
|
- }).then(() => {
|
|
|
- if (connection.connection_info && connection.connection_info.secret_ref) {
|
|
|
- let uuidIndex = connection.connection_info.secret_ref.lastIndexOf("/")
|
|
|
- let uuid = connection.connection_info.secret_ref.substr(uuidIndex + 1)
|
|
|
- Api.sendAjaxRequest({
|
|
|
- url: servicesUrl.barbican + "/v1/secrets/" + uuid,
|
|
|
- method: "DELETE"
|
|
|
- }).then(ConnectionsActions.deleteConnection.completed(connection), ConnectionsActions.deleteConnection.failed)
|
|
|
- } else {
|
|
|
- ConnectionsActions.deleteConnection.completed(connection)
|
|
|
- }
|
|
|
- }, ConnectionsActions.deleteConnection.failed)
|
|
|
- .catch(ConnectionsActions.deleteConnection.failed);
|
|
|
+ url: `${servicesUrl.coriolis}/${projectId}/providers`,
|
|
|
+ method: "GET"
|
|
|
+ }).then(response => {
|
|
|
+ ConnectionsActions.loadProviders.completed(response)
|
|
|
+ }, ConnectionsActions.loadProviders.failed)
|
|
|
+ .catch(ConnectionsActions.loadProviders.failed);
|
|
|
})
|
|
|
|
|
|
-ConnectionsActions.editEndpointSecret.listen((data) => {
|
|
|
+ConnectionsActions.newEndpoint.listen((data) => {
|
|
|
if (useSecret) {
|
|
|
let barbicanPayload = {
|
|
|
payload: JSON.stringify(data.connection_info),
|
|
|
@@ -152,31 +83,25 @@ ConnectionsActions.editEndpointSecret.listen((data) => {
|
|
|
method: "POST",
|
|
|
data: barbicanPayload
|
|
|
}).then((response) => {
|
|
|
- ConnectionsActions.newConnection.success(response, data)
|
|
|
- }, ConnectionsActions.newConnection.failed)
|
|
|
- .catch(ConnectionsActions.newConnection.failed);
|
|
|
+ ConnectionsActions.newEndpoint.success(response, data)
|
|
|
+ }, ConnectionsActions.newEndpoint.failed)
|
|
|
+ .catch(ConnectionsActions.newEndpoint.failed);
|
|
|
} else {
|
|
|
ConnectionsActions.saveEndpoint(data)
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-ConnectionsActions.editEndpoint.listen((connection, data) => {
|
|
|
+ConnectionsActions.saveEndpoint.listen((data, secretRef) => {
|
|
|
let projectId = Reflux.GlobalState.userStore.currentUser.project.id
|
|
|
let payload = null
|
|
|
- if (connection.connection_info && connection.connection_info.secret_ref) {
|
|
|
- let uuidIndex = connection.connection_info.secret_ref.lastIndexOf("/")
|
|
|
- let uuid = connection.connection_info.secret_ref.substr(uuidIndex + 1)
|
|
|
-
|
|
|
- Api.sendAjaxRequest({
|
|
|
- url: servicesUrl.barbican + "/v1/secrets/" + uuid,
|
|
|
- method: "POST"
|
|
|
- })
|
|
|
+ if (useSecret) {
|
|
|
payload = {
|
|
|
endpoint: {
|
|
|
name: data.name,
|
|
|
description: data.description,
|
|
|
+ type: data.type,
|
|
|
connection_info: {
|
|
|
- secret_ref: connection.connection_info.secret_ref
|
|
|
+ secret_ref: secretRef
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -185,46 +110,65 @@ ConnectionsActions.editEndpoint.listen((connection, data) => {
|
|
|
}
|
|
|
|
|
|
Api.sendAjaxRequest({
|
|
|
- url: `${servicesUrl.coriolis}/${projectId}/endpoints/${connection.id}`,
|
|
|
- method: "PUT",
|
|
|
+ url: `${servicesUrl.coriolis}/${projectId}/endpoints`,
|
|
|
+ method: "POST",
|
|
|
data: payload
|
|
|
- }).then(ConnectionsActions.editEndpoint.success, ConnectionsActions.editEndpoint.failed)
|
|
|
- .catch(ConnectionsActions.editEndpoint.failed);
|
|
|
+ }).then(ConnectionsActions.saveEndpoint.success, ConnectionsActions.saveEndpoint.failed)
|
|
|
+ .catch(ConnectionsActions.saveEndpoint.failed);
|
|
|
})
|
|
|
|
|
|
-ConnectionsActions.editEndpoint.listen((connection, data) => {
|
|
|
- let projectId = Reflux.GlobalState.userStore.currentUser.project.id
|
|
|
- let payload = null
|
|
|
+ConnectionsActions.editEndpoint.listen((connection, data, callback = null) => {
|
|
|
if (connection.connection_info && connection.connection_info.secret_ref) {
|
|
|
let uuidIndex = connection.connection_info.secret_ref.lastIndexOf("/")
|
|
|
let uuid = connection.connection_info.secret_ref.substr(uuidIndex + 1)
|
|
|
-
|
|
|
Api.sendAjaxRequest({
|
|
|
url: servicesUrl.barbican + "/v1/secrets/" + uuid,
|
|
|
- method: "POST"
|
|
|
+ method: "DELETE"
|
|
|
})
|
|
|
- payload = {
|
|
|
- endpoint: {
|
|
|
- name: data.name,
|
|
|
- description: data.description,
|
|
|
- connection_info: {
|
|
|
- secret_ref: connection.connection_info.secret_ref
|
|
|
- }
|
|
|
+ let barbicanPayload = {
|
|
|
+ payload: JSON.stringify(data.connection_info),
|
|
|
+ payload_content_type: "text/plain",
|
|
|
+ content_types: {
|
|
|
+ default: "text/plain"
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ Api.sendAjaxRequest({
|
|
|
+ url: servicesUrl.barbican + "/v1/secrets",
|
|
|
+ method: "POST",
|
|
|
+ data: barbicanPayload
|
|
|
+ }).then((response) => {
|
|
|
+ ConnectionsActions.editEndpoint.success(response, connection, data, callback)
|
|
|
+ }, ConnectionsActions.editEndpoint.failed)
|
|
|
+ .catch(ConnectionsActions.editEndpoint.failed);
|
|
|
} else {
|
|
|
- payload = { endpoint: data }
|
|
|
+ ConnectionsActions.saveEditEndpoint(connection, data, callback)
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+ConnectionsActions.saveEditEndpoint.listen((connection, data, callback = null) => {
|
|
|
+ let projectId = Reflux.GlobalState.userStore.currentUser.project.id
|
|
|
+ let payload = {
|
|
|
+ endpoint: {
|
|
|
+ name: data.name,
|
|
|
+ description: data.description,
|
|
|
+ connection_info: data.connection_info
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
Api.sendAjaxRequest({
|
|
|
url: `${servicesUrl.coriolis}/${projectId}/endpoints/${connection.id}`,
|
|
|
method: "PUT",
|
|
|
data: payload
|
|
|
- }).then(ConnectionsActions.editEndpoint.success, ConnectionsActions.editEndpoint.failed)
|
|
|
- .catch(ConnectionsActions.editEndpoint.failed);
|
|
|
+ }).then((response) => {
|
|
|
+ ConnectionsActions.saveEditEndpoint.success(response)
|
|
|
+ if (callback) {
|
|
|
+ callback()
|
|
|
+ }
|
|
|
+ }, ConnectionsActions.saveEditEndpoint.failed)
|
|
|
+ .catch(ConnectionsActions.saveEditEndpoint.failed);
|
|
|
})
|
|
|
|
|
|
-
|
|
|
ConnectionsActions.validateConnection.listen((endpoint, callback) => {
|
|
|
let projectId = Reflux.GlobalState.userStore.currentUser.project.id
|
|
|
Api.sendAjaxRequest({
|
|
|
@@ -240,4 +184,26 @@ ConnectionsActions.validateConnection.listen((endpoint, callback) => {
|
|
|
.catch(ConnectionsActions.validateConnection.failed);
|
|
|
})
|
|
|
|
|
|
+
|
|
|
+ConnectionsActions.deleteConnection.listen((connection) => {
|
|
|
+ let projectId = Reflux.GlobalState.userStore.currentUser.project.id
|
|
|
+
|
|
|
+ Api.sendAjaxRequest({
|
|
|
+ url: `${servicesUrl.coriolis}/${projectId}/endpoints/${connection.id}`,
|
|
|
+ method: "DELETE"
|
|
|
+ }).then(() => {
|
|
|
+ if (connection.connection_info && connection.connection_info.secret_ref) {
|
|
|
+ let uuidIndex = connection.connection_info.secret_ref.lastIndexOf("/")
|
|
|
+ let uuid = connection.connection_info.secret_ref.substr(uuidIndex + 1)
|
|
|
+ Api.sendAjaxRequest({
|
|
|
+ url: servicesUrl.barbican + "/v1/secrets/" + uuid,
|
|
|
+ method: "DELETE"
|
|
|
+ }).then(ConnectionsActions.deleteConnection.completed(connection), ConnectionsActions.deleteConnection.failed)
|
|
|
+ } else {
|
|
|
+ ConnectionsActions.deleteConnection.completed(connection)
|
|
|
+ }
|
|
|
+ }, ConnectionsActions.deleteConnection.failed)
|
|
|
+ .catch(ConnectionsActions.deleteConnection.failed);
|
|
|
+})
|
|
|
+
|
|
|
export default ConnectionsActions;
|