Files
moloapp/src/google/ops/api_state.h
T

32 lines
1.0 KiB
C++
Raw Normal View History

#pragma once
// Recognises "the API is not enabled on this project" so callers can say so
// loudly instead of showing a bare 403. Enabling is a human decision: this
// class only reports.
#include <optional>
#include <string>
#include "google/errors.h"
namespace molo::google::ops {
struct DisabledApi {
std::string service; // e.g. iam.googleapis.com ("" when Google named none)
std::string activation_url; // console page where a human enables it
// "API NOT ENABLED: iam.googleapis.com, enable it at https://..."
std::string loud() const;
};
class ApiState {
public:
// Set when the error is Google's "has not been used in project ... or it is
// disabled" / SERVICE_DISABLED answer (HTTP 403).
static std::optional<DisabledApi> disabled(const GoogleError& error,
const std::string& project);
// "services/serviceusage.googleapis.com" style segment of the API host in a text.
static std::string service_in(const std::string& text);
};
} // namespace molo::google::ops