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

Centralize frontend API endpoints and update with versioned apis #493

Merged
merged 6 commits into from
Sep 17, 2024
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
1 change: 1 addition & 0 deletions frontend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ NODE_PATH=src/
SKIP_PREFLIGHT_CHECK=true
REACT_APP_DEBUG_TORNJAK=true
REACT_APP_TORNJAK_MANAGER=false
REACT_APP_API_VERSION=v1

##### Backend Server uri
REACT_APP_API_SERVER_URI=http://localhost:10000/
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/agent-create-join-token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { serverSelectedFunc } from 'redux/actions';
import { RootState } from 'redux/reducers';
import { ToastContainer } from "react-toastify"
import { showResponseToast, showToast } from './error-api';
import apiEndpoints from './apiConfig';

type CreateJoinTokenProp = {
globalServerSelected: string,
Expand Down Expand Up @@ -102,7 +103,7 @@ class CreateJoinToken extends Component<CreateJoinTokenProp, CreateJoinTokenStat

getApiTokenEndpoint(): string {
if (!IsManager) {
return GetApiServerUri('/api/agent/createjointoken')
return GetApiServerUri(apiEndpoints.spireJoinTokenApi)
} else if (IsManager && this.state.selectedServer !== "") {
return GetApiServerUri('/manager-api/agent/createjointoken') + "/" + this.state.selectedServer
} else {
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/components/apiConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {env} from '../env';

const API_VERSION = env.REACT_APP_API_VERSION;
const API_BASE_URL = `/api/${API_VERSION}`;
const apiEndpoints = {
spireServerInfoApi: `${API_BASE_URL}/spire/serverinfo`,
spireHealthCheckApi: `${API_BASE_URL}/spire/healthcheck`,
spireAgentsApi: `${API_BASE_URL}/spire/agents`,
spireAgentsBanApi: `${API_BASE_URL}/spire/agents/ban`,
spireJoinTokenApi: `${API_BASE_URL}/spire/agents/jointoken`,
spireEntriesApi: `${API_BASE_URL}/spire/entries`,
tornjakServerInfoApi: `${API_BASE_URL}/tornjak/serverinfo`,
tornjakSelectorsApi: `${API_BASE_URL}/tornjak/selectors`,
tornjakAgentsApi: `${API_BASE_URL}/tornjak/agents`,
tornjakClustersApi: `${API_BASE_URL}/tornjak/clusters`,
};

export default apiEndpoints;
3 changes: 2 additions & 1 deletion frontend/src/components/cluster-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
TornjakServerInfo
} from './types'
import { showResponseToast, showToast } from './error-api';
import apiEndpoints from './apiConfig';

type ClusterCreateProp = {
// dispatches a payload for the server trust domain and nodeAttestorPlugin as a ServerInfoType and has a return type of void
Expand Down Expand Up @@ -205,7 +206,7 @@ class ClusterCreate extends Component<ClusterCreateProp, ClusterCreateState> {

getApiEntryCreateEndpoint(): string {
if (!IsManager) {
return GetApiServerUri('/api/tornjak/clusters/create')
return GetApiServerUri(apiEndpoints.tornjakClustersApi)
} else if (IsManager && this.state.selectedServer !== "") {
return GetApiServerUri('/manager-api/tornjak/clusters/create') + "/" + this.state.selectedServer
} else {
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/cluster-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
DebugServerInfo,
} from './types';
import { showResponseToast, showToast } from './error-api';
import apiEndpoints from './apiConfig';

type ClusterEditProp = {
// tornjak server debug info of the selected server
Expand Down Expand Up @@ -259,7 +260,7 @@ class ClusterEdit extends Component<ClusterEditProp, ClusterEditState> {

getApiEntryCreateEndpoint(): string {
if (!IsManager) {
return GetApiServerUri('/api/tornjak/clusters/edit')
return GetApiServerUri(apiEndpoints.tornjakClustersApi)
}
if (IsManager && this.state.selectedServer !== "") {
return GetApiServerUri('/manager-api/tornjak/clusters/edit') + "/" + this.state.selectedServer
Expand Down Expand Up @@ -342,7 +343,7 @@ class ClusterEdit extends Component<ClusterEditProp, ClusterEditState> {
return
}

axios.post(endpoint, cjtData)
axios.patch(endpoint, cjtData)
.then(
res => this.setState({
message: "Request:" + JSON.stringify(cjtData, null, ' ') + "\n\nSuccess:" + JSON.stringify(res.data, null, ' '),
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/entry-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import EntryExpiryFeatures from './entry-expiry-features';
import CreateEntryJson from './entry-create-json';
import { ToastContainer } from "react-toastify"
import { showResponseToast, showToast } from './error-api';
import apiEndpoints from './apiConfig';
// import PropTypes from "prop-types"; // needed for testing will be removed on last pr

type CreateEntryProp = {
Expand Down Expand Up @@ -573,7 +574,7 @@ class CreateEntry extends Component<CreateEntryProp, CreateEntryState> {

getApiEntryCreateEndpoint(): string {
if (!IsManager) {
return GetApiServerUri('/api/entry/create')
return GetApiServerUri(apiEndpoints.spireEntriesApi)
}
if (IsManager && this.state.selectedServer !== "") {
return GetApiServerUri('/manager-api/entry/create') + "/" + this.state.selectedServer
Expand Down
Loading
Loading