github.com/freiheit-com/kuberpult@v1.24.2-0.20240328135542-315d5630abe6/services/frontend-service/src/ui/utils/GrpcApi.tsx (about)

     1  /*This file is part of kuberpult.
     2  
     3  Kuberpult is free software: you can redistribute it and/or modify
     4  it under the terms of the Expat(MIT) License as published by
     5  the Free Software Foundation.
     6  
     7  Kuberpult is distributed in the hope that it will be useful,
     8  but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    10  MIT License for more details.
    11  
    12  You should have received a copy of the MIT License
    13  along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>.
    14  
    15  Copyright 2023 freiheit.com*/
    16  import * as api from '../../api/api';
    17  
    18  export interface Api {
    19      // overview service is used to get data about apps, envs and releases
    20      overviewService(): api.OverviewService;
    21      // batch service can make changes, e.g. adding/removing locks, deploying..
    22      batchService(): api.BatchService;
    23      // config service returns basics configuration like for azure auth
    24      configService(): api.FrontendConfigService;
    25      // rollout service
    26      rolloutService(): api.RolloutService;
    27      // tags service
    28      gitService(): api.GitService;
    29      // environment service
    30      environmentService(): api.EnvironmentService;
    31  }
    32  
    33  class GrpcApi implements Api {
    34      _overviewService: api.OverviewService;
    35      _batchService: api.BatchService;
    36      _configService: api.FrontendConfigService;
    37      _rolloutService: api.RolloutService;
    38      _gitService: api.GitService;
    39      _environmentService: api.EnvironmentService;
    40      constructor() {
    41          // eslint-disable-next-line no-restricted-globals
    42          const gcli = new api.GrpcWebImpl(location.protocol + '//' + location.host, {});
    43          this._overviewService = new api.OverviewServiceClientImpl(gcli);
    44          this._batchService = new api.BatchServiceClientImpl(gcli);
    45          this._configService = new api.FrontendConfigServiceClientImpl(gcli);
    46          this._rolloutService = new api.RolloutServiceClientImpl(gcli);
    47          this._gitService = new api.GitServiceClientImpl(gcli);
    48          this._environmentService = new api.EnvironmentServiceClientImpl(gcli);
    49      }
    50      overviewService(): api.OverviewService {
    51          return this._overviewService;
    52      }
    53      batchService(): api.BatchService {
    54          return this._batchService;
    55      }
    56      configService(): api.FrontendConfigService {
    57          return this._configService;
    58      }
    59      rolloutService(): api.RolloutService {
    60          return this._rolloutService;
    61      }
    62      gitService(): api.GitService {
    63          return this._gitService;
    64      }
    65      environmentService(): api.EnvironmentService {
    66          return this._environmentService;
    67      }
    68  }
    69  
    70  export const useApi = new GrpcApi();