|
@@ -14,7 +14,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
// @flow
|
|
// @flow
|
|
|
|
|
|
|
|
-import cookie from 'js-cookie'
|
|
|
|
|
import moment from 'moment'
|
|
import moment from 'moment'
|
|
|
|
|
|
|
|
import Api from '../utils/ApiCaller'
|
|
import Api from '../utils/ApiCaller'
|
|
@@ -39,46 +38,33 @@ let getBarbicanPayload = data => {
|
|
|
|
|
|
|
|
class EdnpointSource {
|
|
class EdnpointSource {
|
|
|
static getEndpoints(): Promise<Endpoint[]> {
|
|
static getEndpoints(): Promise<Endpoint[]> {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
|
- let projectId = cookie.get('projectId')
|
|
|
|
|
- if (projectId) {
|
|
|
|
|
- Api.get(`${servicesUrl.coriolis}/${projectId}/endpoints`).then(response => {
|
|
|
|
|
- let connections = []
|
|
|
|
|
- if (response.data.endpoints.length) {
|
|
|
|
|
- response.data.endpoints.forEach(endpoint => {
|
|
|
|
|
- connections.push(endpoint)
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- connections.sort((c1, c2) => moment(c2.created_at).diff(moment(c1.created_at)))
|
|
|
|
|
-
|
|
|
|
|
- resolve(connections)
|
|
|
|
|
- }).catch(reject)
|
|
|
|
|
- } else {
|
|
|
|
|
- reject()
|
|
|
|
|
|
|
+ return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/endpoints`).then(response => {
|
|
|
|
|
+ let connections = []
|
|
|
|
|
+ if (response.data.endpoints.length) {
|
|
|
|
|
+ response.data.endpoints.forEach(endpoint => {
|
|
|
|
|
+ connections.push(endpoint)
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ connections.sort((c1, c2) => moment(c2.created_at).diff(moment(c1.created_at)))
|
|
|
|
|
+ return connections
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
static delete(endpoint: Endpoint): Promise<string> {
|
|
static delete(endpoint: Endpoint): Promise<string> {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
|
- let projectId: any = cookie.get('projectId')
|
|
|
|
|
-
|
|
|
|
|
- Api.send({
|
|
|
|
|
- url: `${servicesUrl.coriolis}/${projectId}/endpoints/${endpoint.id}`,
|
|
|
|
|
- method: 'DELETE',
|
|
|
|
|
- }).then(() => {
|
|
|
|
|
- if (endpoint.connection_info && endpoint.connection_info.secret_ref) {
|
|
|
|
|
- let uuidIndex = endpoint.connection_info.secret_ref.lastIndexOf('/')
|
|
|
|
|
- // $FlowIssue
|
|
|
|
|
- let uuid = endpoint.connection_info.secret_ref.substr(uuidIndex + 1)
|
|
|
|
|
- Api.send({
|
|
|
|
|
- url: `${servicesUrl.barbican}/v1/secrets/${uuid}`,
|
|
|
|
|
- method: 'DELETE',
|
|
|
|
|
- }).then(() => { resolve(endpoint.id) }).catch(reject)
|
|
|
|
|
- } else {
|
|
|
|
|
- resolve(endpoint.id)
|
|
|
|
|
- }
|
|
|
|
|
- }).catch(reject)
|
|
|
|
|
|
|
+ return Api.send({
|
|
|
|
|
+ url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpoint.id}`,
|
|
|
|
|
+ method: 'DELETE',
|
|
|
|
|
+ }).then(() => {
|
|
|
|
|
+ if (endpoint.connection_info && endpoint.connection_info.secret_ref) {
|
|
|
|
|
+ let uuidIndex = endpoint.connection_info.secret_ref.lastIndexOf('/')
|
|
|
|
|
+ // $FlowIssue
|
|
|
|
|
+ let uuid = endpoint.connection_info.secret_ref.substr(uuidIndex + 1)
|
|
|
|
|
+ return Api.send({
|
|
|
|
|
+ url: `${servicesUrl.barbican}/v1/secrets/${uuid}`,
|
|
|
|
|
+ method: 'DELETE',
|
|
|
|
|
+ }).then(() => { return endpoint.id })
|
|
|
|
|
+ }
|
|
|
|
|
+ return endpoint.id
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -90,175 +76,149 @@ class EdnpointSource {
|
|
|
return Promise.resolve(endpoint.connection_info)
|
|
return Promise.resolve(endpoint.connection_info)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
|
- Api.send({
|
|
|
|
|
- url: `${servicesUrl.barbican}/v1/secrets/${uuid || 'undefined'}/payload`,
|
|
|
|
|
- responseType: 'text',
|
|
|
|
|
- headers: { Accept: 'text/plain' },
|
|
|
|
|
- }).then((response) => {
|
|
|
|
|
- resolve(response.data)
|
|
|
|
|
- }).catch(reject)
|
|
|
|
|
|
|
+ return Api.send({
|
|
|
|
|
+ url: `${servicesUrl.barbican}/v1/secrets/${uuid || 'undefined'}/payload`,
|
|
|
|
|
+ responseType: 'text',
|
|
|
|
|
+ headers: { Accept: 'text/plain' },
|
|
|
|
|
+ }).then((response) => {
|
|
|
|
|
+ return response.data
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static getConnectionsInfo(endpoints: Endpoint[]): Promise<Endpoint[]> {
|
|
static getConnectionsInfo(endpoints: Endpoint[]): Promise<Endpoint[]> {
|
|
|
- return new Promise(resolve => {
|
|
|
|
|
- if (!endpoints || endpoints.length === 0) {
|
|
|
|
|
- resolve([])
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- let count = 0
|
|
|
|
|
- let connectionsInfo = []
|
|
|
|
|
- let isDone = () => {
|
|
|
|
|
- count += 1
|
|
|
|
|
- if (count === endpoints.length) {
|
|
|
|
|
- resolve(connectionsInfo)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- endpoints.forEach(endpoint => {
|
|
|
|
|
- let index = endpoint.connection_info.secret_ref ? endpoint.connection_info.secret_ref.lastIndexOf('/') : ''
|
|
|
|
|
- let uuid = endpoint.connection_info.secret_ref && index ? endpoint.connection_info.secret_ref.substr(index + 1) : ''
|
|
|
|
|
- Api.send({
|
|
|
|
|
- url: `${servicesUrl.barbican}/v1/secrets/${uuid}/payload`,
|
|
|
|
|
- responseType: 'text',
|
|
|
|
|
- headers: { Accept: 'text/plain' },
|
|
|
|
|
- }).then(response => {
|
|
|
|
|
- connectionsInfo.push({ ...endpoint, connection_info: response.data })
|
|
|
|
|
- isDone()
|
|
|
|
|
- }, isDone).catch(isDone)
|
|
|
|
|
|
|
+ return Promise.all(endpoints.map(endpoint => {
|
|
|
|
|
+ let index = endpoint.connection_info.secret_ref ? endpoint.connection_info.secret_ref.lastIndexOf('/') : ''
|
|
|
|
|
+ let uuid = endpoint.connection_info.secret_ref && index ? endpoint.connection_info.secret_ref.substr(index + 1) : ''
|
|
|
|
|
+ return Api.send({
|
|
|
|
|
+ url: `${servicesUrl.barbican}/v1/secrets/${uuid}/payload`,
|
|
|
|
|
+ responseType: 'text',
|
|
|
|
|
+ headers: { Accept: 'text/plain' },
|
|
|
|
|
+ }).then(response => {
|
|
|
|
|
+ return { ...endpoint, connection_info: response.data }
|
|
|
})
|
|
})
|
|
|
- })
|
|
|
|
|
|
|
+ }))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static validate(endpoint: Endpoint): Promise<Validation> {
|
|
static validate(endpoint: Endpoint): Promise<Validation> {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
|
- let projectId = cookie.get('projectId')
|
|
|
|
|
- Api.send({
|
|
|
|
|
- url: `${servicesUrl.coriolis}/${projectId || ''}/endpoints/${endpoint.id}/actions`,
|
|
|
|
|
- method: 'POST',
|
|
|
|
|
- data: { 'validate-connection': null },
|
|
|
|
|
- }).then(response => {
|
|
|
|
|
- resolve(response.data['validate-connection'])
|
|
|
|
|
- }).catch(reject)
|
|
|
|
|
|
|
+ return Api.send({
|
|
|
|
|
+ url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpoint.id}/actions`,
|
|
|
|
|
+ method: 'POST',
|
|
|
|
|
+ data: { 'validate-connection': null },
|
|
|
|
|
+ }).then(response => {
|
|
|
|
|
+ return response.data['validate-connection']
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static update(endpoint: Endpoint): Promise<Endpoint> {
|
|
static update(endpoint: Endpoint): Promise<Endpoint> {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
|
- let projectId = cookie.get('projectId')
|
|
|
|
|
- let parsedEndpoint = SchemaParser.fieldsToPayload(endpoint)
|
|
|
|
|
-
|
|
|
|
|
- if (parsedEndpoint.connection_info && parsedEndpoint.connection_info.secret_ref) {
|
|
|
|
|
- // $FlowIgnore
|
|
|
|
|
- let uuidIndex = parsedEndpoint.connection_info.secret_ref.lastIndexOf('/')
|
|
|
|
|
- // $FlowIgnore
|
|
|
|
|
- let uuid = parsedEndpoint.connection_info.secret_ref.substr(uuidIndex + 1)
|
|
|
|
|
-
|
|
|
|
|
- Api.send({
|
|
|
|
|
- url: `${servicesUrl.barbican}/v1/secrets/${uuid}`,
|
|
|
|
|
- method: 'DELETE',
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- Api.send({
|
|
|
|
|
|
|
+ let parsedEndpoint = SchemaParser.fieldsToPayload(endpoint)
|
|
|
|
|
+
|
|
|
|
|
+ if (parsedEndpoint.connection_info && parsedEndpoint.connection_info.secret_ref) {
|
|
|
|
|
+ // $FlowIgnore
|
|
|
|
|
+ let uuidIndex = parsedEndpoint.connection_info.secret_ref.lastIndexOf('/')
|
|
|
|
|
+ // $FlowIgnore
|
|
|
|
|
+ let uuid = parsedEndpoint.connection_info.secret_ref.substr(uuidIndex + 1)
|
|
|
|
|
+ let newEndpoint: any = {}
|
|
|
|
|
+ let connectionInfo = {}
|
|
|
|
|
+ return Api.send({
|
|
|
|
|
+ url: `${servicesUrl.barbican}/v1/secrets/${uuid}`,
|
|
|
|
|
+ method: 'DELETE',
|
|
|
|
|
+ }).then(() => {
|
|
|
|
|
+ return Api.send({
|
|
|
url: `${servicesUrl.barbican}/v1/secrets`,
|
|
url: `${servicesUrl.barbican}/v1/secrets`,
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
|
data: getBarbicanPayload(ObjectUtils.skipField(parsedEndpoint.connection_info, 'secret_ref')),
|
|
data: getBarbicanPayload(ObjectUtils.skipField(parsedEndpoint.connection_info, 'secret_ref')),
|
|
|
- }).then(response => {
|
|
|
|
|
- let connectionInfo = { secret_ref: response.data.secret_ref }
|
|
|
|
|
- let newPayload = {
|
|
|
|
|
- endpoint: {
|
|
|
|
|
- name: parsedEndpoint.name,
|
|
|
|
|
- description: parsedEndpoint.description,
|
|
|
|
|
- connection_info: connectionInfo,
|
|
|
|
|
- },
|
|
|
|
|
- }
|
|
|
|
|
- Api.send({
|
|
|
|
|
- url: `${servicesUrl.coriolis}/${projectId || ''}/endpoints/${endpoint.id}`,
|
|
|
|
|
- method: 'PUT',
|
|
|
|
|
- data: newPayload,
|
|
|
|
|
- }).then(putResponse => {
|
|
|
|
|
- uuidIndex = connectionInfo.secret_ref.lastIndexOf('/')
|
|
|
|
|
- uuid = connectionInfo.secret_ref.substr(uuidIndex + 1)
|
|
|
|
|
- let newEndpoint = putResponse.data.endpoint
|
|
|
|
|
-
|
|
|
|
|
- Api.send({
|
|
|
|
|
- url: `${servicesUrl.barbican}/v1/secrets/${uuid}/payload`,
|
|
|
|
|
- method: 'GET',
|
|
|
|
|
- responseType: 'text',
|
|
|
|
|
- headers: { Accept: 'text/plain' },
|
|
|
|
|
- }).then(conInfoResponse => {
|
|
|
|
|
- newEndpoint.connection_info = {
|
|
|
|
|
- ...newEndpoint.connection_info,
|
|
|
|
|
- ...conInfoResponse.data,
|
|
|
|
|
- }
|
|
|
|
|
- resolve(newEndpoint)
|
|
|
|
|
- }).catch(reject)
|
|
|
|
|
- }).catch(reject)
|
|
|
|
|
- }).catch(reject)
|
|
|
|
|
- } else {
|
|
|
|
|
- Api.send({
|
|
|
|
|
- url: `${servicesUrl.coriolis}/${projectId || ''}/endpoints/${endpoint.id}`,
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+ }).then(response => {
|
|
|
|
|
+ connectionInfo = { secret_ref: response.data.secret_ref }
|
|
|
|
|
+ let newPayload = {
|
|
|
|
|
+ endpoint: {
|
|
|
|
|
+ name: parsedEndpoint.name,
|
|
|
|
|
+ description: parsedEndpoint.description,
|
|
|
|
|
+ connection_info: connectionInfo,
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+ return Api.send({
|
|
|
|
|
+ url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpoint.id}`,
|
|
|
method: 'PUT',
|
|
method: 'PUT',
|
|
|
- data: { endpoint: parsedEndpoint },
|
|
|
|
|
- }).then(response => {
|
|
|
|
|
- resolve(response.data.endpoint)
|
|
|
|
|
- }).catch(reject)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ data: newPayload,
|
|
|
|
|
+ })
|
|
|
|
|
+ }).then(putResponse => {
|
|
|
|
|
+ uuidIndex = connectionInfo.secret_ref.lastIndexOf('/')
|
|
|
|
|
+ uuid = connectionInfo.secret_ref.substr(uuidIndex + 1)
|
|
|
|
|
+ newEndpoint = putResponse.data.endpoint
|
|
|
|
|
+ return Api.send({
|
|
|
|
|
+ url: `${servicesUrl.barbican}/v1/secrets/${uuid}/payload`,
|
|
|
|
|
+ method: 'GET',
|
|
|
|
|
+ responseType: 'text',
|
|
|
|
|
+ headers: { Accept: 'text/plain' },
|
|
|
|
|
+ })
|
|
|
|
|
+ }).then(conInfoResponse => {
|
|
|
|
|
+ newEndpoint.connection_info = {
|
|
|
|
|
+ ...newEndpoint.connection_info,
|
|
|
|
|
+ ...conInfoResponse.data,
|
|
|
|
|
+ }
|
|
|
|
|
+ return newEndpoint
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return Api.send({
|
|
|
|
|
+ url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpoint.id}`,
|
|
|
|
|
+ method: 'PUT',
|
|
|
|
|
+ data: { endpoint: parsedEndpoint },
|
|
|
|
|
+ }).then(response => {
|
|
|
|
|
+ return response.data.endpoint
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static add(endpoint: Endpoint, skipSchemaParser: boolean = false): Promise<Endpoint> {
|
|
static add(endpoint: Endpoint, skipSchemaParser: boolean = false): Promise<Endpoint> {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
|
- let parsedEndpoint = skipSchemaParser ? { ...endpoint } : SchemaParser.fieldsToPayload(endpoint)
|
|
|
|
|
- let projectId = cookie.get('projectId')
|
|
|
|
|
- if (useSecret) {
|
|
|
|
|
- Api.send({
|
|
|
|
|
- url: `${servicesUrl.barbican}/v1/secrets`,
|
|
|
|
|
|
|
+ let parsedEndpoint = skipSchemaParser ? { ...endpoint } : SchemaParser.fieldsToPayload(endpoint)
|
|
|
|
|
+ let newEndpoint: any = {}
|
|
|
|
|
+ let connectionInfo = {}
|
|
|
|
|
+ if (useSecret) {
|
|
|
|
|
+ return Api.send({
|
|
|
|
|
+ url: `${servicesUrl.barbican}/v1/secrets`,
|
|
|
|
|
+ method: 'POST',
|
|
|
|
|
+ data: getBarbicanPayload(ObjectUtils.skipField(parsedEndpoint.connection_info, 'secret_ref')),
|
|
|
|
|
+ }).then(response => {
|
|
|
|
|
+ connectionInfo = { secret_ref: response.data.secret_ref }
|
|
|
|
|
+ let newPayload = {
|
|
|
|
|
+ endpoint: {
|
|
|
|
|
+ name: parsedEndpoint.name,
|
|
|
|
|
+ description: parsedEndpoint.description,
|
|
|
|
|
+ type: endpoint.type,
|
|
|
|
|
+ connection_info: connectionInfo,
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+ return Api.send({
|
|
|
|
|
+ url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints`,
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
|
- data: getBarbicanPayload(ObjectUtils.skipField(parsedEndpoint.connection_info, 'secret_ref')),
|
|
|
|
|
- }).then(response => {
|
|
|
|
|
- let connectionInfo = { secret_ref: response.data.secret_ref }
|
|
|
|
|
- let newPayload = {
|
|
|
|
|
- endpoint: {
|
|
|
|
|
- name: parsedEndpoint.name,
|
|
|
|
|
- description: parsedEndpoint.description,
|
|
|
|
|
- type: endpoint.type,
|
|
|
|
|
- connection_info: connectionInfo,
|
|
|
|
|
- },
|
|
|
|
|
- }
|
|
|
|
|
- Api.send({
|
|
|
|
|
- url: `${servicesUrl.coriolis}/${projectId || ''}/endpoints`,
|
|
|
|
|
- method: 'POST',
|
|
|
|
|
- data: newPayload,
|
|
|
|
|
- }).then(postResponse => {
|
|
|
|
|
- let uuidIndex = connectionInfo.secret_ref.lastIndexOf('/')
|
|
|
|
|
- let uuid = connectionInfo.secret_ref.substr(uuidIndex + 1)
|
|
|
|
|
- let newEndpoint = postResponse.data.endpoint
|
|
|
|
|
|
|
+ data: newPayload,
|
|
|
|
|
+ })
|
|
|
|
|
+ }).then(postResponse => {
|
|
|
|
|
+ let uuidIndex = connectionInfo.secret_ref.lastIndexOf('/')
|
|
|
|
|
+ let uuid = connectionInfo.secret_ref.substr(uuidIndex + 1)
|
|
|
|
|
+ newEndpoint = postResponse.data.endpoint
|
|
|
|
|
|
|
|
- Api.send({
|
|
|
|
|
- url: `${servicesUrl.barbican}/v1/secrets/${uuid}/payload`,
|
|
|
|
|
- responseType: 'text',
|
|
|
|
|
- headers: { Accept: 'text/plain' },
|
|
|
|
|
- }).then(conInfoResponse => {
|
|
|
|
|
- newEndpoint.connection_info = {
|
|
|
|
|
- ...newEndpoint.connection_info,
|
|
|
|
|
- ...conInfoResponse.data,
|
|
|
|
|
- }
|
|
|
|
|
- resolve(newEndpoint)
|
|
|
|
|
- }).catch(reject)
|
|
|
|
|
- }).catch(reject)
|
|
|
|
|
- }).catch(reject)
|
|
|
|
|
- } else {
|
|
|
|
|
- Api.send({
|
|
|
|
|
- url: `${servicesUrl.coriolis}/${projectId || ''}/endpoints`,
|
|
|
|
|
- method: 'POST',
|
|
|
|
|
- data: { endpoint: parsedEndpoint },
|
|
|
|
|
- }).then(response => {
|
|
|
|
|
- resolve(response.data.endpoint)
|
|
|
|
|
- }).catch(reject)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return Api.send({
|
|
|
|
|
+ url: `${servicesUrl.barbican}/v1/secrets/${uuid}/payload`,
|
|
|
|
|
+ responseType: 'text',
|
|
|
|
|
+ headers: { Accept: 'text/plain' },
|
|
|
|
|
+ })
|
|
|
|
|
+ }).then(conInfoResponse => {
|
|
|
|
|
+ newEndpoint.connection_info = {
|
|
|
|
|
+ ...newEndpoint.connection_info,
|
|
|
|
|
+ ...conInfoResponse.data,
|
|
|
|
|
+ }
|
|
|
|
|
+ return newEndpoint
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return Api.send({
|
|
|
|
|
+ url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints`,
|
|
|
|
|
+ method: 'POST',
|
|
|
|
|
+ data: { endpoint: parsedEndpoint },
|
|
|
|
|
+ }).then(response => {
|
|
|
|
|
+ return response.data.endpoint
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|