From 2e81bf5b1c9b0145ca34b02d13535ecd1ce9778c Mon Sep 17 00:00:00 2001 From: Jason-Guo Date: Tue, 8 Oct 2024 11:35:52 -0400 Subject: [PATCH 01/13] add federation navbar links Signed-off-by: Jason-Guo --- frontend/src/components/navbar.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/frontend/src/components/navbar.tsx b/frontend/src/components/navbar.tsx index d00eb7a6..221376c5 100644 --- a/frontend/src/components/navbar.tsx +++ b/frontend/src/components/navbar.tsx @@ -127,6 +127,15 @@ class NavigationBar extends Component { } +
+ Federations +
+ Federations List + {(isAdmin || !withAuth) && + Create Federation + } +
+
Agents
From a21c2bd4cae30bd3cef8a41d2b02087a393510ce Mon Sep 17 00:00:00 2001 From: Jason-Guo Date: Wed, 9 Oct 2024 11:18:45 -0400 Subject: [PATCH 02/13] create copy of cluster list for federations Signed-off-by: Jason-Guo --- frontend/src/components/federation-list.tsx | 149 ++++++++++++++++++++ frontend/src/components/types.ts | 11 ++ 2 files changed, 160 insertions(+) create mode 100644 frontend/src/components/federation-list.tsx diff --git a/frontend/src/components/federation-list.tsx b/frontend/src/components/federation-list.tsx new file mode 100644 index 00000000..63c1e89d --- /dev/null +++ b/frontend/src/components/federation-list.tsx @@ -0,0 +1,149 @@ +import { Component } from 'react'; +import { connect } from 'react-redux'; +import IsManager from './is_manager'; +import Table from "tables/clusters-list-table"; +import TornjakApi from './tornjak-api-helpers'; +import { + serverSelectedFunc, + agentsListUpdateFunc, + tornjakServerInfoUpdateFunc, + serverInfoUpdateFunc, + selectorInfoFunc, + tornjakMessageFunc, + workloadSelectorInfoFunc, + agentworkloadSelectorInfoFunc, + clustersListUpdateFunc, +} from 'redux/actions'; +import { RootState } from 'redux/reducers'; +import { FederationsList, ServerInfo, TornjakServerInfo } from './types' + +type FederationsListProp = { + // dispatches a payload for list of clusters with their metadata info as an array of FederationsList Type and has a return type of void + federationsListUpdateFunc: (globalClustersList: FederationsList[]) => void, + // dispatches a payload for the tornjak error messsege and has a return type of void + tornjakMessageFunc: (globalErrorMessage: string) => void, + // dispatches a payload for the server trust domain and nodeAttestorPlugin as a ServerInfoType and has a return type of void + serverInfoUpdateFunc: (globalServerInfo: ServerInfo) => void, + // the selected server for manager mode + globalServerSelected: string, + // error/ success messege returned for a specific function + globalErrorMessage: string, + // tornjak server info of the selected server + globalTornjakServerInfo: TornjakServerInfo, + // list of federations with their metadata info as an array of FederationsList Type + globalFederationsList: FederationsList[], +} + +type FederationsListState = { + message: string // error/ success messege returned for a specific function for this specific component +} + +const Cluster = (props: { federations: FederationsList }) => ( + + {props.cluster.name} + {props.cluster.platformType} + {props.cluster.domainName} + {props.cluster.managedBy} +
+
{JSON.stringify(props.cluster.agentsList, null, ' ')}
+
+ +) + +class FederationsList extends Component { + TornjakApi: TornjakApi; + constructor(props: FederationsListProp) { + super(props); + this.TornjakApi = new TornjakApi(props); + this.state = { + message: "", + }; + } + + componentDidMount() { + if (IsManager) { + if (this.props.globalServerSelected !== "") { + this.TornjakApi.populateClustersUpdate(this.props.globalServerSelected, this.props.clustersListUpdateFunc, this.props.tornjakMessageFunc); + } + } else { + this.TornjakApi.populateLocalClustersUpdate(this.props.clustersListUpdateFunc, this.props.tornjakMessageFunc); + if (this.props.globalTornjakServerInfo && Object.keys(this.props.globalTornjakServerInfo).length) { + this.TornjakApi.populateServerInfo(this.props.globalTornjakServerInfo, this.props.serverInfoUpdateFunc); + } + } + } + + componentDidUpdate(prevProps: FederationsListProp) { + if (IsManager) { + if (prevProps.globalServerSelected !== this.props.globalServerSelected) { + this.TornjakApi.populateClustersUpdate(this.props.globalServerSelected, this.props.clustersListUpdateFunc, this.props.tornjakMessageFunc); + } + } else { + if (prevProps.globalTornjakServerInfo !== this.props.globalTornjakServerInfo) { + this.TornjakApi.populateServerInfo(this.props.globalTornjakServerInfo, this.props.serverInfoUpdateFunc); + } + } + } + + clusterList() { + if (typeof this.props.globalClustersList !== 'undefined') { + return this.props.globalClustersList.map((currentCluster: FederationsList) => { + return ; + }) + } else { + return "" + } + } + + render() { + return ( +
+

Clusters List

+ {this.props.globalErrorMessage !== "OK" && +
+
+              {this.props.globalErrorMessage}
+            
+
+ } +

+
+ + + + ) + } +} + +// Note: Needed for UI testing - will be removed after +// FederationsList.propTypes = { +// globalServerSelected: PropTypes.string, +// globalClustersList: PropTypes.array, +// globalTornjakServerInfo: PropTypes.object, +// globalErrorMessage: PropTypes.string, +// serverSelectedFunc: PropTypes.func, +// agentsListUpdateFunc: PropTypes.func, +// tornjakServerInfoUpdateFunc: PropTypes.func, +// serverInfoUpdateFunc: PropTypes.func, +// clusterTypeList: PropTypes.array, +// agentsList: PropTypes.array, +// selectorInfoFunc: PropTypes.func, +// tornjakMessageFunc: PropTypes.func, +// workloadSelectorInfoFunc: PropTypes.func, +// agentworkloadSelectorInfoFunc: PropTypes.func, +// clustersListUpdateFunc: PropTypes.func +// }; + +const mapStateToProps = (state: RootState) => ({ + globalServerSelected: state.servers.globalServerSelected, + globalClustersList: state.clusters.globalClustersList, + globalTornjakServerInfo: state.servers.globalTornjakServerInfo, + globalErrorMessage: state.tornjak.globalErrorMessage, +}) + +export default connect( + mapStateToProps, + { serverSelectedFunc, agentsListUpdateFunc, tornjakServerInfoUpdateFunc, serverInfoUpdateFunc, selectorInfoFunc, tornjakMessageFunc, workloadSelectorInfoFunc, agentworkloadSelectorInfoFunc, clustersListUpdateFunc } +)(FederationsList) + +export { FederationsList } diff --git a/frontend/src/components/types.ts b/frontend/src/components/types.ts index 61fdec20..54516810 100644 --- a/frontend/src/components/types.ts +++ b/frontend/src/components/types.ts @@ -46,6 +46,17 @@ export interface ClustersList { agentsList: Array; // List of agents associated with the cluster } +// federations +export interface FederationsList { + name: string; // Name of Cluster + editedName: string; // Edited Name if Cluster Name is edited from original + creationTime: string; // Time cluster is created + domainName: string; // Domain Name of cluster if any + managedBy: string; // Person/ entity managing the cluster + platformType: string; // Platform type of the cluster + agentsList: Array; // List of agents associated with the cluster +} + // entries export interface EntriesList { // From https://github.com/spiffe/spire-api-sdk/blob/main/proto/spire/api/types/entry.pb.go From 9a3ebfbba4bf73a403b98961298cdea10cbd6cb6 Mon Sep 17 00:00:00 2001 From: Jason-Guo Date: Fri, 11 Oct 2024 11:35:41 -0400 Subject: [PATCH 03/13] add route to federations list Signed-off-by: Jason-Guo --- frontend/src/App.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 14dae335..e8607960 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -7,6 +7,7 @@ import NavigationBar from "./components/navbar"; import SelectServer from "./components/select-server"; import ClusterList from "./components/cluster-list"; import ClusterManagement from "./components/cluster-management"; +import FederationList from "./components/federation-list"; import AgentList from "./components/agent-list"; import CreateJoinToken from "./components/agent-create-join-token"; import EntryList from "./components/entry-list"; @@ -44,6 +45,7 @@ function App() { {IsManager &&
} + From aa3f54bf46763c8d6e0a6bb44921c8cafb6be8d1 Mon Sep 17 00:00:00 2001 From: Jason-Guo Date: Fri, 11 Oct 2024 11:39:54 -0400 Subject: [PATCH 04/13] update names for classes and functions Signed-off-by: Jason-Guo --- frontend/src/components/federation-list.tsx | 36 ++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/federation-list.tsx b/frontend/src/components/federation-list.tsx index 63c1e89d..227b01db 100644 --- a/frontend/src/components/federation-list.tsx +++ b/frontend/src/components/federation-list.tsx @@ -18,8 +18,8 @@ import { RootState } from 'redux/reducers'; import { FederationsList, ServerInfo, TornjakServerInfo } from './types' type FederationsListProp = { - // dispatches a payload for list of clusters with their metadata info as an array of FederationsList Type and has a return type of void - federationsListUpdateFunc: (globalClustersList: FederationsList[]) => void, + // dispatches a payload for list of federations with their metadata info as an array of FederationsList Type and has a return type of void + federationsListUpdateFunc: (globalFederationsList: FederationsList[]) => void, // dispatches a payload for the tornjak error messsege and has a return type of void tornjakMessageFunc: (globalErrorMessage: string) => void, // dispatches a payload for the server trust domain and nodeAttestorPlugin as a ServerInfoType and has a return type of void @@ -38,19 +38,19 @@ type FederationsListState = { message: string // error/ success messege returned for a specific function for this specific component } -const Cluster = (props: { federations: FederationsList }) => ( +const Federation = (props: { federation: FederationsList }) => (
- - - - + + + + ) -class FederationsList extends Component { +class FederationList extends Component { TornjakApi: TornjakApi; constructor(props: FederationsListProp) { super(props); @@ -76,7 +76,7 @@ class FederationsList extends Component { - return ; + federationList() { + if (typeof this.props.globalFederationsList !== 'undefined') { + return this.props.globalFederationsList.map((currentFederation: FederationsList) => { + return ; }) } else { return "" @@ -98,7 +98,7 @@ class FederationsList extends Component -

Clusters List

+

Federations List

{this.props.globalErrorMessage !== "OK" &&
@@ -108,7 +108,7 @@ class FederationsList extends Component
-
{props.cluster.name}{props.cluster.platformType}{props.cluster.domainName}{props.cluster.managedBy}{props.federation.name}{props.federation.platformType}{props.federation.domainName}{props.federation.managedBy}
-
{JSON.stringify(props.cluster.agentsList, null, ' ')}
+
{JSON.stringify(props.federation.agentsList, null, ' ')}
+
) @@ -144,6 +144,6 @@ const mapStateToProps = (state: RootState) => ({ export default connect( mapStateToProps, { serverSelectedFunc, agentsListUpdateFunc, tornjakServerInfoUpdateFunc, serverInfoUpdateFunc, selectorInfoFunc, tornjakMessageFunc, workloadSelectorInfoFunc, agentworkloadSelectorInfoFunc, clustersListUpdateFunc } -)(FederationsList) +)(FederationList) -export { FederationsList } +export { FederationList } From 5b1267ff5f543a62c680f571fc8668faea943532 Mon Sep 17 00:00:00 2001 From: Jason-Guo Date: Tue, 15 Oct 2024 09:40:49 -0400 Subject: [PATCH 05/13] add api call on render and removed unavailable manager version call Signed-off-by: Jason-Guo --- frontend/src/components/apiConfig.ts | 1 + frontend/src/components/federation-list.tsx | 22 +++++-------------- .../src/components/tornjak-api-helpers.tsx | 21 +++++++++++++++++- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/apiConfig.ts b/frontend/src/components/apiConfig.ts index 22d64724..7ffcc0f5 100644 --- a/frontend/src/components/apiConfig.ts +++ b/frontend/src/components/apiConfig.ts @@ -9,6 +9,7 @@ const apiEndpoints = { spireAgentsBanApi: `${API_BASE_URL}/spire/agents/ban`, spireJoinTokenApi: `${API_BASE_URL}/spire/agents/jointoken`, spireEntriesApi: `${API_BASE_URL}/spire/entries`, + spireFederationsApi: `${API_BASE_URL}/spire/federations`, tornjakServerInfoApi: `${API_BASE_URL}/tornjak/serverinfo`, tornjakSelectorsApi: `${API_BASE_URL}/tornjak/selectors`, tornjakAgentsApi: `${API_BASE_URL}/tornjak/agents`, diff --git a/frontend/src/components/federation-list.tsx b/frontend/src/components/federation-list.tsx index 227b01db..e0fc4f1f 100644 --- a/frontend/src/components/federation-list.tsx +++ b/frontend/src/components/federation-list.tsx @@ -61,27 +61,15 @@ class FederationList extends Component { }) } + // populateLocalFederationsUpdate - returns the list of federations with their info in Local mode for the server + populateLocalFederationsUpdate = (federationsListUpdateFunc: { + (globalFederationsList: FederationsList[]): void; + }, + tornjakMessageFunc: { (globalErrorMessage: string): void; }) => { + axios.get(GetApiServerUri(apiEndpoints.spireFederationsApi), { crossdomain: true }) + .then(response => { + if (!response.data["federations"]) { + federationsListUpdateFunc([]); + } else { federationsListUpdateFunc(response.data["federations"]); } + tornjakMessageFunc(response.statusText); + }) + .catch((error) => { + showResponseToast(error, { caption: "Could not populate local federations." }) + federationsListUpdateFunc([]); + tornjakMessageFunc("Error retrieving: " + error.message); + }) + } + // populateLocalClustersUpdate - returns the list of clusters with their info in Local mode for the server populateLocalClustersUpdate = ( clustersListUpdateFunc: { (globalClustersList: ClustersList[]): void }, From 1b9ef96a8d00717867fe1425bf486245973c098c Mon Sep 17 00:00:00 2001 From: Jason-Guo Date: Tue, 15 Oct 2024 10:06:17 -0400 Subject: [PATCH 06/13] fix update list func for federations Signed-off-by: Jason-Guo --- frontend/src/components/federation-list.tsx | 3 ++- frontend/src/redux/actions/index.ts | 15 +++++++++++++-- frontend/src/redux/actions/types.ts | 13 ++++++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/federation-list.tsx b/frontend/src/components/federation-list.tsx index e0fc4f1f..8184c23f 100644 --- a/frontend/src/components/federation-list.tsx +++ b/frontend/src/components/federation-list.tsx @@ -13,6 +13,7 @@ import { workloadSelectorInfoFunc, agentworkloadSelectorInfoFunc, clustersListUpdateFunc, + federationsListUpdateFunc } from 'redux/actions'; import { RootState } from 'redux/reducers'; import { FederationsList, ServerInfo, TornjakServerInfo } from './types' @@ -131,7 +132,7 @@ const mapStateToProps = (state: RootState) => ({ export default connect( mapStateToProps, - { serverSelectedFunc, agentsListUpdateFunc, tornjakServerInfoUpdateFunc, serverInfoUpdateFunc, selectorInfoFunc, tornjakMessageFunc, workloadSelectorInfoFunc, agentworkloadSelectorInfoFunc, clustersListUpdateFunc } + { serverSelectedFunc, agentsListUpdateFunc, tornjakServerInfoUpdateFunc, serverInfoUpdateFunc, selectorInfoFunc, tornjakMessageFunc, workloadSelectorInfoFunc, agentworkloadSelectorInfoFunc, clustersListUpdateFunc, federationsListUpdateFunc } )(FederationList) export { FederationList } diff --git a/frontend/src/redux/actions/index.ts b/frontend/src/redux/actions/index.ts index 3a9b2f8a..74bba8d7 100644 --- a/frontend/src/redux/actions/index.ts +++ b/frontend/src/redux/actions/index.ts @@ -44,7 +44,7 @@ import { GLOBAL_SPIRE_HEALTH_CHECK_TIME, SpireHealthCheckTimeAction, GLOBAL_DEBUG_SERVER_INFO, - DebugServerInfoAction + DebugServerInfoAction, GLOBAL_FEDERATIONS_LIST, FederationsListAction } from './types'; import { @@ -58,7 +58,7 @@ import { TornjakServerInfo, WorkloadSelectorInfoLabels, SpireHealthCheckFreq, - DebugServerInfo + DebugServerInfo, FederationsList } from 'components/types'; // Expected input - spire debug server info @@ -319,6 +319,17 @@ export function agentsListUpdateFunc(globalAgentsList: AgentsList[]): ThunkActio } } +// Expected input - List of federations with their info +// federationsListUpdateFunc returns the list of federations with their info +export function federationsListUpdateFunc(globalFederationsList: FederationsList[]): ThunkAction { + return dispatch => { + dispatch({ + type: GLOBAL_FEDERATIONS_LIST, + payload: globalFederationsList + }); + } +} + // Expected input - // [ // "workloadselector1": [ diff --git a/frontend/src/redux/actions/types.ts b/frontend/src/redux/actions/types.ts index d4541e09..7d54c92d 100644 --- a/frontend/src/redux/actions/types.ts +++ b/frontend/src/redux/actions/types.ts @@ -10,7 +10,7 @@ import { TornjakServerInfo, WorkloadSelectorInfoLabels, SpireHealthCheckFreq, - DebugServerInfo + DebugServerInfo, FederationsList } from "components/types"; // auth @@ -50,6 +50,17 @@ export interface AgentWorkloadSelectorInfoAction extends Action { + payload: FederationsList[]; +} + // clusters export const GLOBAL_CLUSTERS_LIST = 'GLOBAL_CLUSTERS_LIST'; export const GLOBAL_CLUSTER_TYPE_INFO = 'GLOBAL_CLUSTER_TYPE_INFO'; From 435341ff64d9c718a805e6527b83f2dee010f334 Mon Sep 17 00:00:00 2001 From: Jason-Guo Date: Tue, 15 Oct 2024 10:06:35 -0400 Subject: [PATCH 07/13] update route url Signed-off-by: Jason-Guo --- frontend/src/components/navbar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/navbar.tsx b/frontend/src/components/navbar.tsx index 221376c5..8b1cc2a7 100644 --- a/frontend/src/components/navbar.tsx +++ b/frontend/src/components/navbar.tsx @@ -128,7 +128,7 @@ class NavigationBar extends Component {
- Federations + Federations
Federations List {(isAdmin || !withAuth) && From fb6d13ca4e1e8a4eb998abe5a6923a3e33f6368f Mon Sep 17 00:00:00 2001 From: Jason-Guo Date: Mon, 21 Oct 2024 10:34:53 -0400 Subject: [PATCH 08/13] Create table and types for federations Signed-off-by: Jason-Guo --- frontend/src/components/federation-list.tsx | 19 ++- .../src/components/tornjak-api-helpers.tsx | 9 +- frontend/src/components/types.ts | 19 ++- .../src/redux/reducers/federationsReducer.ts | 21 +++ frontend/src/redux/reducers/index.ts | 2 + .../src/tables/federations-list-table.tsx | 126 ++++++++++++++++++ 6 files changed, 175 insertions(+), 21 deletions(-) create mode 100644 frontend/src/redux/reducers/federationsReducer.ts create mode 100644 frontend/src/tables/federations-list-table.tsx diff --git a/frontend/src/components/federation-list.tsx b/frontend/src/components/federation-list.tsx index 8184c23f..7b4e6d66 100644 --- a/frontend/src/components/federation-list.tsx +++ b/frontend/src/components/federation-list.tsx @@ -1,7 +1,7 @@ import { Component } from 'react'; import { connect } from 'react-redux'; import IsManager from './is_manager'; -import Table from "tables/clusters-list-table"; +import Table from "tables/federations-list-table"; import TornjakApi from './tornjak-api-helpers'; import { serverSelectedFunc, @@ -41,13 +41,9 @@ type FederationsListState = { const Federation = (props: { federation: FederationsList }) => (
- - - - - + + + ) @@ -75,9 +71,10 @@ class FederationList extends Component { - return ; + return this.props.globalFederationsList.map((currentFederation: FederationsList, index) => { + return ; }) } else { return "" @@ -86,7 +83,7 @@ class FederationList extends Component +

Federations List

{this.props.globalErrorMessage !== "OK" &&
diff --git a/frontend/src/components/tornjak-api-helpers.tsx b/frontend/src/components/tornjak-api-helpers.tsx index d6f2334a..48944d17 100644 --- a/frontend/src/components/tornjak-api-helpers.tsx +++ b/frontend/src/components/tornjak-api-helpers.tsx @@ -10,7 +10,8 @@ import { ServerInfo, EntriesList, ClustersList, - DebugServerInfo, FederationsList + DebugServerInfo, + FederationsList } from './types'; import KeycloakService from "auth/KeycloakAuth"; import { showResponseToast } from './error-api'; @@ -235,9 +236,11 @@ class TornjakApi extends Component { tornjakMessageFunc: { (globalErrorMessage: string): void; }) => { axios.get(GetApiServerUri(apiEndpoints.spireFederationsApi), { crossdomain: true }) .then(response => { - if (!response.data["federations"]) { + console.log(response) + console.log(response.data["federation_relationships"]) + if (!response.data["federation_relationships"]) { federationsListUpdateFunc([]); - } else { federationsListUpdateFunc(response.data["federations"]); } + } else { federationsListUpdateFunc(response.data["federation_relationships"]); } tornjakMessageFunc(response.statusText); }) .catch((error) => { diff --git a/frontend/src/components/types.ts b/frontend/src/components/types.ts index 54516810..ce54a69b 100644 --- a/frontend/src/components/types.ts +++ b/frontend/src/components/types.ts @@ -18,6 +18,15 @@ export interface Selector { value: string; } +export interface FederationProfileSpiffeResponse { + endpoint_spiffe_id: string; +} + +export interface BundleEndpointProfile { + HttpsSpiffe?: FederationProfileSpiffeResponse + HttpsWeb?: object +} + export interface AgentsList { // From https://github.com/spiffe/spire-api-sdk/blob/main/proto/spire/api/types/agent.pb.go id: SPIFFEID; // SPIFFE ID of the agent. @@ -48,13 +57,9 @@ export interface ClustersList { // federations export interface FederationsList { - name: string; // Name of Cluster - editedName: string; // Edited Name if Cluster Name is edited from original - creationTime: string; // Time cluster is created - domainName: string; // Domain Name of cluster if any - managedBy: string; // Person/ entity managing the cluster - platformType: string; // Platform type of the cluster - agentsList: Array; // List of agents associated with the cluster + trust_domain: string; + bundle_endpoint_url: string; + BundleEndpointProfile: BundleEndpointProfile; } // entries diff --git a/frontend/src/redux/reducers/federationsReducer.ts b/frontend/src/redux/reducers/federationsReducer.ts new file mode 100644 index 00000000..8ebabfff --- /dev/null +++ b/frontend/src/redux/reducers/federationsReducer.ts @@ -0,0 +1,21 @@ +import { + FederationsListAction, + FederationsReducerState, + GLOBAL_FEDERATIONS_LIST, +} from '../actions/types'; + +const initialState: FederationsReducerState = { + globalFederationsList: [], +}; + +export default function federationsReducer(state: FederationsReducerState = initialState, action: FederationsListAction) { + switch (action.type) { + case GLOBAL_FEDERATIONS_LIST: + return { + ...state, + globalFederationsList: action.payload + }; + default: + return state; + } +} \ No newline at end of file diff --git a/frontend/src/redux/reducers/index.ts b/frontend/src/redux/reducers/index.ts index ec38764f..ef1c7b85 100644 --- a/frontend/src/redux/reducers/index.ts +++ b/frontend/src/redux/reducers/index.ts @@ -5,10 +5,12 @@ import entriesReducer from './entriesReducer'; import tornjakReducer from './tornjakReducer'; import {combineReducers} from 'redux'; import authReducer from './authReducer'; +import federationsReducer from "./federationsReducer"; const allReducers = combineReducers({ servers : serversReducer, clusters : clustersReducer, + federations: federationsReducer, agents : agentsReducer, entries : entriesReducer, tornjak: tornjakReducer, diff --git a/frontend/src/tables/federations-list-table.tsx b/frontend/src/tables/federations-list-table.tsx new file mode 100644 index 00000000..280447e7 --- /dev/null +++ b/frontend/src/tables/federations-list-table.tsx @@ -0,0 +1,126 @@ +import React from "react"; +import { connect } from 'react-redux'; +import IsManager from 'components/is_manager'; +import { + federationsListUpdateFunc +} from 'redux/actions'; +import Table from './list-table'; +import { FederationsList } from "components/types"; +import { RootState } from "redux/reducers"; +import TornjakApi from 'components/tornjak-api-helpers'; + +// FederationListTable takes in +// listTableData: federation data to be rendered on table +// returns federations data inside a carbon component table with specified functions + +type FederationsListTableProp = { + // dispatches a payload for list of federations with their metadata info as an array of FederationsList Type and has a return type of void + federationsListUpdateFunc: (globalFederationsList: FederationsList[]) => void, + // data provided to the federations table + data: { + key: string, + props: { federation: FederationsList } + }[] | string | JSX.Element[], + id: string, + // list of federations with their metadata info as an array of FederationsList Type + globalFederationsList: FederationsList[], + // the selected server for manager mode + globalServerSelected: string, +} + +type FederationsListTableState = { + listData: { key: string, props: { federation: FederationsList } }[] | FederationsList[] | string | JSX.Element[], + listTableData: { + id: string; + federationTrustDomain: string; + federationBundleUrl: string; + federationBundleProfile: string; + }[] + +} +class FederationsListTable extends React.Component { + TornjakApi: TornjakApi; + constructor(props: FederationsListTableProp) { + super(props); + this.TornjakApi = new TornjakApi(props); + this.state = { + listData: props.data, + listTableData: [], + }; + this.prepareTableData = this.prepareTableData.bind(this); + } + + componentDidMount() { + this.prepareTableData(); + } + componentDidUpdate(prevProps: FederationsListTableProp) { + if (prevProps !== this.props) { + this.setState({ + listData: this.props.globalFederationsList + }) + this.prepareTableData(); + } + } + + prepareTableData() { + const { data } = this.props; + let listData: { props: { federation: FederationsList; }; }[] | ({ key: string; props: { federation: FederationsList; }; } | JSX.Element)[] = []; + if (typeof (data) === "string" || data === undefined) + return + data.forEach(val => listData.push(Object.assign({}, val))); + let listtabledata: { id: string; federationTrustDomain: string; federationBundleUrl: string; federationBundleProfile: string }[] = []; + for (let i = 0; i < listData.length; i++) { + listtabledata[i] = { id: "", federationTrustDomain: "", federationBundleUrl: "", federationBundleProfile: "" }; + listtabledata[i]["id"] = (i + 1).toString(); + listtabledata[i]["federationTrustDomain"] = listData[i].props.federation.trust_domain; + listtabledata[i]["federationBundleUrl"] = listData[i].props.federation.bundle_endpoint_url; + listtabledata[i]["federationBundleUrl"] = listData[i].props.federation.BundleEndpointProfile; + } + this.setState({ + listTableData: listtabledata + }) + } + + render() { + const { listTableData } = this.state; + const headerData = [ + { + header: '#No', + key: 'id', + }, + { + header: 'Trust Domain', + key: 'federationTrustDomain', + }, + { + header: 'Bundle Endpoint URL', + key: 'federationBundleURL', + }, + { + header: 'Bundle Endpoint Profile', + key: 'federationBundleProfile', + }, + ]; + return ( +
+
{props.federation.name}{props.federation.platformType}{props.federation.domainName}{props.federation.managedBy}
-
{JSON.stringify(props.federation.agentsList, null, ' ')}
-
{props.federation.trust_domain}{props.federation.bundle_endpoint_url}{props.federation.BundleEndpointProfile.HttpsSpiffe ? 'https_spiffe' : 'https_web'}
{}} + banEntity={undefined} + downloadEntity={undefined} /> + + ); + } +} + +const mapStateToProps = (state: RootState) => ({ + globalServerSelected: state.servers.globalServerSelected, + globalFederationsList: state.federations.globalFederationsList, +}) + +export default connect( + mapStateToProps, + { federationsListUpdateFunc } +)(FederationsListTable) \ No newline at end of file From e84a927c70f2c3945af2ae8bc8c118fb31ccd0b1 Mon Sep 17 00:00:00 2001 From: Jason-Guo Date: Mon, 21 Oct 2024 10:50:48 -0400 Subject: [PATCH 09/13] correctly display data on table Signed-off-by: Jason-Guo --- frontend/src/components/federation-list.tsx | 3 +-- frontend/src/components/tornjak-api-helpers.tsx | 2 -- frontend/src/tables/federations-list-table.tsx | 4 ++-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/federation-list.tsx b/frontend/src/components/federation-list.tsx index 7b4e6d66..d6b9f2e7 100644 --- a/frontend/src/components/federation-list.tsx +++ b/frontend/src/components/federation-list.tsx @@ -71,7 +71,6 @@ class FederationList extends Component { return ; @@ -122,7 +121,7 @@ class FederationList extends Component ({ globalServerSelected: state.servers.globalServerSelected, - globalClustersList: state.clusters.globalClustersList, + globalFederationsList: state.federations.globalFederationsList, globalTornjakServerInfo: state.servers.globalTornjakServerInfo, globalErrorMessage: state.tornjak.globalErrorMessage, }) diff --git a/frontend/src/components/tornjak-api-helpers.tsx b/frontend/src/components/tornjak-api-helpers.tsx index 48944d17..44edb71f 100644 --- a/frontend/src/components/tornjak-api-helpers.tsx +++ b/frontend/src/components/tornjak-api-helpers.tsx @@ -236,8 +236,6 @@ class TornjakApi extends Component { tornjakMessageFunc: { (globalErrorMessage: string): void; }) => { axios.get(GetApiServerUri(apiEndpoints.spireFederationsApi), { crossdomain: true }) .then(response => { - console.log(response) - console.log(response.data["federation_relationships"]) if (!response.data["federation_relationships"]) { federationsListUpdateFunc([]); } else { federationsListUpdateFunc(response.data["federation_relationships"]); } diff --git a/frontend/src/tables/federations-list-table.tsx b/frontend/src/tables/federations-list-table.tsx index 280447e7..15a3f1e9 100644 --- a/frontend/src/tables/federations-list-table.tsx +++ b/frontend/src/tables/federations-list-table.tsx @@ -74,7 +74,7 @@ class FederationsListTable extends React.Component Date: Mon, 21 Oct 2024 13:20:05 -0400 Subject: [PATCH 10/13] removed unused imports Signed-off-by: Jason-Guo --- frontend/src/components/federation-list.tsx | 1 - frontend/src/tables/federations-list-table.tsx | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/frontend/src/components/federation-list.tsx b/frontend/src/components/federation-list.tsx index d6b9f2e7..b66453a7 100644 --- a/frontend/src/components/federation-list.tsx +++ b/frontend/src/components/federation-list.tsx @@ -1,6 +1,5 @@ import { Component } from 'react'; import { connect } from 'react-redux'; -import IsManager from './is_manager'; import Table from "tables/federations-list-table"; import TornjakApi from './tornjak-api-helpers'; import { diff --git a/frontend/src/tables/federations-list-table.tsx b/frontend/src/tables/federations-list-table.tsx index 15a3f1e9..8820d544 100644 --- a/frontend/src/tables/federations-list-table.tsx +++ b/frontend/src/tables/federations-list-table.tsx @@ -1,6 +1,5 @@ import React from "react"; -import { connect } from 'react-redux'; -import IsManager from 'components/is_manager'; +import { connect } from 'react-redux';= import { federationsListUpdateFunc } from 'redux/actions'; From d02dab04f7c573c90eeaf4d8d0d4f2b9a04b515a Mon Sep 17 00:00:00 2001 From: Jason-Guo Date: Mon, 21 Oct 2024 13:22:04 -0400 Subject: [PATCH 11/13] comment out Create Federation sublink Signed-off-by: Jason-Guo --- frontend/src/components/navbar.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/navbar.tsx b/frontend/src/components/navbar.tsx index 8b1cc2a7..eb0470f5 100644 --- a/frontend/src/components/navbar.tsx +++ b/frontend/src/components/navbar.tsx @@ -131,9 +131,10 @@ class NavigationBar extends Component { Federations
Federations List - {(isAdmin || !withAuth) && - Create Federation - } + {/* To be added */} + {/*{(isAdmin || !withAuth) &&*/} + {/* Create Federation*/} + {/*}*/}
From aa3fd35a22ab4f44debb7f0bb33dd9fd54e4f7d8 Mon Sep 17 00:00:00 2001 From: Jason-Guo Date: Tue, 22 Oct 2024 09:08:31 -0400 Subject: [PATCH 12/13] add Info column to federation table Signed-off-by: Jason-Guo --- frontend/src/components/federation-list.tsx | 5 ++- frontend/src/components/types.ts | 34 ++++++++++++++----- .../src/tables/federations-list-table.tsx | 18 +++++----- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/frontend/src/components/federation-list.tsx b/frontend/src/components/federation-list.tsx index b66453a7..37d82348 100644 --- a/frontend/src/components/federation-list.tsx +++ b/frontend/src/components/federation-list.tsx @@ -1,4 +1,4 @@ -import { Component } from 'react'; +import React, { Component } from 'react'; import { connect } from 'react-redux'; import Table from "tables/federations-list-table"; import TornjakApi from './tornjak-api-helpers'; @@ -43,6 +43,9 @@ const Federation = (props: { federation: FederationsList }) => (
+ ) diff --git a/frontend/src/components/types.ts b/frontend/src/components/types.ts index ce54a69b..89d257f8 100644 --- a/frontend/src/components/types.ts +++ b/frontend/src/components/types.ts @@ -18,15 +18,6 @@ export interface Selector { value: string; } -export interface FederationProfileSpiffeResponse { - endpoint_spiffe_id: string; -} - -export interface BundleEndpointProfile { - HttpsSpiffe?: FederationProfileSpiffeResponse - HttpsWeb?: object -} - export interface AgentsList { // From https://github.com/spiffe/spire-api-sdk/blob/main/proto/spire/api/types/agent.pb.go id: SPIFFEID; // SPIFFE ID of the agent. @@ -56,10 +47,35 @@ export interface ClustersList { } // federations +export interface FederationProfileSpiffeResponse { + endpoint_spiffe_id: string; +} + +export interface BundleEndpointProfile { + HttpsSpiffe?: FederationProfileSpiffeResponse + HttpsWeb?: object +} + +export interface x509Authority { + asn1: string +} + +export interface JwtAuthority { + public_key: string + key_id: string +} + +export interface TrustDomainBundle { + trust_domain: string + x509_authorities: Array + jwt_authorities: Array +} + export interface FederationsList { trust_domain: string; bundle_endpoint_url: string; BundleEndpointProfile: BundleEndpointProfile; + trust_domain_bundle: TrustDomainBundle; } // entries diff --git a/frontend/src/tables/federations-list-table.tsx b/frontend/src/tables/federations-list-table.tsx index 8820d544..7ba92f78 100644 --- a/frontend/src/tables/federations-list-table.tsx +++ b/frontend/src/tables/federations-list-table.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { connect } from 'react-redux';= +import { connect } from 'react-redux'; import { federationsListUpdateFunc } from 'redux/actions'; @@ -29,12 +29,7 @@ type FederationsListTableProp = { type FederationsListTableState = { listData: { key: string, props: { federation: FederationsList } }[] | FederationsList[] | string | JSX.Element[], - listTableData: { - id: string; - federationTrustDomain: string; - federationBundleUrl: string; - federationBundleProfile: string; - }[] + listTableData: { id: string, [x: string]: string; }[] } class FederationsListTable extends React.Component { @@ -67,13 +62,14 @@ class FederationsListTable extends React.Component listData.push(Object.assign({}, val))); - let listtabledata: { id: string; federationTrustDomain: string; federationBundleUrl: string; federationBundleProfile: string }[] = []; + let listtabledata: { id: string; federationTrustDomain: string; federationBundleUrl: string; federationBundleProfile: string; info: string }[] = []; for (let i = 0; i < listData.length; i++) { - listtabledata[i] = { id: "", federationTrustDomain: "", federationBundleUrl: "", federationBundleProfile: "" }; + listtabledata[i] = { id: "", federationTrustDomain: "", federationBundleUrl: "", federationBundleProfile: "", info: "" }; listtabledata[i]["id"] = (i + 1).toString(); listtabledata[i]["federationTrustDomain"] = listData[i].props.federation.trust_domain; listtabledata[i]["federationBundleUrl"] = listData[i].props.federation.bundle_endpoint_url; listtabledata[i]["federationBundleProfile"] = listData[i].props.federation.BundleEndpointProfile.HttpsSpiffe ? 'https_spiffe' : 'https_web'; + listtabledata[i]["info"] = JSON.stringify(listData[i].props.federation, null, ' '); } this.setState({ listTableData: listtabledata @@ -99,6 +95,10 @@ class FederationsListTable extends React.Component From e3ada1d23f1f1d690bdfda1c7186408192d4b6ad Mon Sep 17 00:00:00 2001 From: Jason-Guo Date: Tue, 22 Oct 2024 09:09:55 -0400 Subject: [PATCH 13/13] moved federation location on navbar Signed-off-by: Jason-Guo --- frontend/src/components/navbar.tsx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/navbar.tsx b/frontend/src/components/navbar.tsx index eb0470f5..5b11249a 100644 --- a/frontend/src/components/navbar.tsx +++ b/frontend/src/components/navbar.tsx @@ -127,16 +127,6 @@ class NavigationBar extends Component { } -
- Federations -
- Federations List - {/* To be added */} - {/*{(isAdmin || !withAuth) &&*/} - {/* Create Federation*/} - {/*}*/} -
-
Agents
@@ -155,6 +145,16 @@ class NavigationBar extends Component { }
+
+ Federations +
+ Federations List + {/* To be added */} + {/*{(isAdmin || !withAuth) &&*/} + {/* Create Federation*/} + {/*}*/} +
+
{props.federation.trust_domain} {props.federation.bundle_endpoint_url} {props.federation.BundleEndpointProfile.HttpsSpiffe ? 'https_spiffe' : 'https_web'}
+
{JSON.stringify(props.federation, null, ' ')}
+