Skip to content

Commit

Permalink
Eliminate SonarQube warnings (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert authored Jan 22, 2024
1 parent 871ac29 commit b198d6c
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ private InventoryContent getInventoryContent(ValueProviderContext context) {
content = tryReadInitStyle(inventoryContent);
}

// fallback to empty map
if (content == null) {
content = new InventoryContent(Map.of());
}

// put to cache
context.setValueProviderCache(content);
return content;
Expand All @@ -147,6 +142,7 @@ private InventoryContent tryReadJsonStyle(String inventoryContent, File file, Va
return null;
}

@SuppressWarnings("java:S3776") // ignore complexity
private Map<String, List<String>> jsonToConfig(JsonObject root) {
Map<String, List<String>> content = new HashMap<>();
for (Map.Entry<String, JsonElement> entry : root.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* @author Andrea Scarpino
*/
final public class AnsibleConstants {
public final class AnsibleConstants {

/**
* Connection type to the host. Candidates are <code>local</code>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public final class AnsibleInventoryReader {
private AnsibleInventoryReader() {
}

@SuppressWarnings({ "java:S3776", "java:S135", "java:S6541" }) // ignore complexity
public static AnsibleInventory read(String text) {
final AnsibleInventory inventory = new AnsibleInventory();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private static void printHost(AnsibleHost host, OutputStream stream) throws IOEx
stream.write("\n".getBytes());
}

@SuppressWarnings("java:S3776") // ignore complexity
public static String write(AnsibleInventory inventory) {
final StringBuilder builder = new StringBuilder();

Expand Down Expand Up @@ -120,6 +121,7 @@ public static String write(AnsibleInventory inventory) {
return builder.toString();
}

@SuppressWarnings("java:S3776") // ignore complexity
public static void write(AnsibleInventory inventory, OutputStream stream) throws IOException {
for (AnsibleHost host : inventory.getHosts()) {
printHost(host, stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,12 @@ public Object getFromYaml(Class<?> objectClass, String yaml) {
return reader.load(yaml);
}

public String writeToYaml(Object object) {
public String writeToYaml(Object object) throws IOException {
try (StringWriter resultWriter = new StringWriter()) {
Yaml writer = new Yaml();
writer.dump(object, resultWriter);
return resultWriter.getBuffer().toString();
}
catch (IOException ex) {
throw new RuntimeException(ex);
}
}

public Object getFromVault(Class<?> objectClass, String yaml, String password) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

final public class VaultContent {
public final class VaultContent {

private static final Logger logger = LoggerFactory.getLogger(VaultContent.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.wedjaa.ansible.vault.crypto.data.VaultInfo;
import net.wedjaa.ansible.vault.crypto.decoders.inter.CypherInterface;

@SuppressWarnings("java:S1192") // duplicate string literal
public class CypherAES implements CypherInterface {

public static final String CYPHER_ID = "AES";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ public byte[] encryptAES(byte[] cleartext, byte[] key, byte[] iv) throws IOExcep
try {
Cipher cipher = Cipher.getInstance(CYPHER_ALGO);
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);
byte[] encrypted = cipher.doFinal(cleartext);
return encrypted;
return cipher.doFinal(cleartext);
}
catch (Exception ex) {
throw new IOException("Failed to encrypt data: " + ex.getMessage(), ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ private byte[] createRawKey() throws IOException {
PBKDF2Parameters params = new PBKDF2Parameters(algo, CHAR_ENCODING.name(), salt, iterations);
int keylength = ivlen + 2 * keylen;
PBKDF2Engine pbkdf2Engine = new PBKDF2Engine(params);
byte[] keys = pbkdf2Engine.deriveKey(password, keylength);
return keys;
return pbkdf2Engine.deriveKey(password, keylength);
}
catch (Exception ex) {
throw new IOException("Cryptofailure: " + ex.getMessage(), ex);
Expand Down Expand Up @@ -99,7 +98,6 @@ private byte[] generateSalt(int length) {
return thesalt;
}


public byte[] getSalt() {
return salt;
}
Expand All @@ -108,11 +106,12 @@ public byte[] getEncryptionKey() {
return encryptionKey;
}


@SuppressWarnings("java:S1845") // naming
public byte[] getHmacKey() {
return hmacKey;
}

@SuppressWarnings("java:S1845") // naming
public byte[] getIv() {
return iv;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import io.wcm.devops.conga.generator.util.PluginManager;
import io.wcm.devops.conga.generator.util.PluginManagerImpl;

@SuppressWarnings("java:S5976")
@ExtendWith(MockitoExtension.class)
class AnsibleInventoryValueProviderPluginTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


@SuppressWarnings("java:S5783")
class ManagerTest {

Logger logger = LoggerFactory.getLogger(ManagerTest.class);
Expand Down

0 comments on commit b198d6c

Please sign in to comment.