Skip to content

Commit

Permalink
Merge branch 'gabrielsroka:master' into feat-toggle-all-attributes-ex…
Browse files Browse the repository at this point in the history
…port-all
  • Loading branch information
pro4tlzz authored Mar 20, 2024
2 parents 3da64d9 + 177b92f commit ae9438c
Show file tree
Hide file tree
Showing 53 changed files with 6,667 additions and 568 deletions.
6 changes: 2 additions & 4 deletions CloneAppRules.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ <h1>Clone App Rules (new)</h1>
const lines = file.split(lineSeparator);
if (lines[lines.length - 1] == '') lines.pop();
const fields = lines.shift().split(fieldSeparator);
const headers = {};
fields.forEach((val, i) => headers[val] = i); /* Map header name to number. */
const headers = Object.fromEntries(fields.map((val, i) => [val, i])); /* Map header name to number. */

const apps = lines.map(line => {
const fields = line.replace(/"/g, '').split(fieldSeparator); /* TODO: improve support for "s */
Expand Down Expand Up @@ -163,8 +162,7 @@ <h1>Clone App Rules (new)</h1>
const lines = file.split(lineSeparator);
if (lines[lines.length - 1] == '') lines.pop();
const fields = lines.shift().split(fieldSeparator);
const headers = {};
fields.forEach((val, i) => headers[val] = i); /* Map header name to number. */
const headers = Object.fromEntries(fields.map((val, i) => [val, i])); /* Map header name to number. */

form.find('div.cloned').html('');
form.find('div.error').html('');
Expand Down
2 changes: 1 addition & 1 deletion FetchYield.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
return nextUrl.pathname + nextUrl.search;
}
}
function sleep(time) {
async function sleep(time) {
return new Promise(resolve => setTimeout(resolve, time));
}
})();
3 changes: 1 addition & 2 deletions ImportGroupsFromCSV.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ Group 1,The first group

const lines = file.split(lineSeparator);
const fields = lines.shift().split(fieldSeparator);
const headers = {};
fields.forEach((val, i) => headers[val] = i); /* Map header name to number. */
const headers = Object.fromEntries(fields.map((val, i) => [val, i])); /* Map header name to number. */

lines.forEach(line => {
if (line == '') return;
Expand Down
22 changes: 13 additions & 9 deletions SearchGroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Setup:
Or, copy this code to the browser console, or, if using Chrome, to a Snippet:
1. Press F12 (Windows) to open DevTools.
2. Go to Sources > Snippets, click New Snippet.
3. Give it a name, eg, "SearchGroups.js".
4. Copy/paste the code from https://gabrielsroka.github.io/SearchGroups.js
3. Give it a name, eg, "SearchGroups".
4. Copy/paste this code.
5. Save (Ctrl+S, Windows).
Usage:
Expand All @@ -23,13 +23,9 @@ Usage:
(async function () {
const popup = createPopup('Search Group Names using a regex');
const form = $('<form>Name <input class=name style="width: 250px"> <button type=submit>Search</button></form><br><div class=results>Loading...</div>').appendTo(popup);
let groups = [];
let url = '/api/v1/groups';
while (url) {
const r = await fetch(url);
const moreGroups = await r.json();
groups = groups.concat(moreGroups);
url = r.headers.get('link')?.match('<https://[^/]+(/[^>]+)>; rel="next"')?.[1];
const groups = [];
for await (const group of getObjects('/api/v1/groups')) {
groups.push(group);
}
form.find('input.name').focus();
form.submit(event => {
Expand All @@ -42,6 +38,14 @@ Usage:
popup.find('div.results').html(found || 'Not found');
}).submit();

async function* getObjects(url) {
while (url) {
const r = await fetch(url);
const objects = await r.json();
for (const o of objects) yield o;
url = r.headers.get('link')?.match('<https://[^/]+(/[^>]+)>; rel="next"')?.[1];
}
}
function createPopup(title) {
const popup = $(`<div style='position: absolute; z-index: 1000; top: 0px; max-height: calc(100% - 28px); max-width: calc(100% - 28px); padding: 8px; margin: 4px; ` +
`overflow: auto; background-color: white; border: 1px solid #ddd;'>` +
Expand Down
12 changes: 6 additions & 6 deletions SearchUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Setup:
Or, copy/paste this code to the browser console, or, if using Chrome, to a Snippet:
1. Press F12 (Windows) to open DevTools.
2. Go to Sources > Snippets, click New Snippet.
3. Give it a name, eg, "SearchUsers.js".
3. Give it a name, eg, "SearchUsers".
4. Copy/paste this code.
5. Save (Ctrl+S, Windows).
Expand Down Expand Up @@ -50,8 +50,8 @@ Usage:
users = [];
oldSearchStatus = searchStatus.value;
popup.find('div.results').html('Loading...');
for await (const page of getPages('/api/v1/users' + (searchStatus.value ? `?search=status eq "${searchStatus.value}"` : ''))) {
users = users.concat(page);
for await (const user of getObjects('/api/v1/users' + (searchStatus.value ? `?search=status eq "${searchStatus.value}"` : ''))) {
users.push(user);
popup.find('div.results').html('Loading... ' + users.length + ' users.');
}
}
Expand All @@ -69,11 +69,11 @@ Usage:
(found.length ? `<table class=data-list-table><tr><th>Name<th>Username<th>Email<th>Status<th>${attr.value}` + found.join('') + '</table>' : ''));
});

async function* getPages(url) {
async function* getObjects(url) {
while (url) {
const r = await fetch(url);
const page = await r.json();
yield page;
const objects = await r.json();
for (const o of objects) yield o;
url = r.headers.get('link')?.match('<https://[^/]+(/[^>]+)>; rel="next"')?.[1];
}
}
Expand Down
5 changes: 1 addition & 4 deletions UpdateUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ id,login,email

const lines = file.split(lineSeparator);
const fields = lines.shift().split(fieldSeparator);
const headers = {};
for (let i = 0; i < fields.length; i++) {
headers[fields[i]] = i; /* Map header name to number. */
}
const headers = Object.fromEntries(fields.map((val, i) => [val, i])); /* Map header name to number. */

lines.forEach(line => {
if (line == '') return;
Expand Down
12 changes: 8 additions & 4 deletions addSwaApp.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
javascript:
/*
name: /Add SWA App#
url: https://github.com/gabrielsroka/gabrielsroka.github.io/blob/master/addSwaApp.js
Add a Custom SWA app and assign it to me.
Setup:
Drag this to the bookmark toolbar:
javascript:(function(){document.body.appendChild(document.createElement("script")).src="https://gabrielsroka.github.io/addSwaApp.js";})();
Usage:
1. Login to Okta Admin.
Expand All @@ -12,7 +15,8 @@ Usage:

(function () {
var popup = createPopup("Add SWA App");
var form = $("<form><table><tr><td>Label<td><input class=label style='width: 300px'>" +
var form = $("<form><table>" +
"<tr><td>Label<td><input class=label style='width: 300px'>" +
"<tr><td>Login URL<td><input class=loginUrl value='https://LOGIN.oktapreview.com' style='width: 300px'></table>" +
"<button type=submit>Add</button></form>").appendTo(popup);
form.submit(async (event) => {
Expand All @@ -35,7 +39,7 @@ Usage:
}
};
popup.html("Adding app...");
// https://developer.okta.com/docs/reference/api/apps/#add-custom-swa-application
/* https://developer.okta.com/docs/reference/api/apps/#add-custom-swa-application */
app = await postJson({
url: "/api/v1/apps",
data: app
Expand All @@ -45,7 +49,7 @@ Usage:
scope: "USER"
};
popup.html("Assigning user to app...");
// https://developer.okta.com/docs/reference/api/apps/#assign-user-to-application-for-sso
/* https://developer.okta.com/docs/reference/api/apps/#assign-user-to-application-for-sso */
await postJson({
url: "/api/v1/apps/" + app.id + "/users",
data: appUser
Expand Down
Loading

0 comments on commit ae9438c

Please sign in to comment.