File: operations.go

package info (click to toggle)
gitlab-ci-multi-runner 14.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 31,248 kB
  • sloc: sh: 1,694; makefile: 384; asm: 79; ruby: 68
file content (52 lines) | stat: -rw-r--r-- 1,456 bytes parent folder | download
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
package secret_engines

import (
	"fmt"

	"gitlab.com/gitlab-org/gitlab-runner/helpers/vault"
)

type OperationType string

const (
	getOperation    OperationType = "get"
	putOperation    OperationType = "put"
	deleteOperation OperationType = "delete"
)

type OperationNotSupportedError struct {
	secretEngineName string
	operationType    OperationType
}

func NewUnsupportedGetOperationErr(engine vault.SecretEngine) *OperationNotSupportedError {
	return newErrOperationNotSupported(engine, getOperation)
}

func NewUnsupportedPutOperationErr(engine vault.SecretEngine) *OperationNotSupportedError {
	return newErrOperationNotSupported(engine, putOperation)
}

func NewUnsupportedDeleteOperationErr(engine vault.SecretEngine) *OperationNotSupportedError {
	return newErrOperationNotSupported(engine, deleteOperation)
}

func newErrOperationNotSupported(engine vault.SecretEngine, operationType OperationType) *OperationNotSupportedError {
	return &OperationNotSupportedError{
		secretEngineName: engine.EngineName(),
		operationType:    operationType,
	}
}

func (e *OperationNotSupportedError) Error() string {
	return fmt.Sprintf("operation %q for secret engine %q is not supported", e.operationType, e.secretEngineName)
}

func (e *OperationNotSupportedError) Is(err error) bool {
	eerr, ok := err.(*OperationNotSupportedError)
	if !ok {
		return false
	}

	return eerr.secretEngineName == e.secretEngineName && eerr.operationType == e.operationType
}