diff options
author | Jeffrey Armstrong <jeff@approximatrix.com> | 2022-04-28 08:54:49 -0400 |
---|---|---|
committer | Jeffrey Armstrong <jeff@approximatrix.com> | 2022-04-28 08:54:49 -0400 |
commit | e7aaa0256420e8d30dee54e603af60d54434c38e (patch) | |
tree | 908e5d435ea036f8382ed23d7cf30f1c16b04a46 | |
parent | 6ae21577802462f38d98dd0e5415166008b1b13f (diff) | |
download | levitating-e7aaa0256420e8d30dee54e603af60d54434c38e.tar.gz levitating-e7aaa0256420e8d30dee54e603af60d54434c38e.zip |
Added module to generate uuids by calling uuidgen utility
-rw-r--r-- | captain/captain.f90 | 13 | ||||
-rw-r--r-- | captain/levitating-captain.prj | 5 | ||||
-rw-r--r-- | captain/uuid.f90 | 36 |
3 files changed, 53 insertions, 1 deletions
diff --git a/captain/captain.f90 b/captain/captain.f90 index 6713a9e..46287d9 100644 --- a/captain/captain.f90 +++ b/captain/captain.f90 @@ -82,6 +82,7 @@ contains subroutine parse_options use config use m_crypt + use m_uuid, only: generate_uuid4 use captain_db, only: new_admin_db implicit none @@ -122,6 +123,18 @@ contains Print *, "Unverify: "//trim(option)//"X", verify_hash(trim(option)//"X", tmp) stop + ! This option also shouldn't be public, and it verifies that + ! uuids can be generated + else if(trim(option) == "--uuid") then + if(.not. config_loaded) then + ! Look up a directory for temp files - needed below + call get_environment_variable("TEMP", temp_dir) + end if + + option = generate_uuid4() + print *, trim(option) + stop + else if(trim(option) == "--new-admin") then ! Config better be loaded by now... diff --git a/captain/levitating-captain.prj b/captain/levitating-captain.prj index 33003dd..4a2ecbd 100644 --- a/captain/levitating-captain.prj +++ b/captain/levitating-captain.prj @@ -138,6 +138,9 @@ "filename":"template.f90", "enabled":"1" },{ + "filename":"uuid.f90", + "enabled":"1" + },{ "filename":"web.f90", "enabled":"1" }] @@ -184,7 +187,7 @@ "Launch Using MPI":"false", "Keep Console":"true", "External Console":"false", - "Command Line Arguments":"-c example/levitating.conf --new-admin jeff password", + "Command Line Arguments":"--uuid", "Build Before Launch":"true" }, "Build Options":{ diff --git a/captain/uuid.f90 b/captain/uuid.f90 new file mode 100644 index 0000000..1b2d882 --- /dev/null +++ b/captain/uuid.f90 @@ -0,0 +1,36 @@ +module m_uuid +implicit none + + integer, parameter::UUID_LENGTH = 36 + + character(len=*), parameter::UUID_GENERATOR = "uuidgen" + +contains + + function generate_uuid4() result(uuid) + use utilities + implicit none + + character(len=:), pointer::tempfile + character(len=UUID_LENGTH)::uuid + + character(len=5)::fmt + + integer::unum + + tempfile => generate_temporary_filename() + + call execute_command_line(UUID_GENERATOR//" > "//trim(tempfile), wait=.true.) + + open(newunit=unum, action="read", file=tempfile, status="old") + write(fmt, '(I3)') UUID_LENGTH + fmt = "(A"//trim(adjustl(fmt))//")" + read(unum, fmt) uuid + close(unum) + call unlink(tempfile) + + deallocate(tempfile) + + end function generate_uuid4 + +end module m_uuid
\ No newline at end of file |