use of java.nio.file.attribute.PosixFilePermission in project aion by aionnetwork.
the class Aion method writeKeyToFile.
private static void writeKeyToFile(final String path, final String fileName, final String key) throws IOException {
Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxr-----");
FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms);
Path p = Paths.get(path).resolve(fileName);
Path keyFile;
if (!java.nio.file.Files.exists(p)) {
keyFile = java.nio.file.Files.createFile(p, attr);
} else {
keyFile = p;
}
FileOutputStream fos = new FileOutputStream(keyFile.toString());
fos.write(key.getBytes());
fos.close();
}
use of java.nio.file.attribute.PosixFilePermission in project athenz by yahoo.
the class ZMSFileChangeLogStoreCommonTest method testSetFilePermissionsException.
@Test
public void testSetFilePermissionsException() throws IOException {
ZMSFileChangeLogStoreCommon fstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
FilesHelper helper = Mockito.mock(FilesHelper.class);
Mockito.when(helper.setPosixFilePermissions(any(), any())).thenThrow(new IOException("io exception"));
fstore.filesHelper = helper;
try {
File file = new File(FSTORE_PATH, "domain");
Set<PosixFilePermission> perms = EnumSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE);
fstore.setupFilePermissions(file, perms);
fail();
} catch (Exception ex) {
assertTrue(true);
}
}
use of java.nio.file.attribute.PosixFilePermission in project engineblock by engineblock.
the class DockerMetricsHelper method setupGrafanaFiles.
private void setupGrafanaFiles(String ip) {
File grafanaDir = new File(userHome, ".eb/grafana");
grafanaDir.mkdir();
Path grafanaDirPath = Paths.get(userHome, ".eb/grafana");
Set<PosixFilePermission> perms = new HashSet<>();
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.OWNER_WRITE);
perms.add(PosixFilePermission.OWNER_EXECUTE);
try {
Files.setPosixFilePermissions(grafanaDirPath, perms);
} catch (IOException e) {
logger.error("failed to set permissions on prom backup directory (~/.eb/prometheus)");
e.printStackTrace();
System.exit(1);
}
}
use of java.nio.file.attribute.PosixFilePermission in project engineblock by engineblock.
the class DockerMetricsHelper method setupPromFiles.
private void setupPromFiles(String ip) {
String datasource = EngineBlockFiles.readFile("docker/prometheus/prometheus.yml");
if (ip == null) {
logger.error("IP for graphite container not found");
System.exit(1);
}
datasource = datasource.replace("!!!GRAPHITE_IP!!!", ip);
File prometheusDir = new File(userHome, ".eb/prometheus");
prometheusDir.mkdir();
new File(userHome, ".eb/prometheus-conf").mkdir();
Path prometheusDirPath = Paths.get(userHome, ".eb/prometheus");
Set<PosixFilePermission> perms = new HashSet<>();
perms.add(PosixFilePermission.OTHERS_READ);
perms.add(PosixFilePermission.OTHERS_WRITE);
perms.add(PosixFilePermission.OTHERS_EXECUTE);
try {
Files.setPosixFilePermissions(prometheusDirPath, perms);
} catch (IOException e) {
logger.error("failed to set permissions on prom backup directory (~/.eb/prometheus)");
e.printStackTrace();
System.exit(1);
}
try (PrintWriter out = new PrintWriter(new FileWriter(userHome + "/.eb/prometheus-conf/prometheus.yml", false))) {
out.println(datasource);
} catch (FileNotFoundException e) {
e.printStackTrace();
logger.error("error writing prometheus yaml file to ~/.prometheus");
System.exit(1);
} catch (IOException e) {
e.printStackTrace();
logger.error("creating file in ~/.prometheus");
System.exit(1);
}
}
use of java.nio.file.attribute.PosixFilePermission in project cloudconductor-agent-redhat by cinovo.
the class FileHelper method isFileMode.
/**
* Check if a file has a specific file mode or not
*
* @param file the file to check
* @param fileMode the file mode to check
* @return file mode is equal or not
* @throws IOException on error
*/
public static boolean isFileMode(File file, String fileMode) throws IOException {
PosixFileAttributeView view = FileHelper.getFileAttributes(file);
Set<PosixFilePermission> fileModeSet = PosixFilePermissions.fromString(fileMode);
if (view.readAttributes().permissions().equals(fileModeSet)) {
return true;
}
return false;
}
Aggregations