public Path getAndPopulateTempDirectory()

in src/main/java/com/awslabs/aws/greengrass/provisioner/docker/OfficialGreengrassImageDockerHelper.java [139:199]


    public Path getAndPopulateTempDirectory(GreengrassGroupName greengrassGroupName) throws IOException {
        Path innerTempDirectory = Files.createTempDirectory(greengrassGroupName.getGroupName());

        Path localCertsPath = innerTempDirectory.resolve(ggConstants.getCertsDirectoryPrefix());
        Path localConfigPath = innerTempDirectory.resolve(ggConstants.getConfigDirectoryPrefix());

        Files.createDirectory(localCertsPath);
        Files.createDirectory(localConfigPath);

        String coreCertFilename = String.join("/",
                ggConstants.getCertsDirectoryPrefix(),
                ggConstants.getCorePublicCertificateName());

        String coreKeyFilename = String.join("/",
                ggConstants.getCertsDirectoryPrefix(),
                ggConstants.getCorePrivateKeyName());

        String rootCaFilename = String.join("/",
                ggConstants.getCertsDirectoryPrefix(),
                ggConstants.getRootCaName());
        String configJsonFilename = String.join("/",
                ggConstants.getConfigDirectoryPrefix(),
                ggConstants.getConfigFileName());

        String oemArchiveName = ggVariables.getOemArchiveName(greengrassGroupName);

        Optional<InputStream> coreCertStream = ioHelper.extractTar(oemArchiveName, coreCertFilename);
        Optional<InputStream> coreKeyStream = ioHelper.extractTar(oemArchiveName, coreKeyFilename);
        Optional<InputStream> rootCaStream = ioHelper.extractTar(oemArchiveName, rootCaFilename);
        Optional<InputStream> configJsonStream = ioHelper.extractTar(oemArchiveName, configJsonFilename);

        List<String> errors = new ArrayList<>();

        if (!coreCertStream.isPresent()) {
            errors.add("Couldn't extract core certificate from the OEM file");
        }

        if (!coreKeyStream.isPresent()) {
            errors.add("Couldn't extract core private key from the OEM file");
        }

        if (!rootCaStream.isPresent()) {
            errors.add("Couldn't extract the root CA from the OEM file");
        }

        if (!configJsonStream.isPresent()) {
            errors.add("Couldn't extract the config.json from the OEM file");
        }

        if (errors.size() != 0) {
            errors.forEach(log::error);
            throw new RuntimeException("OEM extraction failed");
        }

        FileUtils.copyInputStreamToFile(coreCertStream.get(), innerTempDirectory.resolve(coreCertFilename).toFile());
        FileUtils.copyInputStreamToFile(coreKeyStream.get(), innerTempDirectory.resolve(coreKeyFilename).toFile());
        FileUtils.copyInputStreamToFile(rootCaStream.get(), innerTempDirectory.resolve(rootCaFilename).toFile());
        FileUtils.copyInputStreamToFile(configJsonStream.get(), innerTempDirectory.resolve(configJsonFilename).toFile());

        return innerTempDirectory;
    }