Skip to content

Commit

Permalink
feat: retrieve and set cluster access data
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaDellaValle committed Jul 7, 2023
1 parent 1bd2890 commit d7f02d3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
22 changes: 13 additions & 9 deletions web-client/src/views/CreateUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,30 @@ const mockedItems: SummaryItem[] = [
},
];

const clusterAccessOptions = [
type clusterAccessOption = {
id: ClusterAccess,
label: string,
backendvalue: string,
};

const clusterAccessOptions: clusterAccessOption[] = [
{
id: 'none',
label: 'none',
backendvalue: 'none',
},
{
id: 'read',
label: 'read-only',
backendvalue: 'read',
},
{
id: 'write',
label: 'read-write',
backendvalue: 'admin',
},
];

const clusterRoleMap = {
none: false,
read: 'read-only',
write: 'admin'
};

interface UserCreationParams {
generated_for_user: string,
roleName: string,
Expand Down Expand Up @@ -206,9 +209,9 @@ const CreateUser = () => {

// Call to define Cluster Resources Access
clusterAccess !== 'none' && createClusterRoleBindings.mutate({
roleName: `template-cluster-resources___${clusterRoleMap[clusterAccess]}`,
roleName: `template-cluster-resources___${clusterAccessOptions.find((c: clusterAccessOption) => c.id === clusterAccess).backendvalue}`,
subjects: [{kind: 'ServiceAccount', name: username, namespace: 'permission-manager'}],
clusterRolebindingName: `${username}___template-cluster-resources___${clusterRoleMap[clusterAccess]}`,
clusterRolebindingName: `${username}___template-cluster-resources___${clusterAccessOptions.find((c: clusterAccessOption) => c.id === clusterAccess).backendvalue}`,
})
]).then(res => {
console.log('calls done', res);
Expand Down Expand Up @@ -260,6 +263,7 @@ const CreateUser = () => {
options={clusterAccessOptions}
idSelected={clusterAccess}
onChange={(e) => {
console.log('ACCESS', e)
setClusterAccess(e as any)
}}
/>
Expand Down
38 changes: 23 additions & 15 deletions web-client/src/views/EditUserNew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ type SummaryItem = {
namespaces: string[],
};

type clusterAccessOption = {
id: ClusterAccess,
label: string,
backendvalue: string,
};

const mockedItems: SummaryItem[] = [
{
resource: '*',
Expand All @@ -65,26 +71,29 @@ const mockedItems: SummaryItem[] = [
},
];

const clusterAccessOptions = [
const clusterAccessOptions: clusterAccessOption[] = [
{
id: 'none',
label: 'none',
backendvalue: 'none',
},
{
id: 'read',
label: 'read-only',
backendvalue: 'read',
},
{
id: 'write',
label: 'read-write',
backendvalue: 'admin',
},
];

const clusterRoleMap = {
none: false,
read: 'read-only',
write: 'admin'
};
// const clusterAccessMap = {
// none: {value: false, displayValue: 'none'},
// read: {value: 'read', displayValue: 'read-only'},
// write: {value: 'admin', displayValue: 'read-write'},
// };

interface UserCreationParams {
generated_for_user: string,
Expand Down Expand Up @@ -126,8 +135,9 @@ const EditUser = () => {
console.log(useRbac())


const { extractedPairItems, crbs } = extractUsersRoles(roleBindings, clusterRoleBindings, username);

useEffect(() => {
let { extractedPairItems, crbs } = extractUsersRoles(roleBindings, clusterRoleBindings, username);

const reFormatTemplates = extractedPairItems.map((template, index) => {
// Format templates
Expand All @@ -146,13 +156,10 @@ const EditUser = () => {
const clusterAccess = crbs.find(crb => crb.metadata.name.includes('template-cluster-resources___'))
const formattedClusterAccess = clusterAccess && clusterAccess.roleRef.name.replace('template-cluster-resources___', '')

const entries = Object.entries(clusterAccessOptions);

console.log('ENTRUE', entries)

// const access = entries.find(c => c.value === formattedClusterAccess)
const selectedAccess = clusterAccessOptions.find((c: clusterAccessOption) => c.backendvalue === formattedClusterAccess);
console.log('ENTRUE', formattedClusterAccess, selectedAccess)

setClusterAccess(formattedClusterAccess as ClusterAccess);
selectedAccess && setClusterAccess(selectedAccess.id);
setTemplates(reFormatTemplates as any);
}, [roleBindings, clusterRoleBindings, username]);

Expand Down Expand Up @@ -220,9 +227,9 @@ const EditUser = () => {

// Call to define Cluster Resources Access
clusterAccess !== 'none' && createClusterRoleBindings.mutate({
roleName: `template-cluster-resources___${clusterRoleMap[clusterAccess]}`,
roleName: `template-cluster-resources___${clusterAccessOptions.find((c: clusterAccessOption) => c.id === clusterAccess).backendvalue}`,
subjects: [{kind: 'ServiceAccount', name: username, namespace: 'permission-manager'}],
clusterRolebindingName: `${username}___template-cluster-resources___${clusterRoleMap[clusterAccess]}`,
clusterRolebindingName: `${username}___template-cluster-resources___${clusterAccessOptions.find((c: clusterAccessOption) => c.id === clusterAccess).backendvalue}`,
})
]).then(res => {
console.log('calls done', res);
Expand Down Expand Up @@ -273,6 +280,7 @@ const EditUser = () => {
options={clusterAccessOptions}
idSelected={clusterAccess}
onChange={(e) => {
console.log('event', e)
setClusterAccess(e as any)
}}
/>
Expand Down

0 comments on commit d7f02d3

Please sign in to comment.