Skip to content

Commit 310f0e5

Browse files
committed
[Components] pingone - WIP
1 parent 2e9c364 commit 310f0e5

File tree

9 files changed

+879
-16
lines changed

9 files changed

+879
-16
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import app from "../../pingone.app.mjs";
2+
3+
export default {
4+
key: "pingone-create-user",
5+
name: "Create User",
6+
description: "Creates a new user in PingOne. [See the documentation](https://apidocs.pingidentity.com/pingone/platform/v1/api/#post-create-user).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
username: {
12+
propDefinition: [
13+
app,
14+
"username",
15+
],
16+
},
17+
email: {
18+
propDefinition: [
19+
app,
20+
"email",
21+
],
22+
},
23+
givenName: {
24+
propDefinition: [
25+
app,
26+
"givenName",
27+
],
28+
},
29+
familyName: {
30+
propDefinition: [
31+
app,
32+
"familyName",
33+
],
34+
},
35+
department: {
36+
propDefinition: [
37+
app,
38+
"department",
39+
],
40+
},
41+
locales: {
42+
propDefinition: [
43+
app,
44+
"locales",
45+
],
46+
},
47+
},
48+
methods: {
49+
createUser(args = {}) {
50+
return this.app.post({
51+
path: "/users",
52+
...args,
53+
});
54+
},
55+
},
56+
async run({ $ }) {
57+
const {
58+
createUser,
59+
username,
60+
email,
61+
givenName,
62+
familyName,
63+
department,
64+
locales,
65+
} = this;
66+
67+
const response = await createUser({
68+
$,
69+
data: {
70+
username,
71+
email,
72+
name: {
73+
given: givenName,
74+
family: familyName,
75+
},
76+
department,
77+
locales,
78+
},
79+
});
80+
81+
$.export("$summary", "Successfully created user.");
82+
return response;
83+
},
84+
};
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import app from "../../pingone.app.mjs";
2+
3+
export default {
4+
key: "pingone-update-user",
5+
name: "Update User in PingOne",
6+
description: "Update an existing user's attributes in PingOne. [See the documentation](https://apidocs.pingidentity.com/pingone/platform/v1/api/#patch-update-user).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
userId: {
12+
propDefinition: [
13+
app,
14+
"userId",
15+
],
16+
},
17+
username: {
18+
optional: false,
19+
propDefinition: [
20+
app,
21+
"username",
22+
],
23+
},
24+
email: {
25+
propDefinition: [
26+
app,
27+
"email",
28+
],
29+
},
30+
givenName: {
31+
propDefinition: [
32+
app,
33+
"givenName",
34+
],
35+
},
36+
familyName: {
37+
propDefinition: [
38+
app,
39+
"familyName",
40+
],
41+
},
42+
department: {
43+
propDefinition: [
44+
app,
45+
"department",
46+
],
47+
},
48+
locales: {
49+
propDefinition: [
50+
app,
51+
"locales",
52+
],
53+
},
54+
},
55+
methods: {
56+
updateUser({
57+
userId, ...args
58+
} = {}) {
59+
return this.app.patch({
60+
path: `/users/${userId}`,
61+
...args,
62+
});
63+
},
64+
},
65+
async run({ $ }) {
66+
const {
67+
updateUser,
68+
userId,
69+
username,
70+
email,
71+
givenName,
72+
familyName,
73+
department,
74+
locales,
75+
} = this;
76+
77+
const response = await updateUser({
78+
$,
79+
userId,
80+
data: {
81+
username,
82+
email,
83+
givenName,
84+
familyName,
85+
department,
86+
locales,
87+
},
88+
});
89+
90+
$.export("$summary", "Successfully updated user.");
91+
return response;
92+
},
93+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const BASE_URL = "https://api.pingone.com";
2+
const VERSION_PATH = "/v1";
3+
const ENV_PATH = "/environments";
4+
const SUBSCRIPTION_ID = "subscriptionId";
5+
6+
export default {
7+
BASE_URL,
8+
VERSION_PATH,
9+
ENV_PATH,
10+
SUBSCRIPTION_ID,
11+
};

components/pingone/pingone.app.mjs

Lines changed: 184 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,191 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "pingone",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
username: {
9+
type: "string",
10+
label: "Username",
11+
description: "The user's username. This must either be a well-formed email address or another unique identifier.",
12+
},
13+
email: {
14+
type: "string",
15+
label: "Email",
16+
description: "The user's email address.",
17+
optional: true,
18+
},
19+
givenName: {
20+
type: "string",
21+
label: "First Name",
22+
description: "The user's first name.",
23+
optional: true,
24+
},
25+
familyName: {
26+
type: "string",
27+
label: "Last Name",
28+
description: "The user's last name.",
29+
optional: true,
30+
},
31+
department: {
32+
type: "string",
33+
label: "Department",
34+
description: "The user's department. E.g., `Engineering`.",
35+
optional: true,
36+
},
37+
locales: {
38+
type: "string[]",
39+
label: "Locales",
40+
description: "The user's locales. E.g., `London`.",
41+
optional: true,
42+
async options({ prevContext: { url } }) {
43+
if (url === null) {
44+
return [];
45+
}
46+
const {
47+
_embedded: { languages },
48+
_links: { next },
49+
} = await this.listLanguages({
50+
url,
51+
});
52+
return {
53+
options: languages.map(({ name }) => name),
54+
context: {
55+
url: next?.href || null,
56+
},
57+
};
58+
},
59+
},
60+
userId: {
61+
type: "string",
62+
label: "User ID",
63+
description: "The unique identifier for the user.",
64+
async options({ prevContext: { url } }) {
65+
if (url === null) {
66+
return [];
67+
}
68+
const {
69+
_embedded: { users },
70+
_links: { next },
71+
} = await this.listUsers({
72+
url,
73+
});
74+
return {
75+
options: users.map(({
76+
id: value, username: label,
77+
}) => ({
78+
label,
79+
value,
80+
})),
81+
context: {
82+
url: next?.href || null,
83+
},
84+
};
85+
},
86+
},
87+
applicationId: {
88+
type: "string",
89+
label: "Application ID",
90+
description: "The unique identifier for the application.",
91+
async options({ prevContext: { url } }) {
92+
if (url === null) {
93+
return [];
94+
}
95+
const {
96+
_embedded: { applications },
97+
_links: { next },
98+
} = await this.listApplications({
99+
url,
100+
});
101+
return {
102+
options: applications.map(({
103+
id: value, name: label,
104+
}) => ({
105+
label,
106+
value,
107+
})),
108+
context: {
109+
url: next?.href || null,
110+
},
111+
};
112+
},
113+
},
114+
userAttributes: {
115+
type: "object",
116+
label: "User Attributes",
117+
description: "The attributes to update the user with.",
118+
optional: true,
119+
},
120+
groupId: {
121+
type: "string",
122+
label: "Group ID",
123+
description: "The unique identifier for the group.",
124+
optional: true,
125+
},
126+
status: {
127+
type: "string",
128+
label: "User Status",
129+
description: "The current status of the user, e.g., active, inactive.",
130+
optional: true,
131+
},
132+
},
5133
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
134+
getUrl(path) {
135+
return `${constants.BASE_URL}${constants.VERSION_PATH}${constants.ENV_PATH}/${this.$auth.environment_id}${path}`;
136+
},
137+
getHeaders(headers) {
138+
return {
139+
"Content-Type": "application/json",
140+
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
141+
...headers,
142+
};
143+
},
144+
_makeRequest({
145+
$ = this, url, path, headers, ...args
146+
} = {}) {
147+
return axios($, {
148+
...args,
149+
debug: true,
150+
url: url || this.getUrl(path),
151+
headers: this.getHeaders(headers),
152+
});
153+
},
154+
post(args = {}) {
155+
return this._makeRequest({
156+
method: "POST",
157+
...args,
158+
});
159+
},
160+
patch(args = {}) {
161+
return this._makeRequest({
162+
method: "PATCH",
163+
...args,
164+
});
165+
},
166+
delete(args = {}) {
167+
return this._makeRequest({
168+
method: "DELETE",
169+
...args,
170+
});
171+
},
172+
listUsers(args = {}) {
173+
return this._makeRequest({
174+
path: "/users",
175+
...args,
176+
});
177+
},
178+
listApplications(args = {}) {
179+
return this._makeRequest({
180+
path: "/applications",
181+
...args,
182+
});
183+
},
184+
listLanguages(args = {}) {
185+
return this._makeRequest({
186+
path: "/languages",
187+
...args,
188+
});
9189
},
10190
},
11191
};

0 commit comments

Comments
 (0)