All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.bitrise.gradle.cache.Globals.kt Maven / Gradle / Ivy

/**
 * Copyright (C)2022 Bitrise
 * All rights reserved.
 */
package io.bitrise.gradle.cache

import io.grpc.Status
import java.security.MessageDigest

const val METADATA_KEY_BLOB_VALIDATION_LEVEL = "x-flare-blob-validation-level"
const val METADATA_KEY_BLOB_VALIDATION_SHA256 = "x-flare-blob-validation-sha256"
const val METADATA_KEY_BLOB_VALIDATION_WARNING = "x-flare-blob-validation-warning"

enum class ValidationLevel(val lvl: String? = null) {
    NONE(), // header is just unset if NONE
    WARNING("WARN"),
    ERROR("ERROR"),
}

fun ByteArray.sha256String(): String {
    return MessageDigest
        .getInstance("SHA-256")
        .digest(this)
        .fold("") { str, it -> str + "%02x".format(it) }
}

inline val currT: Long
    get() {
        return System.currentTimeMillis()
    }

fun Throwable.isNotFound(): Boolean {
    return Status.fromThrowable(this).code == Status.Code.NOT_FOUND
}

fun  Result.mapToFoundOrThrow(throwfn: (Throwable) -> Throwable): Boolean = this.exceptionOrNull().let {
    return when {
        it == null -> true
        it.isNotFound() -> false
        else -> throw throwfn(it)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy