Skip to content
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

[WIP] feat(cloud provider) Support sts token #46

Open
wants to merge 1 commit into
base: 2.8-ui-driver
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 69 additions & 21 deletions component/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ export default Ember.Component.extend(ClusterDriver, {

cloudCredentialDriverName: 'aliyun',
config: null,
isSTSToken: false,

init() {
// This does on the fly template compiling, if you mess with this :cry:
Expand All @@ -367,6 +368,8 @@ export default Ember.Component.extend(ClusterDriver, {
cluster_id: null,
cluster_name: null,
regionId: 'cn-beijing',
account_id: '',
role_name: '',
});
} else {
config = this.get('globalStore').createRecord({
Expand Down Expand Up @@ -394,6 +397,8 @@ export default Ember.Component.extend(ClusterDriver, {
masterCount: 3,
osType: 'Linux',
resourceGroupId: '',
account_id: '',
role_name: '',
});

set(this, 'nodePoolList', [{
Expand Down Expand Up @@ -587,11 +592,15 @@ export default Ember.Component.extend(ClusterDriver, {

config.aliyun_credential_secret = aliyun_credential_secret;

if (get(this, 'isSTSToken')) {
config.aliyun_credential_secret = ""
}

if ( !clusterName ) {
errors.push(intl.t('clusterNew.aliyunkcs.cluster.name.required'));
}

if ( !config.aliyun_credential_secret ) {
if ( !config.aliyun_credential_secret && !get(this, 'isSTSToken')) {
errors.push(intl.t('nodeDriver.cloudCredentialError'));
}

Expand Down Expand Up @@ -685,6 +694,13 @@ export default Ember.Component.extend(ClusterDriver, {
this.send('aliyunLogin');
}
},
switchTab(record) {
set(this, 'isSTSToken', record)
if (!record) {
set(this, 'config.account_id', "")
set(this, 'config.role_name', "")
}
}
},

languageDidChanged: observer('intl.locale', function() {
Expand Down Expand Up @@ -733,7 +749,11 @@ export default Ember.Component.extend(ClusterDriver, {
}
const intl = get(this, 'intl');
const resourceGroupId = get(this, 'config.resourceGroupId');
const externalParams = { regionId: get(this, 'config.regionId'), };
const externalParams = {
regionId: get(this, 'config.regionId'),
accountId: get(this, 'config.account_id'),
roleName: get(this, 'config.role_name'),
};

if (!!resourceGroupId && resourceGroupId !== '') {
externalParams.resourceGroupId = resourceGroupId;
Expand Down Expand Up @@ -776,6 +796,8 @@ export default Ember.Component.extend(ClusterDriver, {
const externalParams = {
regionId: get(this, 'config.regionId'),
vpcId: get(this, 'config.vpcId'),
accountId: get(this, 'config.account_id'),
roleName: get(this, 'config.role_name'),
};

if (!!resourceGroupId && resourceGroupId !== '') {
Expand Down Expand Up @@ -1120,7 +1142,11 @@ export default Ember.Component.extend(ClusterDriver, {
},

setInstances(type) {
const externalParams = { regionId: get(this, 'config.regionId'), };
const externalParams = {
regionId: get(this, 'config.regionId'),
accountId: get(this, 'config.account_id'),
roleName: get(this, 'config.role_name'),
};

if (type === 'master') {
set(externalParams, 'instanceChargeType', get(this, 'config.masterInstanceChargeType'));
Expand Down Expand Up @@ -1167,7 +1193,7 @@ export default Ember.Component.extend(ClusterDriver, {
.catch((err) => {
const errors = get(this, 'errors') || [];

errors.pushObject(err.message || get(err, 'body.detail') || err);
errors.pushObject(err.message || get(err, 'body.error') || err);
set(this, 'errors', errors);
reject();

Expand All @@ -1178,7 +1204,11 @@ export default Ember.Component.extend(ClusterDriver, {

setKeyPairs() {
const resourceGroupId = get(this, 'config.resourceGroupId');
const externalParams = { regionId: get(this, 'config.regionId'), };
const externalParams = {
regionId: get(this, 'config.regionId'),
accountId: get(this, 'config.account_id'),
roleName: get(this, 'config.role_name'),
};

if (!!resourceGroupId && resourceGroupId !== '') {
externalParams.resourceGroupId = resourceGroupId;
Expand All @@ -1194,16 +1224,14 @@ export default Ember.Component.extend(ClusterDriver, {
if ( !get(this, 'config.keyPair') && get(this, 'keyChoices.length') ) {
set(this, 'config.keyPair', get(this, 'keyChoices.firstObject.value'));
}
}).catch((err) => {
const errors = get(this, 'errors') || [];

errors.pushObject(err.message || get(err, 'body.detail') || err);
set(this, 'errors', errors);
});
})
},

async fetchResourceGroups() {
const groups = await this.fetch('ResourceGroup', 'ResourceGroups');
const groups = await this.fetch('ResourceGroup', 'ResourceGroups', {
accountId: get(this, 'config.account_id'),
roleName: get(this, 'config.role_name'),
});

set(this, 'resourceGroups', groups.map((group) => {
return {
Expand All @@ -1215,7 +1243,10 @@ export default Ember.Component.extend(ClusterDriver, {
},

async fetchRegions() {
const regions = await this.fetch('Region', 'Regions');
const regions = await this.fetch('Region', 'Regions', {
accountId: get(this, 'config.account_id'),
roleName: get(this, 'config.role_name'),
});
const transformRegions = [];

REGIONS.forEach((regionTemp) => {
Expand All @@ -1236,7 +1267,11 @@ export default Ember.Component.extend(ClusterDriver, {

async fetchCluster() {
const regionId = get(this, 'config.regionId');
const clusters = await this.fetch('', 'cluster', { regionId, });
const clusters = await this.fetch('', 'cluster', {
regionId,
accountId: get(this, 'config.account_id'),
roleName: get(this, 'config.role_name'),
});

set(this, 'clusterChoices', (get(clusters, 'clusters') || []).map((item, index) => {
if (index === 0){
Expand All @@ -1259,7 +1294,9 @@ export default Ember.Component.extend(ClusterDriver, {
regionId: get(this, 'config.regionId'),
instanceChargeType: get(this, 'config.masterInstanceChargeType'),
networkCategory: 'vpc',
destinationResource: 'InstanceType'
destinationResource: 'InstanceType',
accountId: get(this, 'config.account_id'),
roleName: get(this, 'config.role_name'),
}).then((res) => {
results = this.getAvailableResources(res);
resolve(results);
Expand Down Expand Up @@ -1287,7 +1324,9 @@ export default Ember.Component.extend(ClusterDriver, {
instanceChargeType: get(this, 'config.masterInstanceChargeType'),
networkCategory: 'vpc',
ioOptimized: 'optimized',
destinationResource: 'SystemDisk'
destinationResource: 'SystemDisk',
accountId: get(this, 'config.account_id'),
roleName: get(this, 'config.role_name'),
}).then((res) => {
results = this.getAvailableResources(res);

Expand Down Expand Up @@ -1339,7 +1378,9 @@ export default Ember.Component.extend(ClusterDriver, {
networkCategory: 'vpc',
systemDiskCategory: get(this, 'nodePoolList.firstObject.system_disk_category'),
ioOptimized: 'optimized',
destinationResource: 'DataDisk'
destinationResource: 'DataDisk',
accountId: get(this, 'config.account_id'),
roleName: get(this, 'config.role_name'),
}).then((res) => {
results = this.getAvailableResources(res) || [];
const dataDiskChoices = [];
Expand Down Expand Up @@ -1466,7 +1507,7 @@ export default Ember.Component.extend(ClusterDriver, {
acceptLanguage = 'en-US';
}

const cloudCredentialId = get(this, 'primaryResource.cloudCredentialId');
const cloudCredentialId = get(this, 'isSTSToken') ? '' : get(this, 'primaryResource.cloudCredentialId');
const results = [];
const location = window.location;
let req = {};
Expand All @@ -1486,7 +1527,7 @@ export default Ember.Component.extend(ClusterDriver, {
};

return new EmberPromise((resolve, reject) => {
if (!cloudCredentialId){
if (!cloudCredentialId && !query.accountId && !query.roleName){
// console.error(`${resourceName}: "cloudCredentialId" not found`)
return resolve(results);
}
Expand All @@ -1512,13 +1553,20 @@ export default Ember.Component.extend(ClusterDriver, {
resolve(results);
})
.catch((err) => {
reject(get(err, 'body.detail') || err);
reject(get(err, 'body.error') || err);
});
} else {
resolve(results);
}
}).catch((err) => {
reject(get(err, 'body.detail') || err);
const errors = get(this, 'errors') || [];

errors.pushObject(err.message || get(err, 'body.error') || get(err, 'body.message') || err);
const uniqueErrors = [...new Set(errors)];

// Set the errors with unique values
set(this, 'errors', uniqueErrors);
reject(get(err, 'body.error') || err);
});
});
},
Expand Down
75 changes: 65 additions & 10 deletions component/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,70 @@
expandOnInit=true
}}
{{#if (eq step 1)}}
{{form-auth-cloud-credential
cloudCredentials=cloudCredentials
driverName=cloudCredentialDriverName
parseAndCollectErrors=(action "errorHandler")
finishAndSelectCloudCredential=(action "finishAndSelectCloudCredential")
primaryResource=primaryResource
region=config.region
hideSave=true
}}
<div class="mb-20 has-tabs">
<ul class="tab-nav">
<li>
<a
class={{concat (unless isSTSToken "active" ) " ember-view hand"}}
{{action "switchTab" false}}
>
Credential
</a>
</li>
<li>
<a
class={{concat (if isSTSToken "active" ) " ember-view hand"}}
{{action "switchTab" true}}
>
STS Token
</a>
</li>
</ul>
</div>
{{#if isSTSToken}}
<div class="row" style="padding: 10px;">
<div class="col span-12">
<label class="acc-label">
Account ID{{field-required}}
</label>
{{#input-or-display
editable=(eq step 1)
value=config.account_id
}}
{{input
type="text"
class="form-control"
value=config.account_id
}}
{{/input-or-display}}
</div>
<div class="col span-12">
<label class="acc-label">
Role Name{{field-required}}
</label>
{{#input-or-display
editable=(eq step 1)
value=config.role_name
}}
{{input
type="text"
class="form-control"
value=config.role_name
}}
{{/input-or-display}}
</div>
</div>
{{else}}
{{form-auth-cloud-credential
cloudCredentials=cloudCredentials
driverName=cloudCredentialDriverName
parseAndCollectErrors=(action "errorHandler")
finishAndSelectCloudCredential=(action "finishAndSelectCloudCredential")
primaryResource=primaryResource
region=config.region
hideSave=true
}}
{{/if}}
{{else}}
<div class="row">
<div class="col span-4">
Expand Down Expand Up @@ -96,7 +151,7 @@
cancel=close
createLabel="clusterNew.aliyunkcs.access.next"
savingLabel="clusterNew.aliyunkcs.access.loading"
saveDisabled=(or (not primaryResource.cloudCredentialId) (not nodePoolActive) (and (not isNew) (not isActive) (not isK8sVersionError)))
saveDisabled=(or (and (not isSTSToken) (not primaryResource.cloudCredentialId)) (not nodePoolActive) (and (not isNew) (not isActive) (not isK8sVersionError)))
}}
{{/if}}
{{#if (gte step 2)}}
Expand Down