Sfoglia il codice sorgente

Remove cookie dependencies from all 'Source' files

Project ID is no longer retrieved from cookies in all 'Source' files,
instead it is retrieved from the API Caller class, which now handles the
retrieval of project ID from cookies. This allows having one place where
cookie retrieval and validation happens.

Includes an update to a unit test.
Sergiu Miclea 8 anni fa
parent
commit
6e7c6c1b60

+ 5 - 1
src/components/organisms/DetailsPageHeader/DetailsPageHeader.jsx

@@ -42,7 +42,7 @@ const Logo = styled.a`
   background: url('${logoImage}') no-repeat;
   background: url('${logoImage}') no-repeat;
   cursor: pointer;
   cursor: pointer;
 `
 `
-const UserDropdownStyled = styled(UserDropdown) `
+const UserDropdownStyled = styled(UserDropdown)`
   margin-left: 16px;
   margin-left: 16px;
 `
 `
 const Menu = styled.div`
 const Menu = styled.div`
@@ -57,10 +57,14 @@ const User = styled.div`
 type Props = {
 type Props = {
   user?: ?UserType,
   user?: ?UserType,
   onUserItemClick: (userItem: { label: string, value: string }) => void,
   onUserItemClick: (userItem: { label: string, value: string }) => void,
+  testMode?: boolean,
 }
 }
 @observer
 @observer
 export class DetailsPageHeader extends React.Component<Props> {
 export class DetailsPageHeader extends React.Component<Props> {
   componentDidMount() {
   componentDidMount() {
+    if (this.props.testMode) {
+      return
+    }
     notificationStore.loadNotifications()
     notificationStore.loadNotifications()
   }
   }
 
 

+ 13 - 3
src/components/organisms/DetailsPageHeader/test.jsx

@@ -18,16 +18,26 @@ import React from 'react'
 import { shallow } from 'enzyme'
 import { shallow } from 'enzyme'
 import sinon from 'sinon'
 import sinon from 'sinon'
 import TW from '../../../utils/TestWrapper'
 import TW from '../../../utils/TestWrapper'
+import type { User } from '../../../types/User'
 import { DetailsPageHeader } from '.'
 import { DetailsPageHeader } from '.'
 
 
-const wrap = props => new TW(shallow(
-  // $FlowIgnore
-  <DetailsPageHeader notificationStore={{}} {...props} />
+type Props = {
+  user?: ?User,
+}
+
+const wrap = (props: Props) => new TW(shallow(
+  <DetailsPageHeader
+    onUserItemClick={() => { }}
+    testMode
+    {...props}
+  />
 ), 'dpHeader')
 ), 'dpHeader')
 
 
 let user = {
 let user = {
   name: 'User name',
   name: 'User name',
   email: 'email@email.com',
   email: 'email@email.com',
+  id: 'user',
+  project: { id: '', name: '' },
 }
 }
 
 
 describe('DetailsPageHeader Component', () => {
 describe('DetailsPageHeader Component', () => {

+ 1 - 4
src/sources/AssessmentSource.js

@@ -14,8 +14,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
 // @flow
 // @flow
 
 
-import cookie from 'js-cookie'
-
 import type { MigrationInfo } from '../types/Assessment'
 import type { MigrationInfo } from '../types/Assessment'
 import type { MainItem } from '../types/MainItem'
 import type { MainItem } from '../types/MainItem'
 import Api from '../utils/ApiCaller'
 import Api from '../utils/ApiCaller'
@@ -38,7 +36,6 @@ class AssessmentSourceUtils {
 
 
 class AssessmentSource {
 class AssessmentSource {
   static migrate(data: MigrationInfo): Promise<MainItem> {
   static migrate(data: MigrationInfo): Promise<MainItem> {
-    let projectId = cookie.get('projectId')
     let useReplicaField = data.options.find(o => o.name === 'use_replica')
     let useReplicaField = data.options.find(o => o.name === 'use_replica')
     let type = useReplicaField && useReplicaField.value ? 'replica' : 'migration'
     let type = useReplicaField && useReplicaField.value ? 'replica' : 'migration'
     let payload = {}
     let payload = {}
@@ -61,7 +58,7 @@ class AssessmentSource {
     })
     })
 
 
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/${type}s`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/${type}s`,
       method: 'POST',
       method: 'POST',
       data: payload,
       data: payload,
     }).then(response => {
     }).then(response => {

+ 16 - 26
src/sources/EndpointSource.js

@@ -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,27 +38,21 @@ let getBarbicanPayload = data => {
 
 
 class EdnpointSource {
 class EdnpointSource {
   static getEndpoints(): Promise<Endpoint[]> {
   static getEndpoints(): Promise<Endpoint[]> {
-    let projectId = cookie.get('projectId')
-    if (projectId) {
-      return Api.get(`${servicesUrl.coriolis}/${projectId}/endpoints`).then(response => {
-        let connections = []
-        if (response.data.endpoints.length) {
-          response.data.endpoints.forEach(endpoint => {
-            connections.push(endpoint)
-          })
-        }
+    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
-      })
-    }
-    return Promise.reject('No Project ID!')
+      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> {
-    let projectId: any = cookie.get('projectId')
-
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId}/endpoints/${endpoint.id}`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpoint.id}`,
       method: 'DELETE',
       method: 'DELETE',
     }).then(() => {
     }).then(() => {
       if (endpoint.connection_info && endpoint.connection_info.secret_ref) {
       if (endpoint.connection_info && endpoint.connection_info.secret_ref) {
@@ -107,9 +100,8 @@ class EdnpointSource {
   }
   }
 
 
   static validate(endpoint: Endpoint): Promise<Validation> {
   static validate(endpoint: Endpoint): Promise<Validation> {
-    let projectId = cookie.get('projectId')
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || ''}/endpoints/${endpoint.id}/actions`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpoint.id}/actions`,
       method: 'POST',
       method: 'POST',
       data: { 'validate-connection': null },
       data: { 'validate-connection': null },
     }).then(response => {
     }).then(response => {
@@ -118,7 +110,6 @@ class EdnpointSource {
   }
   }
 
 
   static update(endpoint: Endpoint): Promise<Endpoint> {
   static update(endpoint: Endpoint): Promise<Endpoint> {
-    let projectId = cookie.get('projectId')
     let parsedEndpoint = SchemaParser.fieldsToPayload(endpoint)
     let parsedEndpoint = SchemaParser.fieldsToPayload(endpoint)
 
 
     if (parsedEndpoint.connection_info && parsedEndpoint.connection_info.secret_ref) {
     if (parsedEndpoint.connection_info && parsedEndpoint.connection_info.secret_ref) {
@@ -147,7 +138,7 @@ class EdnpointSource {
           },
           },
         }
         }
         return Api.send({
         return Api.send({
-          url: `${servicesUrl.coriolis}/${projectId || ''}/endpoints/${endpoint.id}`,
+          url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpoint.id}`,
           method: 'PUT',
           method: 'PUT',
           data: newPayload,
           data: newPayload,
         })
         })
@@ -171,7 +162,7 @@ class EdnpointSource {
     }
     }
 
 
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || ''}/endpoints/${endpoint.id}`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpoint.id}`,
       method: 'PUT',
       method: 'PUT',
       data: { endpoint: parsedEndpoint },
       data: { endpoint: parsedEndpoint },
     }).then(response => {
     }).then(response => {
@@ -181,7 +172,6 @@ class EdnpointSource {
 
 
   static add(endpoint: Endpoint, skipSchemaParser: boolean = false): Promise<Endpoint> {
   static add(endpoint: Endpoint, skipSchemaParser: boolean = false): Promise<Endpoint> {
     let parsedEndpoint = skipSchemaParser ? { ...endpoint } : SchemaParser.fieldsToPayload(endpoint)
     let parsedEndpoint = skipSchemaParser ? { ...endpoint } : SchemaParser.fieldsToPayload(endpoint)
-    let projectId = cookie.get('projectId')
     let newEndpoint: any = {}
     let newEndpoint: any = {}
     let connectionInfo = {}
     let connectionInfo = {}
     if (useSecret) {
     if (useSecret) {
@@ -200,7 +190,7 @@ class EdnpointSource {
           },
           },
         }
         }
         return Api.send({
         return Api.send({
-          url: `${servicesUrl.coriolis}/${projectId || ''}/endpoints`,
+          url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints`,
           method: 'POST',
           method: 'POST',
           data: newPayload,
           data: newPayload,
         })
         })
@@ -224,7 +214,7 @@ class EdnpointSource {
     }
     }
 
 
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || ''}/endpoints`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints`,
       method: 'POST',
       method: 'POST',
       data: { endpoint: parsedEndpoint },
       data: { endpoint: parsedEndpoint },
     }).then(response => {
     }).then(response => {

+ 2 - 7
src/sources/InstanceSource.js

@@ -14,8 +14,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
 // @flow
 // @flow
 
 
-import cookie from 'js-cookie'
-
 import Api from '../utils/ApiCaller'
 import Api from '../utils/ApiCaller'
 import type { Instance } from '../types/Instance'
 import type { Instance } from '../types/Instance'
 
 
@@ -30,8 +28,7 @@ class InstanceSource {
       this.lastEndpointId = endpointId
       this.lastEndpointId = endpointId
     }
     }
 
 
-    let projectId = cookie.get('projectId')
-    let url = `${servicesUrl.coriolis}/${projectId || 'null'}/endpoints/${endpointId}/instances`
+    let url = `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpointId}/instances`
     let symbol = '?'
     let symbol = '?'
 
 
     if (!skipLimit) {
     if (!skipLimit) {
@@ -54,10 +51,8 @@ class InstanceSource {
   }
   }
 
 
   static loadInstanceDetails(endpointId: string, instanceName: string, reqId: number): Promise<{ instance: Instance, reqId: number }> {
   static loadInstanceDetails(endpointId: string, instanceName: string, reqId: number): Promise<{ instance: Instance, reqId: number }> {
-    let projectId = cookie.get('projectId') || 'undefined'
-
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId}/endpoints/${endpointId}/instances/${btoa(instanceName)}`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpointId}/instances/${btoa(instanceName)}`,
       cancelId: `instanceDetail-${reqId}`,
       cancelId: `instanceDetail-${reqId}`,
     }).then(response => {
     }).then(response => {
       return { instance: response.data.instance, reqId }
       return { instance: response.data.instance, reqId }

+ 5 - 13
src/sources/MigrationSource.js

@@ -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'
@@ -51,8 +50,7 @@ class MigrationSourceUtils {
 
 
 class MigrationSource {
 class MigrationSource {
   static getMigrations(): Promise<MainItem[]> {
   static getMigrations(): Promise<MainItem[]> {
-    let projectId = cookie.get('projectId') || 'null'
-    return Api.get(`${servicesUrl.coriolis}/${projectId}/migrations/detail`).then(response => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/migrations/detail`).then(response => {
       let migrations = response.data.migrations
       let migrations = response.data.migrations
       MigrationSourceUtils.sortMigrations(migrations)
       MigrationSourceUtils.sortMigrations(migrations)
       return migrations
       return migrations
@@ -60,9 +58,7 @@ class MigrationSource {
   }
   }
 
 
   static getMigration(migrationId: string): Promise<MainItem> {
   static getMigration(migrationId: string): Promise<MainItem> {
-    let projectId = cookie.get('projectId') || 'null'
-
-    return Api.get(`${servicesUrl.coriolis}/${projectId}/migrations/${migrationId}`).then(response => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/migrations/${migrationId}`).then(response => {
       let migration = response.data.migration
       let migration = response.data.migration
       MigrationSourceUtils.sortTaskUpdates(migration)
       MigrationSourceUtils.sortTaskUpdates(migration)
       return migration
       return migration
@@ -70,25 +66,21 @@ class MigrationSource {
   }
   }
 
 
   static cancel(migrationId: string): Promise<string> {
   static cancel(migrationId: string): Promise<string> {
-    let projectId = cookie.get('projectId') || 'null'
-
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId}/migrations/${migrationId}/actions`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/migrations/${migrationId}/actions`,
       method: 'POST',
       method: 'POST',
       data: { cancel: null },
       data: { cancel: null },
     }).then(() => migrationId)
     }).then(() => migrationId)
   }
   }
 
 
   static delete(migrationId: string): Promise<string> {
   static delete(migrationId: string): Promise<string> {
-    let projectId = cookie.get('projectId')
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/migrations/${migrationId}`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/migrations/${migrationId}`,
       method: 'DELETE',
       method: 'DELETE',
     }).then(() => migrationId)
     }).then(() => migrationId)
   }
   }
 
 
   static migrateReplica(replicaId: string, options: Field[]): Promise<MainItem> {
   static migrateReplica(replicaId: string, options: Field[]): Promise<MainItem> {
-    let projectId = cookie.get('projectId')
     let payload = {
     let payload = {
       migration: {
       migration: {
         replica_id: replicaId,
         replica_id: replicaId,
@@ -99,7 +91,7 @@ class MigrationSource {
     })
     })
 
 
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/migrations`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/migrations`,
       method: 'POST',
       method: 'POST',
       data: payload,
       data: payload,
     }).then(response => response.data.migration)
     }).then(response => response.data.migration)

+ 1 - 4
src/sources/NetworkSource.js

@@ -14,8 +14,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
 // @flow
 // @flow
 
 
-import cookie from 'js-cookie'
-
 import Api from '../utils/ApiCaller'
 import Api from '../utils/ApiCaller'
 import type { Network } from '../types/Network'
 import type { Network } from '../types/Network'
 
 
@@ -23,8 +21,7 @@ import { servicesUrl } from '../config'
 
 
 class NetworkSource {
 class NetworkSource {
   static loadNetworks(enpointId: string, environment: ?{ [string]: mixed }): Promise<Network[]> {
   static loadNetworks(enpointId: string, environment: ?{ [string]: mixed }): Promise<Network[]> {
-    let projectId = cookie.get('projectId')
-    let url = `${servicesUrl.coriolis}/${projectId || 'null'}/endpoints/${enpointId}/networks`
+    let url = `${servicesUrl.coriolis}/${Api.projectId}/endpoints/${enpointId}/networks`
     if (environment) {
     if (environment) {
       url = `${url}?env=${btoa(JSON.stringify(environment))}`
       url = `${url}?env=${btoa(JSON.stringify(environment))}`
     }
     }

+ 1 - 0
src/sources/NotificationSource.js

@@ -16,6 +16,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
 import type { NotificationItem } from '../types/NotificationItem'
 import type { NotificationItem } from '../types/NotificationItem'
 
 
+
 class NotificationSource {
 class NotificationSource {
   static notify(message: string, level?: $PropertyType<NotificationItem, 'level'>, options?: $PropertyType<NotificationItem, 'options'>): Promise<NotificationItem> {
   static notify(message: string, level?: $PropertyType<NotificationItem, 'level'>, options?: $PropertyType<NotificationItem, 'options'>): Promise<NotificationItem> {
     let notifications = JSON.parse(localStorage.getItem('notifications') || '[]')
     let notifications = JSON.parse(localStorage.getItem('notifications') || '[]')

+ 4 - 12
src/sources/ProviderSource.js

@@ -14,8 +14,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
 // @flow
 // @flow
 
 
-import cookie from 'js-cookie'
-
 import Api from '../utils/ApiCaller'
 import Api from '../utils/ApiCaller'
 import { servicesUrl, providerTypes } from '../config'
 import { servicesUrl, providerTypes } from '../config'
 import { SchemaParser } from './Schemas'
 import { SchemaParser } from './Schemas'
@@ -25,9 +23,7 @@ import type { DestinationOption } from '../types/Endpoint'
 
 
 class ProviderSource {
 class ProviderSource {
   static getConnectionInfoSchema(providerName: string): Promise<Field[]> {
   static getConnectionInfoSchema(providerName: string): Promise<Field[]> {
-    let projectId = cookie.get('projectId')
-
-    return Api.get(`${servicesUrl.coriolis}/${projectId || 'null'}/providers/${providerName}/schemas/${providerTypes.CONNECTION}`).then(response => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/providers/${providerName}/schemas/${providerTypes.CONNECTION}`).then(response => {
       let schema = response.data.schemas.connection_info_schema
       let schema = response.data.schemas.connection_info_schema
       schema = SchemaParser.connectionSchemaToFields(providerName, schema)
       schema = SchemaParser.connectionSchemaToFields(providerName, schema)
       return schema
       return schema
@@ -35,17 +31,14 @@ class ProviderSource {
   }
   }
 
 
   static loadProviders(): Promise<Providers> {
   static loadProviders(): Promise<Providers> {
-    let projectId = cookie.get('projectId')
-
-    return Api.get(`${servicesUrl.coriolis}/${projectId || 'null'}/providers`)
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/providers`)
       .then(response => response.data.providers)
       .then(response => response.data.providers)
   }
   }
 
 
   static loadOptionsSchema(providerName: string, schemaType: string): Promise<Field[]> {
   static loadOptionsSchema(providerName: string, schemaType: string): Promise<Field[]> {
-    let projectId = cookie.get('projectId')
     let schemaTypeInt = schemaType === 'migration' ? providerTypes.TARGET_MIGRATION : providerTypes.TARGET_REPLICA
     let schemaTypeInt = schemaType === 'migration' ? providerTypes.TARGET_MIGRATION : providerTypes.TARGET_REPLICA
 
 
-    return Api.get(`${servicesUrl.coriolis}/${projectId || 'null'}/providers/${providerName}/schemas/${schemaTypeInt}`).then(response => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/providers/${providerName}/schemas/${schemaTypeInt}`).then(response => {
       let schema = response.data.schemas.destination_environment_schema
       let schema = response.data.schemas.destination_environment_schema
       let fields = SchemaParser.optionsSchemaToFields(providerName, schema)
       let fields = SchemaParser.optionsSchemaToFields(providerName, schema)
       return fields
       return fields
@@ -53,13 +46,12 @@ class ProviderSource {
   }
   }
 
 
   static getDestinationOptions(endpointId: string, envData: ?{ [string]: mixed }): Promise<DestinationOption[]> {
   static getDestinationOptions(endpointId: string, envData: ?{ [string]: mixed }): Promise<DestinationOption[]> {
-    let projectId = cookie.get('projectId')
     let envString = ''
     let envString = ''
     if (envData) {
     if (envData) {
       envString = `?env=${btoa(JSON.stringify(envData))}`
       envString = `?env=${btoa(JSON.stringify(envData))}`
     }
     }
 
 
-    return Api.get(`${servicesUrl.coriolis}/${projectId || 'null'}/endpoints/${endpointId}/destination-options${envString}`).then(response => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/endpoints/${endpointId}/destination-options${envString}`).then(response => {
       let options = response.data.destination_options
       let options = response.data.destination_options
       return options
       return options
     })
     })

+ 8 - 23
src/sources/ReplicaSource.js

@@ -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'
@@ -85,8 +84,7 @@ class ReplicaSourceUtils {
 
 
 class ReplicaSource {
 class ReplicaSource {
   static getReplicas(): Promise<MainItem[]> {
   static getReplicas(): Promise<MainItem[]> {
-    let projectId = cookie.get('projectId') || 'undefined'
-    return Api.get(`${servicesUrl.coriolis}/${projectId}/replicas/detail`).then(response => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/replicas/detail`).then(response => {
       let replicas = response.data.replicas
       let replicas = response.data.replicas
       replicas = ReplicaSourceUtils.filterDeletedExecutionsInReplicas(replicas)
       replicas = ReplicaSourceUtils.filterDeletedExecutionsInReplicas(replicas)
       ReplicaSourceUtils.sortReplicas(replicas)
       ReplicaSourceUtils.sortReplicas(replicas)
@@ -95,8 +93,7 @@ class ReplicaSource {
   }
   }
 
 
   static getReplicaExecutions(replicaId: string): Promise<Execution[]> {
   static getReplicaExecutions(replicaId: string): Promise<Execution[]> {
-    let projectId = cookie.get('projectId') || 'undefined'
-    return Api.get(`${servicesUrl.coriolis}/${projectId}/replicas/${replicaId}/executions/detail`).then((response) => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/executions/detail`).then((response) => {
       let executions = response.data.executions
       let executions = response.data.executions
       ReplicaSourceUtils.sortExecutionsAndTaskUpdates(executions)
       ReplicaSourceUtils.sortExecutionsAndTaskUpdates(executions)
 
 
@@ -105,9 +102,7 @@ class ReplicaSource {
   }
   }
 
 
   static getReplica(replicaId: string): Promise<MainItem> {
   static getReplica(replicaId: string): Promise<MainItem> {
-    let projectId = cookie.get('projectId') || 'undefined'
-
-    return Api.get(`${servicesUrl.coriolis}/${projectId}/replicas/${replicaId}`).then(response => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}`).then(response => {
       let replica = response.data.replica
       let replica = response.data.replica
       replica.executions = ReplicaSourceUtils.filterDeletedExecutions(replica.executions)
       replica.executions = ReplicaSourceUtils.filterDeletedExecutions(replica.executions)
       ReplicaSourceUtils.sortExecutions(replica.executions)
       ReplicaSourceUtils.sortExecutions(replica.executions)
@@ -122,10 +117,8 @@ class ReplicaSource {
         payload.execution[f.name] = f.value || false
         payload.execution[f.name] = f.value || false
       })
       })
     }
     }
-    let projectId = cookie.get('projectId') || 'undefined'
-
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId}/replicas/${replicaId}/executions`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/executions`,
       method: 'POST',
       method: 'POST',
       data: payload,
       data: payload,
     }).then((response) => {
     }).then((response) => {
@@ -136,38 +129,30 @@ class ReplicaSource {
   }
   }
 
 
   static cancelExecution(replicaId: string, executionId: string): Promise<string> {
   static cancelExecution(replicaId: string, executionId: string): Promise<string> {
-    let projectId = cookie.get('projectId')
-
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}/executions/${executionId}/actions`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/executions/${executionId}/actions`,
       method: 'POST',
       method: 'POST',
       data: { cancel: null },
       data: { cancel: null },
     }).then(() => replicaId)
     }).then(() => replicaId)
   }
   }
 
 
   static deleteExecution(replicaId: string, executionId: string): Promise<string> {
   static deleteExecution(replicaId: string, executionId: string): Promise<string> {
-    let projectId = cookie.get('projectId')
-
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}/executions/${executionId}`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/executions/${executionId}`,
       method: 'DELETE',
       method: 'DELETE',
     }).then(() => replicaId)
     }).then(() => replicaId)
   }
   }
 
 
   static delete(replicaId: string): Promise<string> {
   static delete(replicaId: string): Promise<string> {
-    let projectId = cookie.get('projectId')
-
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}`,
       method: 'DELETE',
       method: 'DELETE',
     }).then(() => replicaId)
     }).then(() => replicaId)
   }
   }
 
 
   static deleteDisks(replicaId: string): Promise<Execution> {
   static deleteDisks(replicaId: string): Promise<Execution> {
-    let projectId = cookie.get('projectId')
-
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}/actions`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/actions`,
       method: 'POST',
       method: 'POST',
       data: { 'delete-disks': null },
       data: { 'delete-disks': null },
     }).then(response => response.data.execution)
     }).then(response => response.data.execution)

+ 5 - 12
src/sources/ScheduleSource.js

@@ -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'
@@ -24,7 +23,6 @@ import type { Schedule } from '../types/Schedule'
 
 
 class ScheduleSource {
 class ScheduleSource {
   static scheduleSinge(replicaId: string, scheduleData: Schedule): Promise<Schedule> {
   static scheduleSinge(replicaId: string, scheduleData: Schedule): Promise<Schedule> {
-    let projectId = cookie.get('projectId')
     let payload = {
     let payload = {
       schedule: {},
       schedule: {},
       expiration_date: null,
       expiration_date: null,
@@ -47,7 +45,7 @@ class ScheduleSource {
     }
     }
 
 
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}/schedules`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/schedules`,
       method: 'POST',
       method: 'POST',
       data: payload,
       data: payload,
     }).then(response => response.data.schedule)
     }).then(response => response.data.schedule)
@@ -60,9 +58,7 @@ class ScheduleSource {
   }
   }
 
 
   static getSchedules(replicaId: string): Promise<Schedule[]> {
   static getSchedules(replicaId: string): Promise<Schedule[]> {
-    let projectId = cookie.get('projectId')
-
-    return Api.get(`${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}/schedules`).then(response => {
+    return Api.get(`${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/schedules`).then(response => {
       let schedules = [...response.data.schedules]
       let schedules = [...response.data.schedules]
       schedules.forEach(s => {
       schedules.forEach(s => {
         if (s.expiration_date) {
         if (s.expiration_date) {
@@ -78,7 +74,6 @@ class ScheduleSource {
   }
   }
 
 
   static addSchedule(replicaId: string, schedule: Schedule): Promise<Schedule> {
   static addSchedule(replicaId: string, schedule: Schedule): Promise<Schedule> {
-    let projectId = cookie.get('projectId')
     let payload = {
     let payload = {
       schedule: { hour: 0, minute: 0 },
       schedule: { hour: 0, minute: 0 },
       enabled: false,
       enabled: false,
@@ -88,16 +83,15 @@ class ScheduleSource {
     }
     }
 
 
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}/schedules`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/schedules`,
       method: 'POST',
       method: 'POST',
       data: payload,
       data: payload,
     }).then(response => response.data.schedule)
     }).then(response => response.data.schedule)
   }
   }
 
 
   static removeSchedule(replicaId: string, scheduleId: string): Promise<void> {
   static removeSchedule(replicaId: string, scheduleId: string): Promise<void> {
-    let projectId = cookie.get('projectId')
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}/schedules/${scheduleId}`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/schedules/${scheduleId}`,
       method: 'DELETE',
       method: 'DELETE',
     }).then(() => { })
     }).then(() => { })
   }
   }
@@ -109,7 +103,6 @@ class ScheduleSource {
     scheduleOldData: ?Schedule,
     scheduleOldData: ?Schedule,
     unsavedData: ?Schedule
     unsavedData: ?Schedule
   ): Promise<Schedule> {
   ): Promise<Schedule> {
-    let projectId = cookie.get('projectId')
     let payload = {}
     let payload = {}
     if (scheduleData.enabled !== null && scheduleData.enabled !== undefined) {
     if (scheduleData.enabled !== null && scheduleData.enabled !== undefined) {
       payload.enabled = scheduleData.enabled
       payload.enabled = scheduleData.enabled
@@ -136,7 +129,7 @@ class ScheduleSource {
     }
     }
 
 
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/replicas/${replicaId}/schedules/${scheduleId}`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/replicas/${replicaId}/schedules/${scheduleId}`,
       method: 'PUT',
       method: 'PUT',
       data: payload,
       data: payload,
     }).then(response => {
     }).then(response => {

+ 1 - 5
src/sources/WizardSource.js

@@ -14,8 +14,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
 // @flow
 // @flow
 
 
-import cookie from 'js-cookie'
-
 import Api from '../utils/ApiCaller'
 import Api from '../utils/ApiCaller'
 import notificationStore from '../stores/NotificationStore'
 import notificationStore from '../stores/NotificationStore'
 import { OptionsSchemaPlugin } from '../plugins/endpoint'
 import { OptionsSchemaPlugin } from '../plugins/endpoint'
@@ -26,8 +24,6 @@ import type { MainItem } from '../types/MainItem'
 
 
 class WizardSource {
 class WizardSource {
   static create(type: string, data: WizardData): Promise<MainItem> {
   static create(type: string, data: WizardData): Promise<MainItem> {
-    let projectId = cookie.get('projectId')
-
     const parser = data.target ? OptionsSchemaPlugin[data.target.type] || OptionsSchemaPlugin.default : OptionsSchemaPlugin.default
     const parser = data.target ? OptionsSchemaPlugin[data.target.type] || OptionsSchemaPlugin.default : OptionsSchemaPlugin.default
     let payload = {}
     let payload = {}
     payload[type] = {
     payload[type] = {
@@ -43,7 +39,7 @@ class WizardSource {
     }
     }
 
 
     return Api.send({
     return Api.send({
-      url: `${servicesUrl.coriolis}/${projectId || 'null'}/${type}s`,
+      url: `${servicesUrl.coriolis}/${Api.projectId}/${type}s`,
       method: 'POST',
       method: 'POST',
       data: payload,
       data: payload,
     }).then(response => response.data[type])
     }).then(response => response.data[type])

+ 5 - 0
src/utils/ApiCaller.js

@@ -16,6 +16,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
 import axios from 'axios'
 import axios from 'axios'
 import type { AxiosXHRConfig, $AxiosXHR } from 'axios'
 import type { AxiosXHRConfig, $AxiosXHR } from 'axios'
+import cookie from 'js-cookie'
 
 
 import notificationStore from '../stores/NotificationStore'
 import notificationStore from '../stores/NotificationStore'
 
 
@@ -49,6 +50,10 @@ class ApiCaller {
     axios.defaults.headers.common['Content-Type'] = 'application/json'
     axios.defaults.headers.common['Content-Type'] = 'application/json'
   }
   }
 
 
+  get projectId(): string {
+    return cookie.get('projectId') || 'undefined'
+  }
+
   cancelRequests(cancelRequestId: string) {
   cancelRequests(cancelRequestId: string) {
     const filteredCancelables = cancelables.filter(r => r.requestId === cancelRequestId)
     const filteredCancelables = cancelables.filter(r => r.requestId === cancelRequestId)
     filteredCancelables.forEach(c => {
     filteredCancelables.forEach(c => {