Skip to content

Commit

Permalink
PR Feedback #1
Browse files Browse the repository at this point in the history
  • Loading branch information
grolu committed Nov 12, 2020
1 parent 1244108 commit 158c55a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 21 deletions.
14 changes: 6 additions & 8 deletions backend/lib/routes/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,21 @@ router.route('/:name')
next(err)
}
})
.delete(async (req, res, next) => {
.post(async (req, res, next) => {
try {
const user = req.user
const namespace = req.params.namespace
const name = req.params.name
res.send(await members.remove({ user, namespace, name }))
const { namespace, name } = req.params
res.send(await members.rotateSecret({ user, namespace, name }))
} catch (err) {
next(err)
}
})

router.route('/:name/secret')
.delete(async (req, res, next) => {
try {
const user = req.user
const { namespace, name } = req.params
res.send(await members.removeSecret({ user, namespace, name }))
const namespace = req.params.namespace
const name = req.params.name
res.send(await members.remove({ user, namespace, name }))
} catch (err) {
next(err)
}
Expand Down
6 changes: 2 additions & 4 deletions backend/lib/services/members/MemberManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'use strict'

const _ = require('lodash')
const { NotFound, Conflict, UnprocessableEntity, MethodNotAllowed } = require('http-errors')
const { NotFound, Conflict, UnprocessableEntity } = require('http-errors')
const { dumpKubeconfig } = require('@gardener-dashboard/kube-config')

const config = require('../../config')
Expand Down Expand Up @@ -108,8 +108,6 @@ class MemberManager {
}

await this.deleteServiceAccountSecret(item)

return this.subjectList.members
}

setItemRoles (item, roles) {
Expand Down Expand Up @@ -187,7 +185,7 @@ class MemberManager {
async deleteServiceAccountSecret (item) {
const { namespace } = Member.parseUsername(item.id)
if (namespace !== this.namespace) {
return
throw new UnprocessableEntity(`ServiceAccount namespace ${namespace} does not match project namespace this.namespace`)
}

const name = _
Expand Down
4 changes: 2 additions & 2 deletions backend/lib/services/members/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ exports.remove = async function ({ user, namespace, name }) {
return memberManager.delete(name)
}

exports.removeSecret = async function ({ user, namespace, name }) {
exports.rotateSecret = async function ({ user, namespace, name }) {
const memberManager = await MemberManager.create(user, namespace)
return memberManager.deleteSecret(name)
return memberManager.rotateServiceAccountSecret(name)
}
5 changes: 2 additions & 3 deletions frontend/src/store/modules/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// SPDX-License-Identifier: Apache-2.0
//

import { getMembers, addMember, updateMember, deleteMember, deleteServiceAccountSecret } from '@/utils/api'
import { getMembers, addMember, updateMember, deleteMember, rotateServiceAccountSecret } from '@/utils/api'

// initial state
const state = {
Expand Down Expand Up @@ -44,8 +44,7 @@ const actions = {
},
async rotateServiceAccountSecret ({ commit, rootState }, name) {
const namespace = rootState.namespace
const res = await deleteServiceAccountSecret({ namespace, name })
commit('RECEIVE', res.data)
await rotateServiceAccountSecret({ namespace, name })
}
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ export function deleteMember ({ namespace, name }) {
return deleteResource(`/api/namespaces/${namespace}/members/${name}`)
}

export function deleteServiceAccountSecret ({ namespace, name }) {
export function rotateServiceAccountSecret ({ namespace, name }) {
namespace = encodeURIComponent(namespace)
name = encodeURIComponent(name)
return deleteResource(`/api/namespaces/${namespace}/members/${name}/secret`)
return createResource(`/api/namespaces/${namespace}/members/${name}`)
}

/* User */
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/views/Members.vue
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,7 @@ export default {
'addMember',
'deleteMember',
'rotateServiceAccountSecret',
'setError',
'set'
'setError'
]),
openUserAddDialog () {
this.userAddDialog = true
Expand Down

0 comments on commit 158c55a

Please sign in to comment.