Skip to content
Open
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
22 changes: 22 additions & 0 deletions check_env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Script to check environment variables
console.log('Checking environment variables for Clarifai keys...');

// List all environment variables that might contain Clarifai keys
const possibleKeys = [
'CLARIFAI_API_KEY',
'clarifai_api',
'new_clarifai_key'
];

possibleKeys.forEach(key => {
if (process.env[key]) {
console.log(`Found key ${key}:`);
console.log(`Value: ${process.env[key]}`);
console.log(`Length: ${process.env[key].length}`);
console.log('First 8 chars:', process.env[key].substring(0, 8));
console.log('---');
} else {
console.log(`No value found for ${key}`);
console.log('---');
}
});
37 changes: 37 additions & 0 deletions check_pat_scopes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const { ClarifaiStub, grpc } = require('clarifai-nodejs-grpc');
const dotenv = require('dotenv');
dotenv.config();

const stub = ClarifaiStub.grpc();
const metadata = new grpc.Metadata();
const pat = (process.env.CLARIFAI_PAT || '').trim();
metadata.set('authorization', `Key ${pat}`);

async function checkPATScopes() {
return new Promise((resolve, reject) => {
stub.MyScopes(
{},
metadata,
(err, response) => {
if (err) {
console.error('Error checking PAT scopes:', err);
reject(err);
} else {
console.log('PAT Scopes:', JSON.stringify(response, null, 2));
resolve(response);
}
}
);
});
}

async function main() {
try {
await checkPATScopes();
} catch (error) {
console.error('Error in main:', error);
process.exit(1);
}
}

main();
109 changes: 109 additions & 0 deletions check_pat_scopes_v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const { ClarifaiStub, grpc } = require('clarifai-nodejs-grpc');
const dotenv = require('dotenv');
dotenv.config();

const stub = ClarifaiStub.grpc();
const metadata = new grpc.Metadata();
const pat = (process.env.CLARIFAI_PAT || '').trim();
metadata.set('authorization', `Key ${pat}`);

// First get user context from ListApps
async function getUserContext() {
return new Promise((resolve, reject) => {
stub.ListApps(
{
page: 1,
per_page: 1
},
metadata,
(err, response) => {
if (err) {
console.error('Error listing apps:', err);
reject(err);
} else {
if (response.apps && response.apps.length > 0) {
const app = response.apps[0];
const userAppId = {
user_id: app.user_id,
app_id: app.id
};
console.log('User context retrieved:', userAppId);
resolve(userAppId);
} else {
reject(new Error('No apps found'));
}
}
}
);
});
}

async function checkPATScopes(userAppId) {
return new Promise((resolve, reject) => {
stub.MyScopes(
{
user_app_id: userAppId
},
metadata,
(err, response) => {
if (err) {
console.error('Error checking PAT scopes:', err);
reject(err);
} else {
console.log('PAT Scopes:', JSON.stringify(response, null, 2));
resolve(response);
}
}
);
});
}

// Function to check specific endpoint access
async function checkEndpointAccess(userAppId) {
const criticalEndpoints = [
'/clarifai.api.V2/PostModels',
'/clarifai.api.V2/PostModelVersions',
'/clarifai.api.V2/PostInputs'
];

console.log('\nChecking access to critical endpoints:');
for (const endpoint of criticalEndpoints) {
try {
const response = await new Promise((resolve, reject) => {
stub.ListScopes(
{
user_app_id: userAppId,
endpoints: [endpoint]
},
metadata,
(err, response) => {
if (err) {
reject(err);
} else {
resolve(response);
}
}
);
});
console.log(`\nEndpoint ${endpoint}:`);
console.log('Access:', JSON.stringify(response, null, 2));
} catch (error) {
console.error(`Error checking access for ${endpoint}:`, error.message);
}
}
}

async function main() {
try {
const userAppId = await getUserContext();
console.log('\nChecking PAT scopes with user context...');
await checkPATScopes(userAppId);
console.log('\nChecking specific endpoint access...');
await checkEndpointAccess(userAppId);
} catch (error) {
console.error('Error in main:', error);
process.exit(1);
}
}

main();
3 changes: 3 additions & 0 deletions controllers/health.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.check = (req, res) => {
res.json({ status: 'ok' });
};
30 changes: 30 additions & 0 deletions controllers/test-images.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const express = require('express');
const router = express.Router();
const fs = require('fs');
const path = require('path');

// Endpoint to list available test images
router.get('/list', (req, res) => {
try {
const catsDir = path.join(__dirname, '..', 'static', 'test_images', 'cats');
const dogsDir = path.join(__dirname, '..', 'static', 'test_images', 'dogs');

const catImages = fs.readdirSync(catsDir)
.filter(file => file.endsWith('.jpg'))
.map(file => `/static/test_images/cats/${file}`);

const dogImages = fs.readdirSync(dogsDir)
.filter(file => file.endsWith('.jpg'))
.map(file => `/static/test_images/dogs/${file}`);

res.json({
cats: catImages,
dogs: dogImages
});
} catch (error) {
console.error('Error listing test images:', error);
res.status(500).json({ error: 'Failed to list test images' });
}
});

module.exports = router;
Loading