Commit 83db17eb authored by Guillermo Sanz López's avatar Guillermo Sanz López
Browse files

add coment to code

parent ef63b7a6
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
import axiosInstance from './axiosInstance'
import axiosMockAdapter from 'axios-mock-adapter'
import axios from 'axios'


export const getInvokers = async () => {
  return axiosInstance.get(`/resources/invokers`)
@@ -19,3 +22,11 @@ export const getProviderServices = async providerId => {
export const getEvents = async id => {
  return axiosInstance.get(`/resources/events/${id}`)
}

export const getUsers = async id => {
  return axiosInstance1.get(`/users`)
}

export const getUser = async id => {
  return axiosInstance.get(`/users/${id}`)
}
+12 −1
Original line number Diff line number Diff line
@@ -4,10 +4,12 @@ import authConfig from 'src/configs/auth'

const DEBUG_SHOW_DATA = true

// Create axios instance
const axiosInstance = axios.create({
  baseURL: process.env.NEXT_PUBLIC_API_BASE_URL
})

// RESPONSE interceptor for API calls
axiosInstance.interceptors.request.use(
  req => {
    if (process.env.NODE_ENV === 'development') {
@@ -20,6 +22,8 @@ axiosInstance.interceptors.request.use(

    const accessToken = getAccessToken()
    const refreshToken = getRefreshToken()

    // if token existe and request is not refresh, add token to headers
    if (accessToken && req.url !== '/refresh') {
      req.headers['Authorization'] = `Bearer ${accessToken}`
    }
@@ -28,7 +32,7 @@ axiosInstance.interceptors.request.use(
      req.headers['Authorization'] = `Bearer ${refreshToken}`
    }

    return req
    return req  // return request
  },
  error => {
    console.error('🔴 REQUEST ERROR: ', error.message)
@@ -37,8 +41,11 @@ axiosInstance.interceptors.request.use(
  }
)

// RESPONSE interceptor for API calls
axiosInstance.interceptors.response.use(
  res => {

    // if env is development, show log
    if (process.env.NODE_ENV === 'development') {
      if (DEBUG_SHOW_DATA) {
        console.log(`🟢 ${res.status} ${res.config.url}`, res.data)
@@ -49,6 +56,8 @@ axiosInstance.interceptors.response.use(

    return res
  },

  // try to refresh token if 401 error
  async error => {
    console.error('🔴 RESPONSE ERROR: ', error.message)

@@ -58,9 +67,11 @@ axiosInstance.interceptors.response.use(
      error.response.config.url !== '/auth/me' &&
      error.response.config.url !== '/refresh'
    ) {
      // try to refresh token
      const refreshToken = getRefreshToken()
      if (refreshToken) {
        try {
          // Post request to refresh token
          const response = await axiosInstance.post(authConfig.refreshEndpoint)
          setAccessToken(response.data.access_token)

+4 −3
Original line number Diff line number Diff line
@@ -15,10 +15,11 @@ export const setAccessToken = accessToken => {
  })
}

// getAccessToken() se utiliza para obtener el token de acceso almacenado en las cookies
export const getAccessToken = () => {
  return Cookies.get(ACCESS_TOKEN_KEY)
    ? decryptString(Cookies.get(ACCESS_TOKEN_KEY), ACCESS_TOKEN_ENCRYPTION_KEY)
    : null
  return Cookies.get(ACCESS_TOKEN_KEY) // comprueba si la cookie existe
    ? decryptString(Cookies.get(ACCESS_TOKEN_KEY), ACCESS_TOKEN_ENCRYPTION_KEY) // si existe, desencripta el token de acceso uitlizando la clave de cifrado
    : null // si no existe, devuelve null
}

export const setRefreshToken = refreshToken => {
+17 −1
Original line number Diff line number Diff line
@@ -6,8 +6,12 @@ const Dashboard = () => {

  return (
    <Grid container spacing={6}>

      {/* Card Runing containers*/}
      <Grid item xs={12} sm={4}>
        <iframe
          // src = url del panel de grafana a incrustar
          // NEXT_PUBLIC_GRAFANA_BASE_URL="http://10.95.235.20:3001"
          src={`${
            process.env.NEXT_PUBLIC_GRAFANA_BASE_URL
          }/d-solo/f66dea48-ca2f-46fb-a6f0-50bf50502d74/docker-monitoring?orgId=1&refresh=10s&theme=${
@@ -15,9 +19,11 @@ const Dashboard = () => {
          }&panelId=7`}
          width='100%'
          height='105'
          style={{ border: 0 }}
          style={{ border: 0 }}  // delete border of iframe
        />
      </Grid>

      {/* Card Total Memory Usage */}
      <Grid item xs={12} sm={4}>
        <iframe
          src={`${
@@ -30,6 +36,8 @@ const Dashboard = () => {
          style={{ border: 0 }}
        />
      </Grid>

      {/* Card Total CPU Usage */}
      <Grid item xs={12} sm={4}>
        <iframe
          src={`${
@@ -42,6 +50,8 @@ const Dashboard = () => {
          style={{ border: 0 }}
        />
      </Grid>

      {/* Car graph CPU Usage*/}
      <Grid item xs={12}>
        <iframe
          src={`${
@@ -54,6 +64,8 @@ const Dashboard = () => {
          style={{ border: 0 }}
        />
      </Grid>

      {/* Card graph Memory Usage */}
      <Grid item xs={12}>
        <iframe
          src={`${
@@ -66,6 +78,8 @@ const Dashboard = () => {
          style={{ border: 0 }}
        />
      </Grid>

      {/* Card Network Rx */}
      <Grid item xs={12} sm={6}>
        <iframe
          src={`${
@@ -78,6 +92,8 @@ const Dashboard = () => {
          style={{ border: 0 }}
        />
      </Grid>

      {/* Card Network Tx */}
      <Grid item xs={12} sm={6}>
        <iframe
          src={`${
+14 −38
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import { styled } from '@mui/material/styles'
import Typography from '@mui/material/Typography'
import CardHeader from '@mui/material/CardHeader'
import PageHeader from 'src/@core/components/page-header'
import Button from '@mui/material/Button'
import Paper from '@mui/material/Paper'
import Table from '@mui/material/Table'
import TableRow from '@mui/material/TableRow'
@@ -49,7 +50,7 @@ const Invokers = () => {
          <CardHeader title='Info' />
          <CardContent>
          {!invokerEvents && <CircularProgress />}
            {invokerEvents && invokerEvents.length === 0 && <strong>Algo de la información del usuario al que pertenece. API para la que se ha creado el invoker. API para hacer X.</strong>}
            {invokerEvents && invokerEvents.length === 0 && <strong>Some of the information about the user that it belongs.API for which the invoker has been created. API to do something.</strong>}
            {invokerEvents && invokerEvents.length > 0 && (
              <TableContainer>
              <Table sx={{ minWidth: 650 }} aria-label='Card Actions'>
@@ -85,10 +86,11 @@ const Invokers = () => {
                <>
                  <TableHead>
                    <TableRow>
                      <TableCell>Nombre API</TableCell>
                      <TableCell>Método Autenticación</TableCell>
                      <TableCell>Fecha alta</TableCell>
                      <TableCell>Validez</TableCell>
                      <TableCell>API name</TableCell>
                      <TableCell>Athentication method</TableCell>
                      <TableCell>Started date</TableCell>
                      <TableCell>Validity</TableCell>
                      <TableCell>Delete</TableCell>
                    </TableRow>
                  </TableHead>
                  <TableBody>
@@ -105,6 +107,10 @@ const Invokers = () => {
                        </TableCell>
                        <TableCell>{invokerSecurityData[0].notification_destination}</TableCell>
                        <TableCell>{invokerSecurityData[0].notification_destination}</TableCell>
                        <TableCell>limit date</TableCell>
                        <TableCell>
                          <Button variant='contained'>Delete</Button>
                        </TableCell>
                      </TableRow>
                    ))}
                  </TableBody>
@@ -117,7 +123,7 @@ const Invokers = () => {
      
      <Grid item xs={12}>
        <Card>
          <CardHeader title='Events 2' />
          <CardHeader title='Events' />
          <TableContainer component={Paper}>
            <Table sx={{ minWidth: 650 }} aria-label='Invokers table'>
            {!invokerSecurityData && <CircularProgress />}
@@ -143,8 +149,8 @@ const Invokers = () => {
                      >
                        <TableCell component='th' scope='row'>
                        </TableCell>
                        <TableCell>{invokerSecurityData[0].notification_destination}</TableCell>
                        <TableCell>{invokerSecurityData[0].notification_destination}</TableCell>
                        <TableCell>For example</TableCell>
                        <TableCell>for example</TableCell>
                      </TableRow>
                    ))}
                  </TableBody>
@@ -154,36 +160,6 @@ const Invokers = () => {
          </TableContainer>
        </Card>
      </Grid>

      <Grid item xs={12}>
        <Card>
          <CardHeader title='Events' />
          <CardContent>
            {!invokerEvents && <CircularProgress />}
            {invokerEvents && invokerEvents.length === 0 && <strong>No info</strong>}
            {invokerEvents && invokerEvents.length > 0 && (
              <TableContainer>
                <Table sx={{ minWidth: 650 }} aria-label='Card Actions'>
                  <TableHead>
                    <TableRow>
                      <TableCell>Identificador</TableCell>
                      <TableCell>TimeStamp</TableCell>
                      <TableCell>Descripción</TableCell>
                    </TableRow>
                  </TableHead>
                  <TableBody>
                    <TableRow>
                      <TableCell>{invokerEvents[0].subscriber_id}</TableCell>
                      <TableCell>{invokerEvents[0].subscription_id}</TableCell>
                      <TableCell>{invokerEvents[0].notificationDestination}</TableCell>
                    </TableRow>
                  </TableBody>
                </Table>
              </TableContainer>
            )}
          </CardContent>
        </Card>
      </Grid>
    </Grid>
  )
}
Loading