Skip to content

Commit

Permalink
Fix azure multi-environment support
Browse files Browse the repository at this point in the history
  • Loading branch information
huacheng authored and huacheng committed Jul 13, 2022
1 parent a9a53a7 commit 338475a
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Component from '@ember/component';
import layout from './template';
import { inject as service } from '@ember/service';
import { environments } from 'ui/utils/azure-choices';

export default Component.extend({
router: service(),

layout,
environments,

tag: null,
config: null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
<div class="row">
<div class="col span-6">
<label class="acc-label">
{{t "nodeDriver.azure.environment.label"}}
</label>
{{new-select
classNames="form-control"
content=environments
optionLabelPath="value"
value=config.environment
}}
</div>
<div class="col span-6">
<label class="acc-label" for="azure-subscription-id">
{{t "modalAddCloudKey.azure.subscriptionId.label"}}
<FieldRequired />
</label>
<Input
@classNames="form-control"
@id="azure-subscription-id"
@type="text"
@value={{mut config.subscriptionId}}
/>
</div>


</div>
<div class="row">
<div class="col span-6">
<label class="acc-label" for="azure-client-id">
Expand All @@ -24,17 +51,4 @@
/>
</div>
</div>
<div class="row">
<div class="col span-6">
<label class="acc-label" for="azure-subscription-id">
{{t "modalAddCloudKey.azure.subscriptionId.label"}}
<FieldRequired />
</label>
<Input
@classNames="form-control"
@id="azure-subscription-id"
@type="text"
@value={{mut config.subscriptionId}}
/>
</div>
</div>

Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export default Component.extend(ViewNewEdit, {
}

const { cloudCredentialType } = this;
const keysThatWeCanValidate = ['amazon', 'digitalOcean', 'linode', 'oci', 'google'];
const keysThatWeCanValidate = ['amazon', 'digitalOcean', 'linode', 'oci', 'google', 'azure'];
const auth = {
type: 'validate',
token: null,
Expand Down Expand Up @@ -372,6 +372,26 @@ export default Component.extend(ViewNewEdit, {
return this.setError(`${ err.message }`);
});
}

if (cloudCredentialType === 'azure') {
return get(this, 'globalStore').rawRequest({
url: '/meta/aksCheckCredentials',
method: 'POST',
data: {
environment: get(this, 'config.environment'),
clientId: get(this, 'config.clientId'),
clientSecret: get(this, 'config.clientSecret'),
subscriptionId: get(this, 'config.subscriptionId'),
},
redirectUnauthorized: false,
}).then(() => {
set(this, 'validatingKeys', false);

return true;
}).catch((err) => {
return this.setError(`${ err.message }`);
});
}
}

set(this, 'validatingKeys', false);
Expand Down
14 changes: 14 additions & 0 deletions lib/nodes/addon/components/driver-azure/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ export default Component.extend(NodeDriver, {
set(this, 'config.managedDisks', get(this, 'managedDisks') === MANAGED);
}),

cloudCredentialChoiceObserver: observer('model.cloudCredentialId', function() {
const cloudCredentialId = get(this, 'model.cloudCredentialId');

if (!cloudCredentialId){
return;
}

get(this, 'store').find('cloudCredential', cloudCredentialId, { forceReload: true }).then((credential) => {
const environment = get(credential, 'azurecredentialConfig.environment');

environment && set(this, 'config.environment', environment);
});
}),

evironmentChoiceObserver: observer('config.environment', function() {
let environment = get(this, 'config.environment');

Expand Down
1 change: 1 addition & 0 deletions lib/nodes/addon/components/driver-azure/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
content=environments
optionLabelPath="value"
value=config.environment
disabled=true
}}
</div>
<div class="col span-6">
Expand Down
8 changes: 8 additions & 0 deletions lib/shared/addon/utils/azure-choices.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ export let regions = {
{
'name': 'chinaeast2',
'displayName': 'China East 2',
},
{
'name': 'chinanorth3',
'displayName': 'China North 3',
}
].sortBy('name'),
'AzureUSGovernmentCloud': [
Expand Down Expand Up @@ -501,6 +505,10 @@ export let aksRegions = [
'name': 'chinaeast2',
'displayName': 'China East 2',
},
{
'name': 'chinanorth3',
'displayName': 'China North 3',
},
{
'name': 'eastasia',
'displayName': 'East Asia',
Expand Down

0 comments on commit 338475a

Please sign in to comment.