Skip to content

Commit

Permalink
Merge pull request #15 from NSLS2/update-github-actions
Browse files Browse the repository at this point in the history
Update GitHub actions
  • Loading branch information
danielballan authored Jan 29, 2024
2 parents 257b826 + 532c7d8 commit 2418499
Show file tree
Hide file tree
Showing 19 changed files with 269 additions and 91 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/test-production-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Integration Tests for Deployed API

on:
schedule:
- cron: '*/5 * * * *'
workflow_dispatch:
pull_request:
branches: [ "main" ]

jobs:
integration_tests:
runs-on: self-hosted

steps:
- name: Print hostname
run: echo "The hostname is $(hostname)"

- name: Checkout
uses: actions/checkout@v2

- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: '17'

- name: Download ijhttp.zip
run: curl -f -L -o ijhttp.zip "https://jb.gg/ijhttp/latest"

- name: Unzip ijhttp.zip
run: unzip -q ijhttp.zip

- name: Beamline endpoint tests
run: |
./ijhttp/ijhttp --env-file ./integration-tests/http-client.env.json \
--env production \
./integration-tests/check_all_beamlines.http
- name: Check API Service
run: |
./ijhttp/ijhttp --env-file ./integration-tests/http-client.env.json \
--env production \
./integration-tests/check_service_health.http
12 changes: 0 additions & 12 deletions .github/workflows/test_runner.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Project exclude paths
/venv/

# Hatch managed version file
src/nsls2api/_version.py

Expand Down
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// 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": [
{
"name": "Python: FastAPI",
"type": "python",
"request": "launch",
"module": "uvicorn",
"args": [
"nsls2api.main:app",
"--reload"
],
"jinja": true,
"justMyCode": true
}
]
}
36 changes: 36 additions & 0 deletions integration-tests/check_service_health.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
### Check About Details
# @name api-about-details
GET http://{{host}}/v1/about
Accept: application/json

> {%
client.test("Request executed successfully", function () {
client.assert(response.status === 200, "Response status is not 200");
});
%}

### Check API Stats
# @name api-stats
GET http://{{host}}/v1/stats
Accept: application/json

> {%
client.test("Request executed successfully", function () {
client.assert(response.status === 200, "Response status is not 200");
});

client.test("Response content-type is json", function() {
var type = response.contentType.mimeType;
client.assert(type === "application/json", "Expected 'application/json' but received '" + type + "'");
});

client.test("Returns sensible numbers", function() {
var data = response.body;
client.assert(data.hasOwnProperty("facility_count"), "Response body does not contain 'facility_count' property");
client.assert(data.facility_count === 3, "Expected 'facility_count' to be 3 but received '" + data.facility_count + "'");
client.assert(data.proposal_count > 0, "Expected 'proposal_count' to be greater than 0 but received '" + data.proposal_count + "'");
client.assert(data.commissioning_proposal_count > 0, "Expected 'commissioning_proposal_count' to be greater than 0 but received '" + data.proposal_count + "'");
client.assert(data.beamline_count > 0, "Expected 'beamline_count' to be greater than 0 but received '" + data.proposal_count + "'");
});

%}
6 changes: 0 additions & 6 deletions integration-tests/facility_api_test.http

This file was deleted.

23 changes: 13 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ description = ''
readme = "README.md"
requires-python = ">=3.9"
license = "BSD-3-Clause"
keywords = []
authors = [
{ name = "Stuart Campbell", email = "scampbell@bnl.gov" },
]
Expand All @@ -18,29 +17,33 @@ classifiers = [
"License :: OSI Approved :: BSD License",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
#dependencies = [
# "hatch",
# "hatch-requirements-txt",
# "hatch-vcs",
# "typer",
#]

[project.scripts]
nsls2api = "nsls2api.cli.cli:app"

[project.urls]
Source = "https://github.com/nsls2/nsls2api/"

[tool.hatch]
version.source = "vcs"
build.hooks.vcs.version-file = "src/nsls2api/_version.py"

[tool.hatch.metadata.hooks.requirements_txt]
files = ["requirements.txt"]

[tool.hatch.build]
packages = ["src/nsls2api"]
hooks.vcs.version-file = "src/nsls2api/_version.py"

[tool.hatch.build.targets.sdist]
exclude = [
"/.github",
]

#[tool.hatch.metadata.hooks.requirements_txt.optional-dependencies]
#dev = ["requirements-dev.txt"]

Expand Down
27 changes: 20 additions & 7 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.12
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile requirements-dev.in
Expand All @@ -14,6 +14,8 @@ anyio==3.7.1
# via asyncer
asttokens==2.4.1
# via stack-data
async-timeout==4.0.3
# via aiohttp
asyncer==0.0.2
# via -r requirements-dev.in
attrs==23.2.0
Expand Down Expand Up @@ -47,9 +49,14 @@ decorator==5.1.1
# via ipython
dnspython==2.4.2
# via pymongo
exceptiongroup==1.2.0
# via
# anyio
# ipython
# pytest
executing==2.0.1
# via stack-data
faker==22.0.0
faker==22.2.0
# via -r requirements-dev.in
flask==3.0.0
# via
Expand Down Expand Up @@ -79,7 +86,7 @@ idna==3.6
# yarl
iniconfig==2.0.0
# via pytest
ipython==8.19.0
ipython==8.20.0
# via -r requirements-dev.in
itsdangerous==2.1.2
# via flask
Expand Down Expand Up @@ -165,7 +172,7 @@ rich==13.7.0
# via textual
roundrobin==0.0.4
# via locust
ruff==0.1.11
ruff==0.1.13
# via -r requirements-dev.in
shellingham==1.4.0
# via typer-cli
Expand All @@ -178,12 +185,16 @@ sniffio==1.3.0
# via anyio
stack-data==0.6.3
# via ipython
textual==0.46.0
textual==0.47.1
# via textual-dev
textual-dev==1.3.0
textual-dev==1.4.0
# via -r requirements-dev.in
toml==0.10.2
# via bunnet
tomli==2.0.1
# via
# black
# pytest
traitlets==5.14.1
# via
# ipython
Expand All @@ -194,6 +205,8 @@ typer-cli==0.0.13
# via -r requirements-dev.in
typing-extensions==4.9.0
# via
# black
# bunnet
# pydantic
# pydantic-core
# textual
Expand All @@ -202,7 +215,7 @@ uc-micro-py==1.0.2
# via linkify-it-py
urllib3==2.1.0
# via requests
wcwidth==0.2.12
wcwidth==0.2.13
# via prompt-toolkit
werkzeug==3.0.1
# via
Expand Down
17 changes: 11 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.12
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile requirements.in
Expand Down Expand Up @@ -35,7 +35,9 @@ decorator==5.1.1
# via gssapi
dnspython==2.4.2
# via pymongo
fastapi==0.108.0
exceptiongroup==1.2.0
# via anyio
fastapi==0.109.0
# via -r requirements.in
gssapi==1.8.3
# via n2snusertools
Expand Down Expand Up @@ -129,28 +131,31 @@ sniffio==1.3.0
# via
# anyio
# httpx
starlette==0.32.0.post1
starlette==0.35.1
# via fastapi
textual==0.46.0
textual==0.47.1
# via -r requirements.in
toml==0.10.2
# via beanie
typer==0.9.0
# via -r requirements.in
typing-extensions==4.9.0
# via
# anyio
# beanie
# fastapi
# pydantic
# pydantic-core
# textual
# typer
# uvicorn
uc-micro-py==1.0.2
# via linkify-it-py
uuid==1.30
# via -r requirements.in
uvicorn==0.25.0
uvicorn==0.26.0
# via -r requirements.in
wcwidth==0.2.12
wcwidth==0.2.13
# via prettytable
werkzeug==3.0.1
# via -r requirements.in
28 changes: 28 additions & 0 deletions src/nsls2api/api/models/proposal_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,31 @@ class RecentProposalsModel(pydantic.BaseModel):
class ProposalSummary(pydantic.BaseModel):
proposal_id: str
title: str


class ProposalDirectories(pydantic.BaseModel):
path: str
owner: str
group: str
group_writable: bool
users: list[dict[str, str]]
groups: list[dict[str, str]]

model_config = {
"json_schema_extra": {
"examples": [{
"path": "/nsls2/xf11id1/2021-2/20210901",
"owner": "xf11id1",
"group": "xf11id1",
"group_writable": True,
"users": [
{"name": "xf11id1", "permissions": "rwx"},
{"name": "xf11id2", "permissions": "rwx"},
],
"groups": [
{"name": "xf11id1", "permissions": "rwx"},
{"name": "xf11id2", "permissions": "rwx"},
],
}]
}
}
2 changes: 1 addition & 1 deletion src/nsls2api/api/v1/admin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from nsls2api.models.apikeys import ApiUser

# router = fastapi.APIRouter()
router = fastapi.APIRouter(dependencies=[Depends(validate_admin_role)], include_in_schema=False)
router = fastapi.APIRouter(dependencies=[Depends(validate_admin_role)], include_in_schema=False, tags=["admin"])


@router.get("/admin/settings") # , include_in_schema=False)
Expand Down
Loading

0 comments on commit 2418499

Please sign in to comment.