mirror of https://github.com/hashicorp/consul
Browse Source
* feat: add api call to hcp/link endpoint * updated * updated * update approach to get the linking status * updated application template * feat: add api call to hcp/link endpoint * updated * updated * update approach to get the linking status * updated application template * update purple banner links * Hook up the linked check to the purple banner * fixed lint issue * Updated tests for new link status API calls as args instead of from service --------- Co-authored-by: Chris Hut <tophernuts@gmail.com>pull/20361/head
Valeriia Ruban
10 months ago
committed by
GitHub
8 changed files with 119 additions and 30 deletions
@ -0,0 +1,42 @@
|
||||
/** |
||||
* Copyright (c) HashiCorp, Inc. |
||||
* SPDX-License-Identifier: BUSL-1.1 |
||||
*/ |
||||
|
||||
import RepositoryService from 'consul-ui/services/repository'; |
||||
import dataSource from 'consul-ui/decorators/data-source'; |
||||
|
||||
export default class HcpLinkService extends RepositoryService { |
||||
@dataSource('/:partition/:ns/:dc/hcp-link') |
||||
async fetch({ partition, ns, dc }, { uri }, request) { |
||||
let result; |
||||
try { |
||||
result = ( |
||||
await request` |
||||
GET /api/hcp/v2/link/global |
||||
` |
||||
)((headers, body) => { |
||||
return { |
||||
meta: { |
||||
version: 2, |
||||
uri: uri, |
||||
}, |
||||
body: { |
||||
isLinked: (body.status['consul.io/hcp/link']['conditions'] || []).some( |
||||
(condition) => condition.type === 'linked' && condition.state === 'STATE_TRUE' |
||||
), |
||||
}, |
||||
headers, |
||||
}; |
||||
}); |
||||
} catch (e) { |
||||
// set linked to false if the global link is not found
|
||||
if (e.statusCode === 404) { |
||||
result = Promise.resolve({ isLinked: false }); |
||||
} else { |
||||
result = Promise.resolve(null); |
||||
} |
||||
} |
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,16 @@
|
||||
{ |
||||
"status": { |
||||
"consul.io/hcp/link": { |
||||
"conditions": [ |
||||
{ |
||||
"message": "Successfully linked to cluster 'organization/f53e5646-6529-4698-ae29-d74f8bd22a01/project/6994bb7a-5561-4d5c-8bb0-cf40177e5b77/hashicorp.consul.global-network-manager.cluster/mkam-vm'", |
||||
"reason": "SUCCESS", |
||||
"state": "STATE_FALSE", |
||||
"type": "linked" |
||||
} |
||||
], |
||||
"observedGeneration":"01HMA2VPHVKNF6QR8TD07KDN5K", |
||||
"updatedAt":"2024-01-16T21:29:25.923140Z" |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue