Skip to content

Commit

Permalink
Tested components (PipedreamHQ#12074)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcortes authored May 27, 2024
1 parent 783c30c commit 27c50a5
Show file tree
Hide file tree
Showing 11 changed files with 604 additions and 8 deletions.
84 changes: 84 additions & 0 deletions components/keycloak/actions/create-user/create-user.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* eslint-disable no-unused-vars */
import app from "../../keycloak.app.mjs";

export default {
key: "keycloak-create-user",
name: "Create User",
description: "Create a new user in Keycloak. The username must be unique. [See the documentation](https://www.keycloak.org/docs-api/latest/rest-api/index.html#_users)",
version: "0.0.1",
type: "action",
props: {
app,
realm: {
propDefinition: [
app,
"realm",
],
},
username: {
type: "string",
label: "Username",
description: "The username of the user.",
},
firstName: {
propDefinition: [
app,
"firstName",
],
},
lastName: {
propDefinition: [
app,
"lastName",
],
},
email: {
propDefinition: [
app,
"email",
],
},
emailVerified: {
propDefinition: [
app,
"emailVerified",
],
},
enabled: {
propDefinition: [
app,
"enabled",
],
},
},
methods: {
createUser({
realm, ...args
} = {}) {
return this.app.post({
path: `/admin/realms/${realm}/users`,
...args,
});
},
},
async run({ $ }) {
const {
app,
createUser,
realm,
...data
} = this;

await createUser({
$,
realm,
data,
});

$.export("$summary", "Successfully created user.");

return {
success: true,
};
},
};
56 changes: 56 additions & 0 deletions components/keycloak/actions/delete-user/delete-user.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import app from "../../keycloak.app.mjs";

export default {
key: "keycloak-delete-user",
name: "Delete User",
description: "Delete a user from Keycloak. [See the documentation](https://www.keycloak.org/docs-api/latest/rest-api/index.html#_users)",
version: "0.0.1",
type: "action",
props: {
app,
realm: {
propDefinition: [
app,
"realm",
],
},
userId: {
propDefinition: [
app,
"userId",
({ realm }) => ({
realm,
}),
],
},
},
methods: {
deleteUser({
realm, userId, ...args
} = {}) {
return this.app.delete({
path: `/admin/realms/${realm}/users/${userId}`,
...args,
});
},
},
async run({ $ }) {
const {
deleteUser,
realm,
userId,
} = this;

await deleteUser({
$,
realm,
userId,
});

$.export("$summary", "Successfully deleted user.");

return {
success: true,
};
},
};
52 changes: 52 additions & 0 deletions components/keycloak/actions/get-user/get-user.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import app from "../../keycloak.app.mjs";

export default {
key: "keycloak-get-user",
name: "Get User",
description: "Retrieve the representation of the user. [See the documentation](https://www.keycloak.org/docs-api/latest/rest-api/index.html#_users)",
version: "0.0.1",
type: "action",
props: {
app,
realm: {
propDefinition: [
app,
"realm",
],
},
userId: {
propDefinition: [
app,
"userId",
({ realm }) => ({
realm,
}),
],
},
},
methods: {
getUser({
realm, userId, ...args
} = {}) {
return this.app._makeRequest({
path: `/admin/realms/${realm}/users/${userId}`,
...args,
});
},
},
async run({ $ }) {
const {
getUser,
realm,
userId,
} = this;

const response = await getUser({
$,
realm,
userId,
});
$.export("$summary", `Successfully retrieved user with ID \`${response.id}\`.`);
return response;
},
};
90 changes: 90 additions & 0 deletions components/keycloak/actions/update-user/update-user.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* eslint-disable no-unused-vars */
import app from "../../keycloak.app.mjs";

export default {
key: "keycloak-update-user",
name: "Update User",
description: "Updates a user in Keycloak. [See the documentation](https://www.keycloak.org/docs-api/latest/rest-api/index.html#_users)",
version: "0.0.1",
type: "action",
props: {
app,
realm: {
propDefinition: [
app,
"realm",
],
},
userId: {
propDefinition: [
app,
"userId",
({ realm }) => ({
realm,
}),
],
},
firstName: {
propDefinition: [
app,
"firstName",
],
},
lastName: {
propDefinition: [
app,
"lastName",
],
},
email: {
propDefinition: [
app,
"email",
],
},
emailVerified: {
propDefinition: [
app,
"emailVerified",
],
},
enabled: {
propDefinition: [
app,
"enabled",
],
},
},
methods: {
updateUser({
realm, userId, ...args
} = {}) {
return this.app.put({
path: `/admin/realms/${realm}/users/${userId}`,
...args,
});
},
},
async run({ $ }) {
const {
app,
updateUser,
realm,
userId,
...data
} = this;

await updateUser({
$,
realm,
userId,
data,
});

$.export("$summary", "Successfully updated user.");

return {
success: true,
};
},
};
9 changes: 9 additions & 0 deletions components/keycloak/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const DEFAULT_LIMIT = 100;
const DEFAULT_MAX = 600;
const LAST_DATE_FROM = "dateFrom";

export default {
DEFAULT_LIMIT,
DEFAULT_MAX,
LAST_DATE_FROM,
};
11 changes: 11 additions & 0 deletions components/keycloak/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
async function iterate(iterations) {
const items = [];
for await (const item of iterations) {
items.push(item);
}
return items;
}

export default {
iterate,
};
Loading

0 comments on commit 27c50a5

Please sign in to comment.