Skip to content

Commit 128d4ec

Browse files
authored
Merge branch 'main' into 227-investigate-enforcing-https-sonarqube
2 parents effb2a1 + 9aecd44 commit 128d4ec

File tree

3 files changed

+34
-29
lines changed

3 files changed

+34
-29
lines changed

anms-core/anms/routes/adms/adm.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
AdmData = adm_data.AdmData
5757
DataModel = data_model_view.DataModel
5858

59-
ACCEPT_FILE_CONTENT_TYPE = "application/octet-stream"
59+
ACCEPT_FILE_CONTENT_TYPE = ["application/octet-stream","application/yang" ]
6060

6161

6262
class RequestError(BaseModel):
@@ -136,8 +136,10 @@ async def handle_adm(admset: ace.AdmSet, adm_file: ace.models.AdmModule, session
136136
if not replace:
137137
logger.info('Not replacing existing ADM name %s', adm_file.norm_name)
138138
return []
139+
data_rec = None
140+
async with get_async_session() as session:
141+
data_rec,_ = await AdmData.get(data_model_view.data_model_id,session)
139142

140-
data_rec = await AdmData.get(data_model_view.data_model_id)
141143
if data_rec:
142144
# Compare old and new contents
143145
logger.info("Checking existing ADM name %s", adm_file.norm_name)
@@ -194,7 +196,7 @@ async def update_adm(file: UploadFile, request: Request):
194196
message = ""
195197
error_details = [] # This is used to store the comparison details between the old adm and the new adm
196198
# Check if not application/json
197-
if file.content_type != ACCEPT_FILE_CONTENT_TYPE:
199+
if file.content_type not in ACCEPT_FILE_CONTENT_TYPE:
198200
message = f"Expect {ACCEPT_FILE_CONTENT_TYPE}. Received: {file.content_type}"
199201
status_code = status.HTTP_415_UNSUPPORTED_MEDIA_TYPE
200202
logger.error(message)
@@ -205,7 +207,7 @@ async def update_adm(file: UploadFile, request: Request):
205207
try:
206208
adm_file_contents = await file.read()
207209
try:
208-
adm_file = admset.load_from_data(io.BytesIO(adm_file_contents).getvalue(), del_dupe=False)
210+
adm_file = admset.load_from_data(io.StringIO(adm_file_contents.decode('utf-8')), del_dupe=False)
209211
except Exception as err:
210212
adm_file = None
211213
status_code = status.HTTP_422_UNPROCESSABLE_ENTITY
@@ -214,19 +216,21 @@ async def update_adm(file: UploadFile, request: Request):
214216

215217
if adm_file:
216218
logger.info("Adm name: %s", adm_file.norm_name)
219+
data_rec = None
217220
# get data_model_id
218-
data_model_rec, error_message = await DataModel.get(adm_file.ns_model_enum, adm_file.ns_org_name )
219-
if error_message:
220-
raise Exception(error_message)
221-
222-
223-
data_rec, error_message = await AdmData.get(data_model_rec.data_model_id )
224-
if error_message:
225-
raise Exception(error_message)
221+
async with get_async_session() as session:
222+
data_model_rec = await DataModel.get(adm_file.ns_model_enum, adm_file.ns_org_name, session )
223+
if data_model_rec == None:
224+
logger.info("new ADM dont compare" )
225+
else:
226+
data_rec,_ = await AdmData.get(data_model_rec.data_model_id,session )
227+
if data_rec == None:
228+
logger.warning("ADM not in DB can't compare")
229+
226230
# Compare with existing adm
227231
if data_rec:
228232
# Compare old and new contents
229-
old_adm = admset.load_from_data(io.BytesIO(data_rec.data).getvalue(), del_dupe=False)
233+
old_adm = admset.load_from_data(io.StringIO(data_rec.data.decode('utf-8')), del_dupe=False)
230234
status_code = status.HTTP_200_OK
231235
if not comp.compare_adms(old_adm, adm_file):
232236
message = f"Updating existing adm {adm_file.norm_name}"
@@ -235,9 +239,10 @@ async def update_adm(file: UploadFile, request: Request):
235239
# reload adm_set
236240
admset.db_session().close()
237241
admset = ace.AdmSet(cache_dir=False)
238-
adm_file = admset.load_from_data(io.BytesIO(adm_file_contents), del_dupe=False)
242+
adm_file = admset.load_from_data(io.StringIO(adm_file_contents.decode('utf-8')), del_dupe=False)
239243
else: # if its the same nothing else to be done
240-
logger.info("Duplicate ADM add attempted")
244+
logger.warning("Duplicate ADM add attempted")
245+
message = "Duplicate ADM add attempted"
241246
response = JSONResponse(status_code=status_code,
242247
content={"message": message, "error_details": error_details})
243248
return response
@@ -277,7 +282,7 @@ async def update_adm(file: UploadFile, request: Request):
277282
try:
278283
async with get_async_session() as session:
279284
# get data_model_id
280-
285+
data_model_rec = await DataModel.get(adm_file.ns_model_enum, adm_file.ns_org_name, session )
281286
# Save the adm file of the new adm
282287
data = {"enumeration": data_model_rec.data_model_id, "data": adm_file_contents}
283288
response, error_message = await AdmData.add_data(data, session)

anms-ui/server/components/adms.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
const requestTimeOut = 3000; //milliseconds
3939
const axios = require('axios');
4040
const FormData = require('form-data');
41-
const ACCEPTED_ADM_TYPE = 'application/json';
41+
const ACCEPTED_ADM_TYPE = 'application/octet-stream';
4242

4343
exports.getAll = async function (req, res, next) {
4444
try {
@@ -97,7 +97,7 @@
9797
exports.upload = async function (req, res, next) {
9898
const usersReqHeader = utils.createAuthenticationHeader(req);
9999
const file = req.file;
100-
100+
101101
if (!_.isNull(file) && file.mimetype != ACCEPTED_ADM_TYPE) {
102102
return res.status(415).json({"message": `Not support this ${file.mimetype}`});
103103
}
@@ -126,6 +126,7 @@
126126
});
127127
if (_.isNil(response) || _.isNil(response.data) || _.isNil(response.data.message)) {
128128
response.status = 500;
129+
console.error(response);
129130
response.data = {"message": "Internal Server Error"};
130131
}
131132
return res.status(response.status).json(response.data);

deps/test-ion-configs/mgr.rc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ION Configuration File for Node N1, ipn:1
1+
# ION Configuration File for Node N1, ipn:1, hostname manager
22
## begin ionadmin
33
1 1 ''
44
s
@@ -12,12 +12,13 @@ m horizon +0
1212
## begin bpadmin
1313
1
1414
e 1
15+
w 1
1516
a scheme ipn 'ipnfw' 'ipnadminep'
1617
a endpoint ipn:1.0 x
1718
a endpoint ipn:1.1 x
1819
a endpoint ipn:1.4 x
19-
a endpoint ipn:1.6 x
20-
a endpoint ipn:1.7 x
20+
a endpoint ipn:1.6 q
21+
a endpoint ipn:1.7 q
2122

2223

2324
# Protocols
@@ -28,19 +29,17 @@ a protocol tcp 1400 100
2829
a induct udp 0.0.0.0:4556 udpcli
2930

3031
# Outducts
31-
a outduct udp 127.0.0.1 udpclo
32-
a outduct udp ION-AGENT2:4556 udpclo
33-
a outduct udp ION-AGENT3:4556 udpclo
34-
32+
a outduct udp 10.5.0.101:4556 udpclo
33+
a outduct udp 10.5.0.102:4556 udpclo
34+
a outduct udp 10.5.0.103:4556 udpclo
3535

3636
s
3737
## end bpadmin
3838

3939
## begin ipnadmin
40-
a plan 1 udp/127.0.0.1
41-
a plan 2 udp/ION-AGENT2:4556
42-
a plan 3 udp/ION-AGENT3:4556
43-
40+
a plan 1 udp/10.5.0.101:4556
41+
a plan 2 udp/10.5.0.102:4556
42+
a plan 3 udp/10.5.0.103:4556
4443

4544
## end ipnadmin
4645

0 commit comments

Comments
 (0)