web/satellite: get gateway credentials request using url from config
WHAT: POST request to get gateway credentials using access grant. Put request url to config and use it for request. WHY: to show gateway credentials on UI Change-Id: I15ef43ecdeed69b0961d5796aacb47f36d560b1b
This commit is contained in:
parent
d3d6e0c67c
commit
bb7677a85f
@ -80,6 +80,7 @@ type Config struct {
|
||||
GoogleTagManagerID string `help:"id for google tag manager" default:""`
|
||||
GeneralRequestURL string `help:"url link to general request page" default:"https://support.tardigrade.io/hc/en-us/requests/new?ticket_form_id=360000379291"`
|
||||
ProjectLimitsIncreaseRequestURL string `help:"url link to project limit increase request page" default:"https://support.tardigrade.io/hc/en-us/requests/new?ticket_form_id=360000683212"`
|
||||
GatewayCredentialsRequestURL string `help:"url link for gateway credentials requests" default:""`
|
||||
|
||||
RateLimit web.IPRateLimiterConfig
|
||||
|
||||
@ -288,6 +289,7 @@ func (server *Server) appHandler(w http.ResponseWriter, r *http.Request) {
|
||||
DefaultProjectLimit int
|
||||
GeneralRequestURL string
|
||||
ProjectLimitsIncreaseRequestURL string
|
||||
GatewayCredentialsRequestURL string
|
||||
}
|
||||
|
||||
data.SatelliteName = server.config.SatelliteName
|
||||
@ -299,6 +301,7 @@ func (server *Server) appHandler(w http.ResponseWriter, r *http.Request) {
|
||||
data.DefaultProjectLimit = server.config.DefaultProjectLimit
|
||||
data.GeneralRequestURL = server.config.GeneralRequestURL
|
||||
data.ProjectLimitsIncreaseRequestURL = server.config.ProjectLimitsIncreaseRequestURL
|
||||
data.GatewayCredentialsRequestURL = server.config.GatewayCredentialsRequestURL
|
||||
|
||||
if server.templates.index == nil {
|
||||
server.log.Error("index template is not set")
|
||||
|
3
scripts/testdata/satellite-config.yaml.lock
vendored
3
scripts/testdata/satellite-config.yaml.lock
vendored
@ -88,6 +88,9 @@ compensation.withheld-percents: 75,75,75,50,50,50,25,25,25,0,0,0,0,0,0
|
||||
# allow domains to embed the satellite in a frame, space separated
|
||||
# console.frame-ancestors: tardigrade.io
|
||||
|
||||
# url link for gateway credentials requests
|
||||
# console.gateway-credentials-request-url: ""
|
||||
|
||||
# url link to general request page
|
||||
# console.general-request-url: https://support.tardigrade.io/hc/en-us/requests/new?ticket_form_id=360000379291
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
<meta name="default-project-limit" content="{{ .DefaultProjectLimit }}">
|
||||
<meta name="general-request-url" content="{{ .GeneralRequestURL }}">
|
||||
<meta name="project-limits-increase-request-url" content="{{ .ProjectLimitsIncreaseRequestURL }}">
|
||||
<meta name="gateway-credentials-request-url" content="{{ .GatewayCredentialsRequestURL }}">
|
||||
<title>{{ .SatelliteName }}</title>
|
||||
<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAL8SURBVHgBxVcxTFNRFL01JvylrRsmNWETWWSybg5I3NTQBCdRFyfrDuoKMgMyOQgdTcDAJmrUrWWCgQIbhJKy0TJQpsc73P/S9/tfP+8/GnqSn1fo77/3nnPufe8nhAR1ETeoy7hJjpj93/ycu0+UuUVuEA5Y2xaifirEVpX/nvknnBFbgpMGUfmIKOkRLRT578oxXy6IJcFCialH0EyaaPoZBy7tEQ3NEY1IKd4/iidHwqYLijLA559cuY6dT0RjBU5AAYm9fiivLFnBKMGBTyeqQ4BXhXDwdqjUiKZkskOzREsbzeeBNRMCEiDgr12uYl1WNbnW/oc2iUys8jrQyyxhHRkM3hdgAMFBHQyGG/GDqyDlsSeS/npQC99jlEBpOnyX2XCF8sGhZLbeMLMZkCDbJ1nYYTfDeMP9fMH5y5vmIKYE8RxUjBXPedDH1Zu6I9QFSzLQxErz4Xn5oNwg+2NSmuv3Lkvz4QlTi8rupDlBmA6tqQLrnYNCvoxSNAOtUEaakwzMv+ALidTP2OlKKiSK75Cs6hy9NYFkjzmG1SBCIuUq0Za8pgydge8R9E+e10qNrGE1ikH5435mo11bQgr4B9LEgVUC0Npm1o+vcuvBxB1NYFsaaeC2XUuW/Xs7msC9Xqa+MMa9jQr1KtXAQoKYHakeskbIhDrVasdTbbVY4s8ZYld/9PWuyeTSHksFBjBFcZ+aH/j/yZk5gcAcgImgIX6MNsKKhKBta1sB2A3HV5pD6iJQIzw/MICwoohc1F6ALBH03XemFYPl+VdzcBNUh6j5gZZEcP341opAAnX/AXl/A0FlrrshgMRR+YUvPPN8CHgAxlqWVYuEdH7V/ZilA6cosFDa53EcmUDKC+7X+IwxHEVhO0DK6aeXH88uHcWQA8xE7Yg69M6xgdWZUEFtNNDyx1s2KnyDIxu22zdZTjgWhANm/vL6clGIsnw3+Fbk94RreS8AMGrBxvwoT0lMPnSNC2JJoAPdgnMBJLjKq5lzAp1C19+OzwFiYzAU5f7eeQAAAABJRU5ErkJggg==" type="image/x-icon">
|
||||
<link rel="dns-prefetch" href="https://js.stripe.com">
|
||||
|
@ -2,13 +2,23 @@
|
||||
// See LICENSE for copying information.
|
||||
|
||||
import { BaseGql } from '@/api/baseGql';
|
||||
import { AccessGrant, AccessGrantCursor, AccessGrantsApi, AccessGrantsPage } from '@/types/accessGrants';
|
||||
import {
|
||||
AccessGrant,
|
||||
AccessGrantCursor,
|
||||
AccessGrantsApi,
|
||||
AccessGrantsPage,
|
||||
GatewayCredentials,
|
||||
} from '@/types/accessGrants';
|
||||
import { HttpClient } from '@/utils/httpClient';
|
||||
import { MetaUtils } from '@/utils/meta';
|
||||
|
||||
/**
|
||||
* AccessGrantsApiGql is a graphql implementation of Access Grants API.
|
||||
* Exposes all access grants-related functionality
|
||||
*/
|
||||
export class AccessGrantsApiGql extends BaseGql implements AccessGrantsApi {
|
||||
private readonly client: HttpClient = new HttpClient();
|
||||
|
||||
/**
|
||||
* Fetch access grants.
|
||||
*
|
||||
@ -118,6 +128,37 @@ export class AccessGrantsApiGql extends BaseGql implements AccessGrantsApi {
|
||||
return response.data.deleteAPIKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get gateway credentials using access grant.
|
||||
*
|
||||
* @param accessGrant - generated access grant
|
||||
* @throws Error
|
||||
*/
|
||||
public async getGatewayCredentials(accessGrant: string): Promise<GatewayCredentials> {
|
||||
const requestURL: string = MetaUtils.getMetaContent('gateway-credentials-request-url');
|
||||
if (!requestURL) throw new Error('Cannot get gateway credentials: request URL is not provided');
|
||||
|
||||
const path = `${requestURL}/v1/access`;
|
||||
const body = {
|
||||
access_grant: accessGrant,
|
||||
public: false,
|
||||
};
|
||||
const response = await this.client.post(path, JSON.stringify(body));
|
||||
if (!response.ok) {
|
||||
throw new Error('Cannot get gateway credentials');
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
return new GatewayCredentials(
|
||||
result.id,
|
||||
new Date(result.created_at),
|
||||
result.access_key_id,
|
||||
result.secret_key,
|
||||
result.endpoint,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for mapping access grants page from json to AccessGrantsPage type.
|
||||
*
|
||||
|
@ -9,6 +9,7 @@ import {
|
||||
AccessGrantsOrderBy,
|
||||
AccessGrantsPage,
|
||||
DurationPermission,
|
||||
GatewayCredentials,
|
||||
} from '@/types/accessGrants';
|
||||
import { SortDirection } from '@/types/common';
|
||||
|
||||
@ -17,6 +18,7 @@ export const ACCESS_GRANTS_ACTIONS = {
|
||||
CREATE: 'createAccessGrant',
|
||||
DELETE: 'deleteAccessGrants',
|
||||
CLEAR: 'clearAccessGrants',
|
||||
GET_GATEWAY_CREDENTIALS: 'getGatewayCredentials',
|
||||
SET_SEARCH_QUERY: 'setAccessGrantsSearchQuery',
|
||||
SET_SORT_BY: 'setAccessGrantsSortingBy',
|
||||
SET_SORT_DIRECTION: 'setAccessGrantsSortingDirection',
|
||||
@ -28,6 +30,7 @@ export const ACCESS_GRANTS_ACTIONS = {
|
||||
|
||||
export const ACCESS_GRANTS_MUTATIONS = {
|
||||
SET_PAGE: 'setAccessGrants',
|
||||
SET_GATEWAY_CREDENTIALS: 'setGatewayCredentials',
|
||||
TOGGLE_SELECTION: 'toggleAccessGrantsSelection',
|
||||
TOGGLE_BUCKET_SELECTION: 'toggleBucketSelection',
|
||||
CLEAR_SELECTION: 'clearAccessGrantsSelection',
|
||||
@ -50,6 +53,7 @@ const {
|
||||
SET_SEARCH_QUERY,
|
||||
SET_PAGE_NUMBER,
|
||||
SET_DURATION_PERMISSION,
|
||||
SET_GATEWAY_CREDENTIALS,
|
||||
} = ACCESS_GRANTS_MUTATIONS;
|
||||
|
||||
export class AccessGrantsState {
|
||||
@ -59,6 +63,7 @@ export class AccessGrantsState {
|
||||
public selectedBucketNames: string[] = [];
|
||||
public permissionNotBefore: Date = new Date();
|
||||
public permissionNotAfter: Date = new Date('2200-01-01');
|
||||
public gatewayCredentials: GatewayCredentials = new GatewayCredentials();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,6 +85,9 @@ export function makeAccessGrantsModule(api: AccessGrantsApi): StoreModule<Access
|
||||
return accessGrant;
|
||||
});
|
||||
},
|
||||
[SET_GATEWAY_CREDENTIALS](state: AccessGrantsState, credentials: GatewayCredentials) {
|
||||
state.gatewayCredentials = credentials;
|
||||
},
|
||||
[SET_PAGE_NUMBER](state: AccessGrantsState, pageNumber: number) {
|
||||
state.cursor.page = pageNumber;
|
||||
},
|
||||
@ -166,6 +174,11 @@ export function makeAccessGrantsModule(api: AccessGrantsApi): StoreModule<Access
|
||||
|
||||
commit(CLEAR_SELECTION);
|
||||
},
|
||||
getGatewayCredentials: async function({state, commit}: any, accessGrant: string): Promise<void> {
|
||||
const credentials: GatewayCredentials = await api.getGatewayCredentials(accessGrant);
|
||||
|
||||
commit(SET_GATEWAY_CREDENTIALS, credentials);
|
||||
},
|
||||
setAccessGrantsSearchQuery: function ({commit}, search: string) {
|
||||
commit(SET_SEARCH_QUERY, search);
|
||||
},
|
||||
|
@ -32,6 +32,14 @@ export interface AccessGrantsApi {
|
||||
* @throws Error
|
||||
*/
|
||||
delete(ids: string[]): Promise<void>;
|
||||
|
||||
/**
|
||||
* Get gateway credentials using access grant
|
||||
*
|
||||
* @returns GatewayCredentials
|
||||
* @throws Error
|
||||
*/
|
||||
getGatewayCredentials(accessGrant: string): Promise<GatewayCredentials>;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,3 +111,16 @@ export class DurationPermission {
|
||||
public notAfter: Date = new Date(),
|
||||
) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* GatewayCredentials class holds info for gateway credentials generated from access grant.
|
||||
*/
|
||||
export class GatewayCredentials {
|
||||
constructor(
|
||||
public id: string = '',
|
||||
public createdAt: Date = new Date(),
|
||||
public accessKeyId: string = '',
|
||||
public secretKey: string = '',
|
||||
public endpoint: string = '',
|
||||
) {}
|
||||
}
|
||||
|
@ -1,7 +1,13 @@
|
||||
// Copyright (C) 2020 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
import { AccessGrant, AccessGrantCursor, AccessGrantsApi, AccessGrantsPage } from '@/types/accessGrants';
|
||||
import {
|
||||
AccessGrant,
|
||||
AccessGrantCursor,
|
||||
AccessGrantsApi,
|
||||
AccessGrantsPage,
|
||||
GatewayCredentials,
|
||||
} from '@/types/accessGrants';
|
||||
|
||||
/**
|
||||
* Mock for AccessGrantsApi
|
||||
@ -25,4 +31,8 @@ export class AccessGrantsMock implements AccessGrantsApi {
|
||||
delete(ids: string[]): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
getGatewayCredentials(accessGrant: string): Promise<GatewayCredentials> {
|
||||
return Promise.resolve(new GatewayCredentials('testCredId', new Date(), 'testAccessKeyId', 'testSecret', 'testEndpoint'));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user