forked from eclipse-jkube/jkube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (jkube-kit/resource/helm) : Support for Pushing Helm Charts to O…
…CI (eclipse-jkube#2091) + Add SHAUtil for generating SHA digests (used in oci helm push) + Add OCIRepositoryUploader as an additional HelmUploader + Add OCI repository related helper classes in `org.eclipse.jkube.kit.resource.helm.oci` package Signed-off-by: Rohan Kumar <rohaan@redhat.com>
- Loading branch information
1 parent
b016b35
commit 2f227c4
Showing
28 changed files
with
1,409 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/SHAUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.common.util; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
public class SHAUtil { | ||
private static final int BUFFER_SIZE = 8192; | ||
private static final String SHA_256 = "SHA-256"; | ||
private SHAUtil() { } | ||
|
||
public static String generateSHA256(File file) throws IOException { | ||
return generateSHA(file, SHA_256); | ||
} | ||
|
||
public static String generateSHA256(String input) { | ||
MessageDigest digest = createNewMessageDigest(SHA_256); | ||
return bytesToHex(digest.digest(input.getBytes(StandardCharsets.UTF_8))); | ||
} | ||
|
||
public static String generateSHA(File file, String algorithm) throws IOException { | ||
try (InputStream input = Files.newInputStream(file.toPath())) { | ||
MessageDigest shaDigest = createNewMessageDigest(algorithm); | ||
byte[] buffer = new byte[BUFFER_SIZE]; | ||
int len = input.read(buffer); | ||
|
||
while (len != -1) { | ||
shaDigest.update(buffer, 0, len); | ||
len = input.read(buffer); | ||
} | ||
|
||
return bytesToHex(shaDigest.digest()); | ||
} | ||
} | ||
|
||
static MessageDigest createNewMessageDigest(String algorithm) { | ||
try { | ||
return MessageDigest.getInstance(algorithm); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new IllegalArgumentException("Error while generating SHA, no such algorithm : " + algorithm); | ||
} | ||
} | ||
|
||
private static String bytesToHex(byte[] hash) { | ||
StringBuilder hexString = new StringBuilder(2 * hash.length); | ||
for (byte b : hash) { | ||
String hex = Integer.toHexString(0xff & b); | ||
if (hex.length() == 1) { | ||
hexString.append('0'); | ||
} | ||
hexString.append(hex); | ||
} | ||
return hexString.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
...e-kit/common/src/test/java/org/eclipse/jkube/kit/common/util/TestFabric8HttpResponse.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.