From 6489ec0dc2d1212e016753445196c2257de07b36 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Mon, 8 Jul 2024 22:33:52 -0300 Subject: [PATCH] Use base58 for random strings --- src/commands/build.cr | 4 +++- src/daemon/funko.cr | 3 ++- src/funko.cr | 7 +------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/commands/build.cr b/src/commands/build.cr index 7eb388d..b34f9b0 100644 --- a/src/commands/build.cr +++ b/src/commands/build.cr @@ -1,3 +1,5 @@ +require "base58" + module Faaso module Commands # Build images for one or more funkos from source @@ -7,7 +9,7 @@ module Faaso # Create temporary build location funkos.each do |funko| - tmp_dir = Path.new("tmp", UUID.random.to_s) + tmp_dir = Path.new("tmp", Random.base58(8)) Dir.mkdir_p(tmp_dir) unless File.exists? tmp_dir funko.runtime = nil if options["--no-runtime"] diff --git a/src/daemon/funko.cr b/src/daemon/funko.cr index fff6787..380b2ec 100644 --- a/src/daemon/funko.cr +++ b/src/daemon/funko.cr @@ -1,3 +1,4 @@ +require "base58" require "docr" require "kemal" require "../funko.cr" @@ -34,7 +35,7 @@ module Funko # mosquito-cr/mosquito to make it a job queue post "/funkos/build/" do |env| # Create place to build funko - tmp_dir = Path.new("tmp", UUID.random.to_s) + tmp_dir = Path.new("tmp", Random.base58(8)) Dir.mkdir_p(tmp_dir) unless File.exists? tmp_dir # Expand tarball in there diff --git a/src/funko.cr b/src/funko.cr index 6f42621..4a10f77 100644 --- a/src/funko.cr +++ b/src/funko.cr @@ -309,7 +309,7 @@ module Funko ) docker_api = Docr::API.new(Docr::Client.new) - response = docker_api.containers.create(name: "faaso-#{name}-#{randstr}", config: conf) + response = docker_api.containers.create(name: "faaso-#{name}-#{Random.base58(6)}", config: conf) response.@warnings.each { |msg| Log.warn { msg } } docker_api.containers.start(response.@id) if autostart response.@id @@ -349,8 +349,3 @@ module Funko end end end - -def randstr(length = 6) : String - chars = "abcdefghijklmnopqrstuvwxyz0123456789" - String.new(Bytes.new(chars.to_slice.sample(length).to_unsafe, length)) -end