Skip to content

Commit

Permalink
Expose port in docker files. Added test run configuration post method…
Browse files Browse the repository at this point in the history
…. tmttestrun expose other basil db information as env variable. moved js method to constants file. Updated ltp example to leverage env variables provided by basil. Update documentation.

Signed-off-by: Luigi Pellecchia <[email protected]>
  • Loading branch information
Luigi Pellecchia committed Sep 9, 2024
1 parent f036fd7 commit 4b43193
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 44 deletions.
3 changes: 3 additions & 0 deletions Dockerfile-api
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ RUN mkdir -p /var/tmp && cd /BASIL-API/db/models && \
# Apply patches
RUN patch -u /usr/local/lib/python3.12/site-packages/tmt/steps/provision/podman.py < /BASIL-API/misc/tmt_provision_podman.patch

# Remove BASIL ADMIN PASSWORD from the environment
ENV BASIL_ADMIN_PASSWORD=

Check warning on line 29 in Dockerfile-api

View workflow job for this annotation

GitHub Actions / build

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "BASIL_ADMIN_PASSWORD") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

EXPOSE ${BASIL_API_PORT}
CMD echo "BASIL_API_PORT: ${BASIL_API_PORT}" && cd api && \

Check warning on line 32 in Dockerfile-api

View workflow job for this annotation

GitHub Actions / build

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/
gunicorn --access-logfile /var/tmp/tc-gunicorn-access.log \
--error-logfile /var/tmp/tc-gunicorn-error.log \
Expand Down
1 change: 1 addition & 0 deletions Dockerfile-app
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ RUN npm run build
# RUN sed -i "s/src=\"\//src=\"/g" dist/index.html
# RUN sed -i "s/href=\"\//href=\"/g" dist/index.html

EXPOSE ${APP_PORT}
CMD ["npm", "run", "start"]
60 changes: 60 additions & 0 deletions api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5654,6 +5654,66 @@ def get(self):
configs = [x.as_dict(full_data=True) for x in configs]
return configs

def post(self):
request_data = request.get_json(force=True)
mandatory_fields = ['context_vars', 'environment_vars',
'git_repo_ref',
'provision_guest', 'provision_guest_port', 'provision_type',
'ssh_key', 'title']
if not check_fields_in_request(mandatory_fields, request_data):
return BAD_REQUEST_MESSAGE, BAD_REQUEST_STATUS

dbi = db_orm.DbInterface(get_db())

# User
user = get_active_user_from_request(request_data, dbi.session)
if not isinstance(user, UserModel):
return UNAUTHORIZED_MESSAGE, UNAUTHORIZED_STATUS

# Config
config_title = str(request_data['title']).strip()
git_repo_ref = str(request_data['git_repo_ref']).strip()
context_vars = str(request_data['context_vars']).strip()
environment_vars = str(request_data['environment_vars']).strip()
provision_type = str(request_data['provision_type']).strip()
provision_guest = str(request_data['provision_guest']).strip()
provision_guest_port = str(request_data['provision_guest_port']).strip()
ssh_key_id = request_data['ssh_key']

# Check mandatory fields
if config_title == '' or provision_type == '':
return BAD_REQUEST_MESSAGE, BAD_REQUEST_STATUS

if provision_type == 'connect':
if provision_guest == '' or provision_guest_port == '' or ssh_key_id == '' or ssh_key_id == '0':
return BAD_REQUEST_MESSAGE, BAD_REQUEST_STATUS

try:
ssh_key = dbi.session.query(SshKeyModel).filter(
SshKeyModel.id == ssh_key_id,
SshKeyModel.created_by_id == user.id
).one()
except NoResultFound:
return BAD_REQUEST_MESSAGE, BAD_REQUEST_STATUS
else:
ssh_key = None

test_config = TestRunConfigModel(config_title,
git_repo_ref,
context_vars,
environment_vars,
provision_type,
provision_guest,
provision_guest_port,
ssh_key,
user)

dbi.session.add(test_config)
dbi.session.commit()
dbi.engine.dispose()

return test_config.as_dict()


class TestRun(Resource):
fields = get_model_editable_fields(TestRunModel, False)
Expand Down
4 changes: 4 additions & 0 deletions api/tmttestrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def __init__(self, id):
sys.exit(3)

env_str = f'basil_test_case_id={mapping.test_case.id};'
env_str += f'basil_test_case_title={mapping.test_case.title};'
env_str += f'basil_api_api={mapping.api.api};'
env_str += f'basil_api_library={mapping.api.library};'
env_str += f'basil_api_library_version={mapping.api.library_version};'
env_str += f'basil_test_case_mapping_table={self.db_test_run.mapping_to};'
env_str += f'basil_test_case_mapping_id={self.db_test_run.mapping_id};'
env_str += f'basil_test_relative_path={mapping.test_case.relative_path};'
Expand Down
24 changes: 16 additions & 8 deletions app/src/app/AppLayout/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,22 @@ const AppLayout: React.FunctionComponent<IAppLayout> = ({ children }) => {
let url = Constants.API_BASE_URL + '/user/notifications?'
url += '&user-id=' + auth.userId + '&token=' + auth.token

fetch(url)
.then((res) => res.json())
.then((data) => {
setNotifications(data)
})
.catch((err) => {
console.log(err.message)
})
fetch(url).then((response) => {
const success = response.ok
response
.json()
.then((data) => {
console.log(data.message)
console.log(success)
if (!success) {
auth.logOut()
}
setNotifications(data)
})
.catch((err) => {
console.log(err.message)
})
})
}

const Header = (
Expand Down
13 changes: 13 additions & 0 deletions app/src/app/Constants/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@ export const docFormEmpty = {
url: ''
}

export const getLimitedText = (_text, _length) => {
if (_text == undefined) {
return ''
}
if (_length == 0) {
return _text
}
if (_text.length > _length) {
return _text.substr(0, _length) + '...'
}
return _text
}

export const logObject = (obj) => {
let i
let k
Expand Down
2 changes: 1 addition & 1 deletion app/src/app/Dashboard/APIListingTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const APIListingTable: React.FunctionComponent<APIListingTableProps> = ({
{dataRow.api}
</Button>
</Td>
<Td dataLabel={columnNames.library_version}>{dataRow.library_version}</Td>
<Td dataLabel={columnNames.library_version}>{Constants.getLimitedText(dataRow.library_version, 10)}</Td>
<Td dataLabel={columnNames.created_by}>{dataRow.created_by}</Td>
<Td dataLabel={columnNames.category}>{dataRow.category}</Td>
<Td dataLabel={columnNames.coverage}>
Expand Down
42 changes: 14 additions & 28 deletions app/src/app/Mapping/MappingListingTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,6 @@ const MappingListingTable: React.FunctionComponent<MappingListingTableProps> = (
work_items: 'WORK ITEMS'
}

const getLimitedText = (_text, _length) => {
if (_text == undefined) {
return ''
}
if (_length == 0) {
return _text
}
let tmp = _text.substr(0, _length)
if (_text.length > _length) {
tmp = tmp + '...'
}
return tmp
}

const coverageFormat = (x) => Number.parseFloat(x).toFixed(1)

const getMappedSectionCodeBlockBackgroundColor = (snippet) => {
Expand Down Expand Up @@ -277,7 +263,7 @@ const MappingListingTable: React.FunctionComponent<MappingListingTableProps> = (
.then((data) => {
if ('valid' in data) {
ret = data['valid']
let label = document.getElementById('label-document-valid-' + _id)
const label = document.getElementById('label-document-valid-' + _id)
if (ret) {
if (label) {
label.innerHTML = ret
Expand Down Expand Up @@ -372,9 +358,9 @@ const MappingListingTable: React.FunctionComponent<MappingListingTableProps> = (
<Flex>
<FlexItem>
<TextContent>
<Text component={TextVariants.h5}>{getLimitedText(test_case[Constants._TC_]['title'], 0)}</Text>
<Text component={TextVariants.h5}>{Constants.getLimitedText(test_case[Constants._TC_]['title'], 0)}</Text>
<Text className='work-item-detail-text'>
<ReactMarkdown>{getLimitedText(test_case[Constants._TC_]['description'], 0)}</ReactMarkdown>
<ReactMarkdown>{Constants.getLimitedText(test_case[Constants._TC_]['description'], 0)}</ReactMarkdown>
</Text>
</TextContent>
</FlexItem>
Expand Down Expand Up @@ -476,18 +462,18 @@ const MappingListingTable: React.FunctionComponent<MappingListingTableProps> = (
<Flex>
<FlexItem>
<TextContent>
<Text component={TextVariants.h5}>{getLimitedText(test_spec[Constants._TS_]['title'], 0)}</Text>
<Text component={TextVariants.h5}>{Constants.getLimitedText(test_spec[Constants._TS_]['title'], 0)}</Text>
<Text component={TextVariants.h6}>Preconditions:</Text>
<Text className='work-item-detail-text'>
<ReactMarkdown>{getLimitedText(test_spec[Constants._TS_]['preconditions'], 0)}</ReactMarkdown>
<ReactMarkdown>{Constants.getLimitedText(test_spec[Constants._TS_]['preconditions'], 0)}</ReactMarkdown>
</Text>
<Text component={TextVariants.h6}>Test Description:</Text>
<Text className='work-item-detail-text'>
<ReactMarkdown>{getLimitedText(test_spec[Constants._TS_]['test_description'], 0)}</ReactMarkdown>
<ReactMarkdown>{Constants.getLimitedText(test_spec[Constants._TS_]['test_description'], 0)}</ReactMarkdown>
</Text>
<Text component={TextVariants.h6}>Expected Behavior:</Text>
<Text className='work-item-detail-text'>
<ReactMarkdown>{getLimitedText(test_spec[Constants._TS_]['expected_behavior'], 0)}</ReactMarkdown>
<ReactMarkdown>{Constants.getLimitedText(test_spec[Constants._TS_]['expected_behavior'], 0)}</ReactMarkdown>
</Text>
</TextContent>
</FlexItem>
Expand Down Expand Up @@ -586,9 +572,9 @@ const MappingListingTable: React.FunctionComponent<MappingListingTableProps> = (
<Flex>
<FlexItem>
<TextContent>
<Text component={TextVariants.h5}>{getLimitedText(mappedItem[Constants._SR_]['title'], 0)}</Text>
<Text component={TextVariants.h5}>{Constants.getLimitedText(mappedItem[Constants._SR_]['title'], 0)}</Text>
<Text className='work-item-detail-text'>
<ReactMarkdown>{getLimitedText(mappedItem[Constants._SR_]['description'], 0)}</ReactMarkdown>
<ReactMarkdown>{Constants.getLimitedText(mappedItem[Constants._SR_]['description'], 0)}</ReactMarkdown>
</Text>
</TextContent>
</FlexItem>
Expand Down Expand Up @@ -663,7 +649,7 @@ const MappingListingTable: React.FunctionComponent<MappingListingTableProps> = (
<FlexItem>
<TextContent>
<Text className='work-item-detail-text'>
<ReactMarkdown>{getLimitedText(mappedItem[Constants._J]['description'], 0)}</ReactMarkdown>
<ReactMarkdown>{Constants.getLimitedText(mappedItem[Constants._J]['description'], 0)}</ReactMarkdown>
</Text>
</TextContent>
</FlexItem>
Expand Down Expand Up @@ -741,7 +727,7 @@ const MappingListingTable: React.FunctionComponent<MappingListingTableProps> = (
<FlexItem>
<TextContent>
<Text className='work-item-detail-text'>
<ReactMarkdown>{getLimitedText(mappedItem[Constants._D]['description'], 0)}</ReactMarkdown>
<ReactMarkdown>{Constants.getLimitedText(mappedItem[Constants._D]['description'], 0)}</ReactMarkdown>
</Text>
</TextContent>
</FlexItem>
Expand Down Expand Up @@ -801,7 +787,7 @@ const MappingListingTable: React.FunctionComponent<MappingListingTableProps> = (
<FlexItem>
<TextContent>
<Text className='work-item-detail-document-offset'>
<b>Offset:</b> {getLimitedText(mappedItem[Constants._D]['offset'], 0)}
<b>Offset:</b> {Constants.getLimitedText(mappedItem[Constants._D]['offset'], 0)}
</Text>
</TextContent>
</FlexItem>
Expand All @@ -818,7 +804,7 @@ const MappingListingTable: React.FunctionComponent<MappingListingTableProps> = (
<Flex>
<FlexItem>
<CodeBlock>
<CodeBlockCode>{getLimitedText(mappedItem[Constants._D]['section'], 0)}</CodeBlockCode>
<CodeBlockCode>{Constants.getLimitedText(mappedItem[Constants._D]['section'], 0)}</CodeBlockCode>
</CodeBlock>
</FlexItem>
</Flex>
Expand Down Expand Up @@ -901,7 +887,7 @@ const MappingListingTable: React.FunctionComponent<MappingListingTableProps> = (
<FlexItem>
<TextContent>
<Text component={TextVariants.h5}>
<ReactMarkdown>{getLimitedText(work_item_description, 0)}</ReactMarkdown>
<ReactMarkdown>{Constants.getLimitedText(work_item_description, 0)}</ReactMarkdown>
</Text>
</TextContent>
</FlexItem>
Expand Down
71 changes: 71 additions & 0 deletions db/models/migration/sqlite_1_3_0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
CREATE TABLE IF NOT EXISTS documents (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
title VARCHAR(200),
description VARCHAR,
document_type VARCHAR,
spdx_relation VARCHAR(200),
url VARCHAR,
section VARCHAR NOT NULL,
"offset" INTEGER NOT NULL,
valid INTEGER NOT NULL,
created_by_id INTEGER NOT NULL,
edited_by_id INTEGER NOT NULL,
status VARCHAR(30) NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
FOREIGN KEY(created_by_id) REFERENCES users (id),
FOREIGN KEY(edited_by_id) REFERENCES users (id)
);
CREATE TABLE IF NOT EXISTS documents_history (
row_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
id INTEGER NOT NULL,
title VARCHAR(200),
description VARCHAR,
document_type VARCHAR,
spdx_relation VARCHAR(200),
url VARCHAR,
section VARCHAR NOT NULL,
"offset" INTEGER NOT NULL,
valid INTEGER NOT NULL,
created_by_id INTEGER NOT NULL,
edited_by_id INTEGER NOT NULL,
status VARCHAR(30) NOT NULL,
version INTEGER NOT NULL,
created_at DATETIME NOT NULL,
FOREIGN KEY(created_by_id) REFERENCES users (id),
FOREIGN KEY(edited_by_id) REFERENCES users (id)
);
CREATE TABLE IF NOT EXISTS document_mapping_api (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
api_id INTEGER NOT NULL,
document_id INTEGER NOT NULL,
section VARCHAR NOT NULL,
"offset" INTEGER NOT NULL,
coverage INTEGER NOT NULL,
created_by_id INTEGER NOT NULL,
edited_by_id INTEGER NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
FOREIGN KEY(api_id) REFERENCES apis (id),
FOREIGN KEY(document_id) REFERENCES documents (id),
FOREIGN KEY(created_by_id) REFERENCES users (id),
FOREIGN KEY(edited_by_id) REFERENCES users (id)
);
CREATE TABLE IF NOT EXISTS document_mapping_api_history (
row_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
id INTEGER NOT NULL,
api_id INTEGER NOT NULL,
document_id INTEGER NOT NULL,
section VARCHAR NOT NULL,
"offset" INTEGER NOT NULL,
coverage INTEGER NOT NULL,
created_by_id INTEGER NOT NULL,
edited_by_id INTEGER NOT NULL,
version INTEGER NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
FOREIGN KEY(api_id) REFERENCES apis (id),
FOREIGN KEY(document_id) REFERENCES documents (id),
FOREIGN KEY(created_by_id) REFERENCES users (id),
FOREIGN KEY(edited_by_id) REFERENCES users (id)
);
Loading

0 comments on commit 4b43193

Please sign in to comment.