blob: 15a8babff4d4f7774d4b7b24ca1011844b4888ee [file] [log] [blame]
khenaidooab1f7bd2019-11-14 14:00:27 -05001// Copyright 2016 The etcd Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package client
16
17import (
18 "regexp"
19)
20
21var (
22 roleNotFoundRegExp *regexp.Regexp
23 userNotFoundRegExp *regexp.Regexp
24)
25
26func init() {
27 roleNotFoundRegExp = regexp.MustCompile("auth: Role .* does not exist.")
28 userNotFoundRegExp = regexp.MustCompile("auth: User .* does not exist.")
29}
30
31// IsKeyNotFound returns true if the error code is ErrorCodeKeyNotFound.
32func IsKeyNotFound(err error) bool {
33 if cErr, ok := err.(Error); ok {
34 return cErr.Code == ErrorCodeKeyNotFound
35 }
36 return false
37}
38
39// IsRoleNotFound returns true if the error means role not found of v2 API.
40func IsRoleNotFound(err error) bool {
41 if ae, ok := err.(authError); ok {
42 return roleNotFoundRegExp.MatchString(ae.Message)
43 }
44 return false
45}
46
47// IsUserNotFound returns true if the error means user not found of v2 API.
48func IsUserNotFound(err error) bool {
49 if ae, ok := err.(authError); ok {
50 return userNotFoundRegExp.MatchString(ae.Message)
51 }
52 return false
53}