Skip to content

Commit a241a6c

Browse files
committed
1.1 - functionality for custom company_id and status_id settings
1 parent 5000977 commit a241a6c

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

config-example.ini

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
[DEFAULT]
22
site = http://insert_url_here.com/api/v1
3-
api_key = insert_api_key_here
3+
api_key = insert_api_key_here
4+
5+
[GENERAL]
6+
snipeit_status_id = 2
7+
snipeit_company_id = 1

main.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def get_or_create_model(self, manufacturer_id):
142142
model_id = self.get_model(self.model)
143143
return model_id
144144

145-
def post_hardware(self, serial_number, model_id, status_id=2, company_id=1):
145+
def post_hardware(self, serial_number, model_id, status_id, company_id):
146146
endpoint = 'hardware'
147147
payload = {
148148
'serial': serial_number,
@@ -180,7 +180,7 @@ def get_hardware(self, serial_number):
180180
print("No hardware found in database, perhaps create a new one?")
181181
return None
182182

183-
def patch_hardware(self, hardware_id, serial_number, model_id, status_id=2, company_id=1):
183+
def patch_hardware(self, hardware_id, serial_number, model_id, status_id, company_id):
184184
endpoint = f'hardware/{hardware_id}?deleted=false'
185185
payload = {
186186
'serial': serial_number,
@@ -207,17 +207,17 @@ def patch_hardware(self, hardware_id, serial_number, model_id, status_id=2, comp
207207
print(f"Failed to update hardware: {response.get('messages')}")
208208
return False
209209

210-
def get_or_create_hardware(self, model_id, update_hardware):
210+
def get_or_create_hardware(self, model_id, update_hardware, status_id = 2, company_id = 1):
211211
hardware_id = self.get_hardware(self.serial_number)
212212
if hardware_id is None:
213213
print("Creating new hardware")
214214
update_hardware = False
215-
success = self.post_hardware(self.serial_number, model_id)
215+
success = self.post_hardware(self.serial_number, model_id, status_id, company_id)
216216
if success:
217217
hardware_id = self.get_hardware(self.serial_number)
218218
if update_hardware:
219219
print("Patching hardware")
220-
self.patch_hardware(hardware_id, self.serial_number, model_id)
220+
self.patch_hardware(hardware_id, self.serial_number, model_id, status_id, company_id)
221221
return hardware_id
222222

223223
# Resolve pyinstaller's stoopid windows executable path issue
@@ -297,8 +297,10 @@ def main():
297297
print("Model fetched: ", model_id)
298298

299299
# Get the hardware, if it exists, update it properly.
300+
snipeit_status_id = config['GENERAL']['snipeit_status_id']
301+
snipeit_company_id = config['GENERAL']['snipeit_company_id']
300302
update_hardware = True
301-
hardware_id = it_client.get_or_create_hardware(model_id, update_hardware)
303+
hardware_id = it_client.get_or_create_hardware(model_id, update_hardware, snipeit_status_id, snipeit_company_id)
302304
if hardware_id is None:
303305
return print("Failed to fetch hardware")
304306
print("Hardware fetched: ", hardware_id)

0 commit comments

Comments
 (0)