[ERDE-2821] Update API Clients #111
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test | |
on: | |
workflow_dispatch: | |
pull_request: | |
# When all changes are Markdown files, this workflow will not run | |
paths-ignore: | |
- '**.md' | |
push: | |
branches: | |
- master | |
jobs: | |
test-pipeline: | |
name: Test Pipeline | |
runs-on: ${{ matrix.operating-system }} | |
strategy: | |
matrix: | |
operating-system: [ubuntu-latest, macos-latest] | |
version: [ '18.x', '19.x', '20.x' ] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup node ${{ matrix.version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.version }} | |
- name: Build and Install @sophos-factory/api-client | |
run: | | |
npm ci | |
npm run build | |
mkdir -p ../test | |
npm pack | |
cp sophos-factory-api-client-*.tgz ../test/api-client.tgz | |
cd ../test | |
npm init -f -y | |
npm install api-client.tgz | |
- name: Create Test Scripts | |
working-directory: ../test | |
run: | | |
cat << SCRIPT > ./testProjects.js | |
const { factoryApi } = require('@sophos-factory/api-client') | |
const accessToken = process.env.TOKEN; | |
const proj = '61ccbe03d42b9bdcc88365d8'; | |
const config = new factoryApi.Configuration({ | |
accessToken: accessToken, | |
basePath: 'https://api.dev.factory.sophos.com/v1' | |
}); | |
const client = new factoryApi.ProjectsApi(config); | |
(async () => { | |
const res = await client.getProject(proj); | |
if (res.data.name.includes('CRUD Testing')) console.info('Everything looks good!'); | |
})().catch(e => { | |
if (e.response && e.response.status) { | |
console.error(`Request failed with status code: ${e.response.status}`); | |
console.error('Response body:'); | |
console.error(e.response.data); | |
} else { | |
console.error(`Request failed with error: ${e}`); | |
} | |
}); | |
SCRIPT | |
cat << SCRIPT > ./testOrganizations.js | |
const { factoryAuthApi } = require('@sophos-factory/api-client') | |
const accessToken = process.env.TOKEN; | |
const config = new factoryAuthApi.Configuration({ | |
accessToken: accessToken, | |
basePath: 'https://api.dev.factory.sophos.com/v1' | |
}); | |
const client = new factoryAuthApi.OrganizationsApi(config); | |
(async () => { | |
const res = await client.getOrganizationsPublic(); | |
if (res.length > 0) console.info('Everything looks good!'); | |
})().catch(e => { | |
if (e.response && e.response.status) { | |
console.error(`Request failed with status code: ${e.response.status}`); | |
console.error('Response body:'); | |
console.error(e.response.data); | |
} else { | |
console.error(`Request failed with error: ${e}`); | |
} | |
}); | |
SCRIPT | |
- name: Run Smoke Test | |
working-directory: ../test | |
env: | |
TOKEN: ${{ secrets.FACTORY_API_TOKEN }} | |
run: | | |
node testProjects.js | |
node testOrganizations.js |