Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add update workbook owner recipe #29

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/sigma-api-recipes/workbooks/update-owner.js"
}
]
}
2 changes: 2 additions & 0 deletions sigma-api-recipes/.env
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ baseURL=https://aws-api.sigmacomputing.com/v2
MEMBERID=
NEW_MEMBER_TYPE=

# yRn1UFV8ngVWBM1Hgrl51h7MS8uow me

EMAIL=

NEW_MEMBER_FIRST_NAME=
Expand Down
43 changes: 43 additions & 0 deletions sigma-api-recipes/workbooks/update-owner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// This script updates the ownership of a specified inode in Sigma using the "Update an inode" endpoint.

// Load environment variables from a specific .env file for configuration
require('dotenv').config({ path: 'sigma-api-recipes/.env' });

// Import the function to obtain a bearer token from the authenticate-bearer module
const getBearerToken = require('../get-access-token');

// Import Axios for making HTTP requests
const axios = require('axios');

// Load use-case specific variables from environment variables
const baseURL = process.env.baseURL; // Base URL for the Sigma API
const memberid = process.env.MEMBERID; // New member ID to assign to the inode as owner
const workbookId = process.env.WORKBOOK_ID; // Workbook ID to be used as the urlId for the inode

// Function to update the ownerId of a specified inode using the workbookId
async function updateInodeOwner(workbookId) {
const token = await getBearerToken();
if (!token) {
console.error('Failed to obtain Bearer token.');
return;
}

try {
const response = await axios.patch(
`${baseURL}/files/${workbookId}`,
{ ownerId: memberid }, // Use `ownerId` with `memberid` value from .env
{
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
}
);
console.log('Inode updated successfully:', response.data);
} catch (error) {
console.error('Error updating inode:', error.response ? error.response.data : error);
}
}

// Execute the update function
updateInodeOwner(workbookId);