Add files::get_access_token().
This commit is contained in:
parent
0c7df4b98a
commit
119d304164
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -26,8 +28,10 @@ namespace FediBlock::files
|
||||||
{
|
{
|
||||||
|
|
||||||
using std::getenv;
|
using std::getenv;
|
||||||
|
using std::ifstream;
|
||||||
using std::runtime_error;
|
using std::runtime_error;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using std::stringstream;
|
||||||
using std::uintmax_t;
|
using std::uintmax_t;
|
||||||
|
|
||||||
string _tmpdir;
|
string _tmpdir;
|
||||||
|
@ -82,4 +86,18 @@ fs::path get_datadir()
|
||||||
throw runtime_error{"Could not find data dir"};
|
throw runtime_error{"Could not find data dir"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string get_access_token()
|
||||||
|
{
|
||||||
|
ifstream file(get_datadir() / "gitea_access_token");
|
||||||
|
if (!file.good())
|
||||||
|
{
|
||||||
|
throw runtime_error{"Could not read access token: "
|
||||||
|
+ (get_datadir() / "gitea_access_token").string()};
|
||||||
|
}
|
||||||
|
stringstream ss;
|
||||||
|
ss << file.rdbuf();
|
||||||
|
|
||||||
|
return ss.str().substr(0, ss.str().find('\n'));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace FediBlock::files
|
} // namespace FediBlock::files
|
||||||
|
|
|
@ -19,9 +19,13 @@
|
||||||
|
|
||||||
#include "fs-compat.hpp"
|
#include "fs-compat.hpp"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace FediBlock::files
|
namespace FediBlock::files
|
||||||
{
|
{
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
|
||||||
// Creates and returns the temporary directory.
|
// Creates and returns the temporary directory.
|
||||||
[[nodiscard]] fs::path get_tmpdir();
|
[[nodiscard]] fs::path get_tmpdir();
|
||||||
|
|
||||||
|
@ -31,6 +35,9 @@ void remove_tmpdir();
|
||||||
// Returns the data directory and creates it if necessary.
|
// Returns the data directory and creates it if necessary.
|
||||||
[[nodiscard]] fs::path get_datadir();
|
[[nodiscard]] fs::path get_datadir();
|
||||||
|
|
||||||
|
// Read and return access token.
|
||||||
|
[[nodiscard]] string get_access_token();
|
||||||
|
|
||||||
} // namespace FediBlock::files
|
} // namespace FediBlock::files
|
||||||
|
|
||||||
#endif // FEDIBLOCK_BACKEND_FILES_HPP
|
#endif // FEDIBLOCK_BACKEND_FILES_HPP
|
||||||
|
|
Reference in New Issue