-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cc 7145 hcp link status api #20330
Cc 7145 hcp link status api #20330
Changes from 5 commits
a0de3be
98bee0a
50b93a2
6baa6fc
2fbc210
c7083b2
967f00f
2b34642
7042752
664db73
c4a15ff
aac0270
471dbb2
5903715
098329a
b6f3fce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
Comment on lines
+25
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was going to ask why we have the array methods here, but the API response does have I hope not - feels like something we should handle in the backend There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea, it is how the backend responds as of now. I've just decided to check that condition is linked, just in case we will have some other stuff added in future. But I totally agree, that as of now we don't assume to have something else to be returned from the endpoint |
||
), | ||
}, | ||
headers, | ||
}; | ||
}); | ||
} catch (e) { | ||
// set linked to false if the global link is not found | ||
if (e.statusCode === 404) { | ||
result = Promise.resolve({ isLinked: false }); | ||
Comment on lines
+33
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love the comment! |
||
} else { | ||
result = Promise.resolve(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if we get an error (auth related or anything really), {{#if hcpLlink.isLinked}}
Say cluster is linked
{{else}}
<DisplayBanner />
{{/if}} Thinking aloud, is that what we'd want to do?
So I think this is fine/great! However we hook this up to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea, the idea was to add some state, where we could see that So I open to discuss it |
||
} | ||
} | ||
return result; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,18 +43,18 @@ | |
|
||
{{#if (not-eq route.currentName 'oauth-provider-debug')}} | ||
|
||
{{! redirect if we aren't on a URL with dc information }} | ||
{{! redirect if we aren't on a URL with dc information }} | ||
{{#if (eq route.currentName 'index')}} | ||
{{! until we get to the dc route we don't know any permissions }} | ||
{{! as we don't know the dc, any inital permission based }} | ||
{{! redirects are in the dc.show route}} | ||
{{! until we get to the dc route we don't know any permissions }} | ||
{{! as we don't know the dc, any inital permission based }} | ||
{{! redirects are in the dc.show route}} | ||
|
||
{{! 2022-04-15: Temporarily reverting the services page to the default }} | ||
{{! 2022-04-15: Temporarily reverting the services page to the default }} | ||
{{did-insert | ||
(route-action 'replaceWith' 'dc.services.index' (hash dc=(env 'CONSUL_DATACENTER_LOCAL'))) | ||
}} | ||
{{else}} | ||
{{! If we are notfound, guess the params we need }} | ||
{{! If we are notfound, guess the params we need }} | ||
{{#if (eq route.currentName 'notfound')}} | ||
<DataSource | ||
@src={{uri '/*/*/*/notfound/${path}' (hash path=route.params.notfound)}} | ||
|
@@ -70,11 +70,11 @@ | |
'' | ||
) | ||
(if (can 'use nspaces') (or route.params.nspace notfound.nspace token.Namespace '') '') | ||
as |partition nspace| | ||
as |partition nspace| | ||
}} | ||
|
||
{{! Make sure we have enough to show the app chrome}} | ||
{{! Don't show anything until we have a list of DCs }} | ||
{{! Make sure we have enough to show the app chrome}} | ||
{{! Don't show anything until we have a list of DCs }} | ||
<DataSource @src={{uri '/*/*/*/datacenters'}} as |dcs|> | ||
{{! Once we have a list of DCs make sure the DC we are asking for exists }} | ||
{{! If not use the DC that the UI is running in }} | ||
|
@@ -85,20 +85,21 @@ | |
(hash Name=(env 'CONSUL_DATACENTER_LOCAL')) | ||
) | ||
dcs.data | ||
as |dc dcs| | ||
as |dc dcs| | ||
}} | ||
{{#if (and (gt dc.Name.length 0) dcs)}} | ||
|
||
{{! figure out our current DC and convert it to a model }} | ||
{{! figure out our current DC and convert it to a model }} | ||
<DataSource | ||
@src={{uri | ||
'/${partition}/*/${dc}/datacenter-cache/${name}' | ||
(hash dc=dc.Name partition=partition name=dc.Name) | ||
}} | ||
'/${partition}/*/${dc}/datacenter-cache/${name}' | ||
(hash dc=dc.Name partition=partition name=dc.Name) | ||
}} | ||
as |dc| | ||
> | ||
{{#if dc.data}} | ||
<HashicorpConsul | ||
<DataSource @src={{uri '/${partition}/*/${dc}/hcp-link' (hash dc=dc.Name partition=partition name=dc.Name) }} @open={{true}} as |hcpLink|> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bit curious about this - Does this mean we'll fetch this upon application load? And this data will be accessible as the Would we still need/want this if we're only requesting this inside of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good question. when application loading, we calling the service. but we have to call it on login as well It is questionable though, when we need to reload it. let's say if we are linking in HCP, and does not reload page in core, I think we still should get the information if it is linked actually it depends on the cost of calling the service, which in our case seems to be not too bad, because it uses local consul... what do you think? |
||
<HashicorpConsul | ||
id='wrapper' | ||
@dcs={{dcs}} | ||
@dc={{dc.data}} | ||
|
@@ -110,10 +111,10 @@ | |
> | ||
|
||
{{#if error}} | ||
{{! If we got an error from anything, show an error page }} | ||
{{! If we got an error from anything, show an error page }} | ||
<AppError @error={{error}} @login={{consul.login.open}} /> | ||
{{else}} | ||
{{! Otherwise show the rest of the app}} | ||
{{! Otherwise show the rest of the app}} | ||
<Outlet | ||
@name='application' | ||
@model={{hash app=consul user=(hash token=token) dc=dc.data dcs=dcs}} | ||
|
@@ -127,6 +128,7 @@ | |
{{/if}} | ||
|
||
</HashicorpConsul> | ||
</DataSource> | ||
{{/if}} | ||
</DataSource> | ||
{{/if}} | ||
|
@@ -135,7 +137,7 @@ | |
{{/let}} | ||
{{/if}} | ||
{{else}} | ||
{{! Routes with no main navigation }} | ||
{{! Routes with no main navigation }} | ||
<Outlet @name='application' @model={{hash user=(hash token=token)}} as |o|> | ||
{{outlet}} | ||
</Outlet> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_TRUE", | ||
"type": "linked" | ||
} | ||
], | ||
"observedGeneration":"01HMA2VPHVKNF6QR8TD07KDN5K", | ||
"updatedAt":"2024-01-16T21:29:25.923140Z" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just "magic" ™️ to make the repo service happy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes 😅