Skip to content

Commit

Permalink
fix docker fingerprinting
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Oct 5, 2023
1 parent e3f518f commit f079039
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ print(machineid.hashed_id('myappid'))
print(machineid.hashed_id())
```

## Testing

To run tests, invoke `unittest`:

```bash
python3 -m unittest
```

## Thanks

Special thanks to Denis Brodbeck for his Go package, [`machineid`](https://github.com/denisbrodbeck/machineid).
4 changes: 3 additions & 1 deletion machineid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def id(winregistry: bool = True) -> str:
mountinfo = __read__('/proc/self/mountinfo')
if mountinfo:
if 'docker' in mountinfo:
id = __exec__("grep 'systemd' /proc/self/mountinfo | cut -d/ -f3")
id = __exec__("grep '/data/docker/containers' /proc/self/mountinfo | cut -d/ -f5")
if not id:
id = __exec__("grep '/var/lib/docker/containers' /proc/self/mountinfo | cut -d/ -f6")
if not id:
if 'microsoft' in uname().release: # wsl
id = __exec__("powershell.exe -ExecutionPolicy bypass -command '(Get-CimInstance -Class Win32_ComputerSystemProduct).UUID'")
Expand Down
16 changes: 8 additions & 8 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

class TestMachineId(unittest.TestCase):
def test_hashed_id(self):
self.assertTrue(isinstance(machineid.hashed_id(), str))
self.assertTrue(len(machineid.hashed_id()) > 0)
self.assertTrue(machineid.hashed_id('foo') != machineid.hashed_id('bar'))
self.assertTrue(machineid.hashed_id('foo') != machineid.hashed_id())
self.assertIsInstance(machineid.hashed_id(), str)
self.assertGreater(len(machineid.hashed_id()), 0)
self.assertNotEqual(machineid.hashed_id('foo'), machineid.hashed_id('bar'))
self.assertNotEqual(machineid.hashed_id('foo'), machineid.hashed_id())

def test_id(self):
self.assertTrue(isinstance(machineid.id(), str))
self.assertTrue(len(machineid.id()) > 0)
self.assertTrue(machineid.id() != machineid.hashed_id())
self.assertIsInstance(machineid.id(), str)
self.assertGreater(len(machineid.id()), 0)
self.assertNotEqual(machineid.id(), machineid.hashed_id())

if __name__ == '__main__':
unittest.main()
unittest.main()

0 comments on commit f079039

Please sign in to comment.