aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/tvmauth/client/client_status.h
blob: 8805d471c83d7d36a7798a2bdaba1f6278042782 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#pragma once

#include <util/generic/string.h>
#include <util/string/builder.h>

namespace NTvmAuth {
    class TClientStatus {
    public:
        enum ECode {
            Ok,
            Warning,
            Error,
            IncompleteTicketsSet, 
        };

        TClientStatus(ECode state, TString&& lastError)
            : Code_(state)
            , LastError_(std::move(lastError))
        {
        }

        TClientStatus() = default;
        TClientStatus(const TClientStatus&) = default;
        TClientStatus(TClientStatus&&) = default;

        TClientStatus& operator=(const TClientStatus&) = default;
        TClientStatus& operator=(TClientStatus&&) = default;

        ECode GetCode() const {
            return Code_;
        }

        const TString& GetLastError() const {
            return LastError_;
        }

        TString CreateJugglerMessage() const {
            return TStringBuilder() << GetJugglerCode() << ";TvmClient: " << LastError_ << "\n"; 
        }

    private:
        int32_t GetJugglerCode() const { 
            switch (Code_) { 
                case ECode::Ok: 
                    return 0; // OK juggler check state
                case ECode::Warning: 
                case ECode::IncompleteTicketsSet: 
                    return 1; // WARN juggler check state
                case ECode::Error: 
                    return 2; // CRIT juggler check state
            } 
            return 2; // This should not happen, so set check state as CRIT. 
        } 
 
        ECode Code_ = Ok;
        TString LastError_;
    };

    static inline bool operator==(const TClientStatus& l, const TClientStatus& r) noexcept {
        return l.GetCode() == r.GetCode() && l.GetLastError() == r.GetLastError();
    }

    static inline bool operator==(const TClientStatus& l, const TClientStatus::ECode r) noexcept {
        return l.GetCode() == r;
    }

    static inline bool operator==(const TClientStatus::ECode l, const TClientStatus& r) noexcept {
        return r.GetCode() == l;
    }

    static inline bool operator!=(const TClientStatus& l, const TClientStatus& r) noexcept {
        return !(l == r);
    }

    static inline bool operator!=(const TClientStatus& l, const TClientStatus::ECode r) noexcept {
        return !(l == r);
    }

    static inline bool operator!=(const TClientStatus::ECode l, const TClientStatus& r) noexcept {
        return !(l == r);
    }
}