Skip to content
Merged
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
30 changes: 0 additions & 30 deletions ui/apps/platform/src/reducers/apitokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,14 @@ import isEqual from 'lodash/isEqual';

import { createFetchingActionTypes, createFetchingActions } from 'utils/fetchingReduxRoutines';

export const apiTokenFormId = 'api-token-form-id';

export const types = {
FETCH_API_TOKENS: createFetchingActionTypes('apitokens/FETCH_API_TOKENS'),
GENERATE_API_TOKEN: createFetchingActionTypes('apitokens/GENERATE_API_TOKEN'),
REVOKE_API_TOKENS: 'apitokens/REVOKE_API_TOKENS',
START_TOKEN_GENERATION_WIZARD: 'apitokens/START_TOKEN_GENERATION_WIZARD',
CLOSE_TOKEN_GENERATION_WIZARD: 'apitokens/CLOSE_TOKEN_GENERATION_WIZARD',
};

export const actions = {
fetchAPITokens: createFetchingActions(types.FETCH_API_TOKENS),
generateAPIToken: createFetchingActions(types.GENERATE_API_TOKEN),
revokeAPITokens: (ids) => ({ type: types.REVOKE_API_TOKENS, ids }),
startTokenGenerationWizard: () => ({ type: types.START_TOKEN_GENERATION_WIZARD }),
closeTokenGenerationWizard: () => ({ type: types.CLOSE_TOKEN_GENERATION_WIZARD }),
};

const apiTokens = (state = [], action) => {
Expand All @@ -28,36 +20,14 @@ const apiTokens = (state = [], action) => {
return state;
};

const tokenGenerationWizard = (state = null, { type, response }) => {
switch (type) {
case types.START_TOKEN_GENERATION_WIZARD:
return { token: '', metadata: null };
case types.CLOSE_TOKEN_GENERATION_WIZARD:
return null;
case types.GENERATE_API_TOKEN.SUCCESS:
return { token: response.token, metadata: response.metadata };
default:
return state;
}
};

const reducer = combineReducers({
apiTokens,
tokenGenerationWizard,
});

const getAPITokens = (state) => state.apiTokens;
const tokenGenerationWizardOpen = (state) => !!state.tokenGenerationWizard;
const getCurrentGeneratedToken = (state) =>
state.tokenGenerationWizard ? state.tokenGenerationWizard.token : null;
const getCurrentGeneratedTokenMetadata = (state) =>
state.tokenGenerationWizard ? state.tokenGenerationWizard.metadata : null;

export const selectors = {
getAPITokens,
tokenGenerationWizardOpen,
getCurrentGeneratedToken,
getCurrentGeneratedTokenMetadata,
};

export default reducer;
55 changes: 0 additions & 55 deletions ui/apps/platform/src/reducers/clusterInitBundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,14 @@ import isEqual from 'lodash/isEqual';

import { createFetchingActionTypes, createFetchingActions } from 'utils/fetchingReduxRoutines';

export const clusterInitBundleFormId = 'cluster-init-bundle-form-id';

export const types = {
FETCH_CLUSTER_INIT_BUNDLES: createFetchingActionTypes(
'clusterInitBundles/FETCH_CLUSTER_INIT_BUNDLES'
),
GENERATE_CLUSTER_INIT_BUNDLE: createFetchingActionTypes(
'clusterInitBundles/GENERATE_CLUSTER_INIT_BUNDLE'
),
// Note: REVOKE_CLUSTER_INIT_BUNDLES does not appear in reducers
// because FETCH_CLUSTER_INIT_BUNDLES is side-effect of saga, if revoke is successful.
REVOKE_CLUSTER_INIT_BUNDLES: 'clusterInitBundles/REVOKE_CLUSTER_INIT_BUNDLES',
START_CLUSTER_INIT_BUNDLE_GENERATION_WIZARD:
'clusterInitBundles/START_CLUSTER_INIT_BUNDLE_GENERATION_WIZARD',
CLOSE_CLUSTER_INIT_BUNDLE_GENERATION_WIZARD:
'clusterInitBundles/CLOSE_CLUSTER_INIT_BUNDLE_GENERATION_WIZARD',
};

export const actions = {
fetchClusterInitBundles: createFetchingActions(types.FETCH_CLUSTER_INIT_BUNDLES),
generateClusterInitBundle: createFetchingActions(types.GENERATE_CLUSTER_INIT_BUNDLE),
revokeClusterInitBundles: (ids) => ({ type: types.REVOKE_CLUSTER_INIT_BUNDLES, ids }),
startClusterInitBundleGenerationWizard: () => ({
type: types.START_CLUSTER_INIT_BUNDLE_GENERATION_WIZARD,
}),
closeClusterInitBundleGenerationWizard: () => ({
type: types.CLOSE_CLUSTER_INIT_BUNDLE_GENERATION_WIZARD,
}),
};

const clusterInitBundles = (state = [], action) => {
Expand All @@ -40,49 +20,14 @@ const clusterInitBundles = (state = [], action) => {
return state;
};

const clusterInitBundleGenerationWizard = (state = null, { type, response }) => {
switch (type) {
case types.START_CLUSTER_INIT_BUNDLE_GENERATION_WIZARD:
return { clusterInitBundle: '', helmValuesBundle: null, kubectlBundle: null };
case types.CLOSE_CLUSTER_INIT_BUNDLE_GENERATION_WIZARD:
return null;
case types.GENERATE_CLUSTER_INIT_BUNDLE.SUCCESS:
return {
clusterInitBundle: response.meta,
helmValuesBundle: response.helmValuesBundle,
kubectlBundle: response.kubectlBundle,
};
default:
return state;
}
};

const reducer = combineReducers({
clusterInitBundles,
clusterInitBundleGenerationWizard,
});

const getClusterInitBundles = (state) => state.clusterInitBundles;
const clusterInitBundleGenerationWizardOpen = (state) => !!state.clusterInitBundleGenerationWizard;
const getCurrentGeneratedClusterInitBundle = (state) =>
state.clusterInitBundleGenerationWizard
? state.clusterInitBundleGenerationWizard.clusterInitBundle
: null;
const getCurrentGeneratedHelmValuesBundle = (state) =>
state.clusterInitBundleGenerationWizard
? state.clusterInitBundleGenerationWizard.helmValuesBundle
: null;
const getCurrentGeneratedKubectlBundle = (state) =>
state.clusterInitBundleGenerationWizard
? state.clusterInitBundleGenerationWizard.kubectlBundle
: null;

export const selectors = {
getClusterInitBundles,
clusterInitBundleGenerationWizardOpen,
getCurrentGeneratedClusterInitBundle,
getCurrentGeneratedHelmValuesBundle,
getCurrentGeneratedKubectlBundle,
};

export default reducer;
24 changes: 0 additions & 24 deletions ui/apps/platform/src/reducers/integrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ export const types = {
FETCH_SIGNATURE_INTEGRATIONS: createFetchingActionTypes(
'signatureIntegrations/FETCH_SIGNATURE_INTEGRATIONS'
),
TEST_INTEGRATION: 'integrations/TEST_INTEGRATION',
DELETE_INTEGRATIONS: 'integrations/DELETE_INTEGRATIONS',
SAVE_INTEGRATION: createFetchingActionTypes('integrations/SAVE_INTEGRATION'),
SET_CREATE_STATE: 'integrations/SET_CREATE_STATE',
};

// Actions
Expand All @@ -28,12 +25,6 @@ export const actions = {
fetchBackups: createFetchingActions(types.FETCH_BACKUPS),
fetchImageIntegrations: createFetchingActions(types.FETCH_IMAGE_INTEGRATIONS),
fetchSignatureIntegrations: createFetchingActions(types.FETCH_SIGNATURE_INTEGRATIONS),
testIntegration: (source, integration, options) => ({
type: types.TEST_INTEGRATION,
source,
integration,
options,
}),
deleteIntegrations: (source, sourceType, ids) => ({
type: types.DELETE_INTEGRATIONS,
source,
Expand All @@ -44,11 +35,6 @@ export const actions = {
type: types.TRIGGER_BACKUP,
id,
}),
saveIntegration: createFetchingActions(types.SAVE_INTEGRATION),
setCreateState: (state) => ({
type: types.SET_CREATE_STATE,
state,
}),
};

// Reducers
Expand Down Expand Up @@ -83,34 +69,24 @@ const signatureIntegrations = (state = [], action) => {
return state;
};

const isCreating = (state = false, action) => {
if (action.type === types.SET_CREATE_STATE) {
return action.state;
}
return state;
};

const reducer = combineReducers({
backups,
notifiers,
imageIntegrations,
signatureIntegrations,
isCreating,
});

// Selectors

const getBackups = (state) => state.backups;
const getNotifiers = (state) => state.notifiers;
const getImageIntegrations = (state) => state.imageIntegrations;
const getCreationState = (state) => state.isCreating;
const getSignatureIntegrations = (state) => state.signatureIntegrations;

export const selectors = {
getBackups,
getNotifiers,
getImageIntegrations,
getCreationState,
getSignatureIntegrations,
};

Expand Down
44 changes: 4 additions & 40 deletions ui/apps/platform/src/sagas/apiTokenSagas.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { all, take, takeLatest, call, fork, put, select } from 'redux-saga/effects';
import { all, take, takeLatest, call, fork, put } from 'redux-saga/effects';

import { integrationsPath } from 'routePaths';
import * as service from 'services/APITokensService';
import { actions, types, apiTokenFormId } from 'reducers/apitokens';
import { actions as roleActions } from 'reducers/roles';
import { actions, types } from 'reducers/apitokens';
import { actions as notificationActions } from 'reducers/notifications';
import { takeEveryNewlyMatchedLocation } from 'utils/sagaEffects';
import { getFormValues } from 'redux-form';

function* getAPITokens() {
try {
Expand All @@ -17,22 +15,6 @@ function* getAPITokens() {
}
}

function* generateAPIToken() {
try {
const formData = yield select(getFormValues(apiTokenFormId));
// TODO: Remove this once we allow assigning multiple roles to a token.
const modifiedFormData = { ...formData, roles: [formData.role], role: null };
const result = yield call(service.generateAPIToken, modifiedFormData);
yield put(actions.generateAPIToken.success(result.response));
} catch (error) {
if (error.response) {
yield put(notificationActions.addNotification(error.response.data.error));
yield put(notificationActions.removeOldestNotification());
}
yield put(actions.generateAPIToken.failure(error));
}
}

function* revokeAPITokens({ ids }) {
try {
yield call(service.revokeAPITokens, ids);
Expand All @@ -57,33 +39,15 @@ function* watchLocation() {

function* watchFetchRequest() {
while (true) {
yield take([types.FETCH_API_TOKENS.REQUEST, types.GENERATE_API_TOKEN.SUCCESS]);
yield take([types.FETCH_API_TOKENS.REQUEST]);
yield fork(getAPITokens);
}
}

function* watchGenerateRequest() {
yield takeLatest(types.GENERATE_API_TOKEN.REQUEST, generateAPIToken);
}

function* watchRevokeRequest() {
yield takeLatest(types.REVOKE_API_TOKENS, revokeAPITokens);
}

function* requestFetchRoles() {
yield put(roleActions.fetchRoles.request());
}

function* watchModalOpen() {
yield takeLatest(types.START_TOKEN_GENERATION_WIZARD, requestFetchRoles);
}

export default function* integrations() {
yield all([
fork(watchLocation),
fork(watchFetchRequest),
fork(watchGenerateRequest),
fork(watchRevokeRequest),
fork(watchModalOpen),
]);
yield all([fork(watchLocation), fork(watchFetchRequest), fork(watchRevokeRequest)]);
}
45 changes: 4 additions & 41 deletions ui/apps/platform/src/sagas/clusterInitBundleSagas.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { all, take, takeLatest, call, fork, put, select } from 'redux-saga/effects';
import { all, take, call, fork, put } from 'redux-saga/effects';

import { integrationsPath } from 'routePaths';
import * as service from 'services/ClustersService';
import { actions, types, clusterInitBundleFormId } from 'reducers/clusterInitBundles';
import { actions as roleActions } from 'reducers/roles';
import { actions as notificationActions } from 'reducers/notifications';
import { actions, types } from 'reducers/clusterInitBundles';
import { takeEveryNewlyMatchedLocation } from 'utils/sagaEffects';
import { getFormValues } from 'redux-form';

function* getClusterInitBundles() {
try {
Expand All @@ -17,51 +14,17 @@ function* getClusterInitBundles() {
}
}

function* generateClusterInitBundle() {
try {
const formData = yield select(getFormValues(clusterInitBundleFormId));
const result = yield call(service.generateClusterInitBundle, formData);
yield put(actions.generateClusterInitBundle.success(result.response));
} catch (error) {
if (error.response) {
yield put(notificationActions.addNotification(error.response.data.error));
yield put(notificationActions.removeOldestNotification());
}
yield put(actions.generateClusterInitBundle.failure(error));
}
}

function* watchLocation() {
yield takeEveryNewlyMatchedLocation(integrationsPath, getClusterInitBundles);
}

function* watchFetchRequest() {
while (true) {
yield take([
types.FETCH_CLUSTER_INIT_BUNDLES.REQUEST,
types.GENERATE_CLUSTER_INIT_BUNDLE.SUCCESS,
]);
yield take([types.FETCH_CLUSTER_INIT_BUNDLES.REQUEST]);
yield fork(getClusterInitBundles);
}
}

function* watchGenerateRequest() {
yield takeLatest(types.GENERATE_CLUSTER_INIT_BUNDLE.REQUEST, generateClusterInitBundle);
}

function* requestFetchRoles() {
yield put(roleActions.fetchRoles.request());
}

function* watchModalOpen() {
yield takeLatest(types.START_CLUSTER_INIT_BUNDLE_GENERATION_WIZARD, requestFetchRoles);
}

export default function* integrations() {
yield all([
fork(watchLocation),
fork(watchFetchRequest),
fork(watchGenerateRequest),
fork(watchModalOpen),
]);
yield all([fork(watchLocation), fork(watchFetchRequest)]);
}