This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
/
service_config.go
116 lines (95 loc) · 2.77 KB
/
service_config.go
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package singleprocess
import (
"context"
empty "google.golang.org/protobuf/types/known/emptypb"
"github.com/hashicorp/go-hclog"
pb "github.com/hashicorp/waypoint/pkg/server/gen"
"github.com/hashicorp/waypoint/pkg/server/hcerr"
"github.com/hashicorp/waypoint/pkg/server/ptypes"
)
func (s *Service) SetConfig(
ctx context.Context,
req *pb.ConfigSetRequest,
) (*pb.ConfigSetResponse, error) {
if err := ptypes.ValidateSetConfigRequest(req); err != nil {
return nil, err
}
if err := s.state(ctx).ConfigSet(ctx, req.Variables...); err != nil {
return nil, hcerr.Externalize(hclog.FromContext(ctx), err, "failed to set config")
}
return &pb.ConfigSetResponse{}, nil
}
func (s *Service) DeleteConfig(
ctx context.Context,
req *pb.ConfigDeleteRequest,
) (*pb.ConfigDeleteResponse, error) {
if err := ptypes.ValidateDeleteConfigRequest(req); err != nil {
return nil, err
}
if err := s.state(ctx).ConfigDelete(ctx, req.Variables...); err != nil {
return nil, hcerr.Externalize(hclog.FromContext(ctx), err, "failed to delete config")
}
return &pb.ConfigDeleteResponse{}, nil
}
func (s *Service) GetConfig(
ctx context.Context,
req *pb.ConfigGetRequest,
) (*pb.ConfigGetResponse, error) {
if err := ptypes.ValidateGetConfigRequest(req); err != nil {
return nil, err
}
vars, err := s.state(ctx).ConfigGet(ctx, req)
if err != nil {
return nil, hcerr.Externalize(hclog.FromContext(ctx), err, "failed to get config")
}
return &pb.ConfigGetResponse{Variables: vars}, nil
}
func (s *Service) SetConfigSource(
ctx context.Context,
req *pb.SetConfigSourceRequest,
) (*empty.Empty, error) {
if err := ptypes.ValidateSetConfigSourceRequest(req); err != nil {
return nil, err
}
if err := s.state(ctx).ConfigSourceSet(ctx, req.ConfigSource); err != nil {
return nil, hcerr.Externalize(
hclog.FromContext(ctx),
err,
"failed to set config source",
)
}
return &empty.Empty{}, nil
}
func (s *Service) DeleteConfigSource(
ctx context.Context,
req *pb.DeleteConfigSourceRequest,
) (*empty.Empty, error) {
if err := ptypes.ValidateDeleteConfigSourceRequest(req); err != nil {
return nil, err
}
if err := s.state(ctx).ConfigSourceDelete(ctx, req.ConfigSource); err != nil {
return nil, hcerr.Externalize(
hclog.FromContext(ctx),
err,
"failed to delete config source",
)
}
return &empty.Empty{}, nil
}
func (s *Service) GetConfigSource(
ctx context.Context,
req *pb.GetConfigSourceRequest,
) (*pb.GetConfigSourceResponse, error) {
if err := ptypes.ValidateGetConfigSourceRequest(req); err != nil {
return nil, err
}
vars, err := s.state(ctx).ConfigSourceGet(ctx, req)
if err != nil {
return nil, hcerr.Externalize(
hclog.FromContext(ctx),
err,
"failed to get config source",
)
}
return &pb.GetConfigSourceResponse{ConfigSources: vars}, nil
}