7
7
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
8
8
)
9
9
10
+ // NewWrappedProviderServer returns a new ProviderServer that wraps the old one.
11
+ // This is used to add additional metadata to the User-Agent header and context.
10
12
func NewWrappedProviderServer (old func () tfprotov6.ProviderServer ) func () tfprotov6.ProviderServer {
11
13
return func () tfprotov6.ProviderServer {
12
14
return & WrappedProviderServer {
@@ -44,57 +46,101 @@ func (s *WrappedProviderServer) StopProvider(ctx context.Context, req *tfprotov6
44
46
}
45
47
46
48
func (s * WrappedProviderServer ) ValidateResourceConfig (ctx context.Context , req * tfprotov6.ValidateResourceConfigRequest ) (* tfprotov6.ValidateResourceConfigResponse , error ) {
47
- ctx = context .WithValue (ctx , config .ContextKeyTFSrc , req .TypeName )
49
+ ctx = config .AddUserAgentExtra (ctx , config.UserAgentExtra {
50
+ Type : "Resource" ,
51
+ Name : req .TypeName ,
52
+ Operation : "ValidateResourceConfig" ,
53
+ })
48
54
return s .OldServer .ValidateResourceConfig (ctx , req )
49
55
}
50
56
51
57
func (s * WrappedProviderServer ) UpgradeResourceState (ctx context.Context , req * tfprotov6.UpgradeResourceStateRequest ) (* tfprotov6.UpgradeResourceStateResponse , error ) {
52
- ctx = context .WithValue (ctx , config .ContextKeyTFSrc , "upgrade." + req .TypeName )
58
+ ctx = config .AddUserAgentExtra (ctx , config.UserAgentExtra {
59
+ Type : "Resource" ,
60
+ Name : req .TypeName ,
61
+ Operation : "UpgradeResourceState" ,
62
+ })
53
63
return s .OldServer .UpgradeResourceState (ctx , req )
54
64
}
55
65
56
66
func (s * WrappedProviderServer ) ReadResource (ctx context.Context , req * tfprotov6.ReadResourceRequest ) (* tfprotov6.ReadResourceResponse , error ) {
57
- ctx = context .WithValue (ctx , config .ContextKeyTFSrc , req .TypeName )
67
+ ctx = config .AddUserAgentExtra (ctx , config.UserAgentExtra {
68
+ Type : "Resource" ,
69
+ Name : req .TypeName ,
70
+ Operation : "ReadResource" ,
71
+ })
58
72
return s .OldServer .ReadResource (ctx , req )
59
73
}
60
74
61
75
func (s * WrappedProviderServer ) PlanResourceChange (ctx context.Context , req * tfprotov6.PlanResourceChangeRequest ) (* tfprotov6.PlanResourceChangeResponse , error ) {
62
- ctx = context .WithValue (ctx , config .ContextKeyTFSrc , req .TypeName )
76
+ ctx = config .AddUserAgentExtra (ctx , config.UserAgentExtra {
77
+ Type : "Resource" ,
78
+ Name : req .TypeName ,
79
+ Operation : "PlanResourceChange" ,
80
+ })
63
81
return s .OldServer .PlanResourceChange (ctx , req )
64
82
}
65
83
66
84
func (s * WrappedProviderServer ) ApplyResourceChange (ctx context.Context , req * tfprotov6.ApplyResourceChangeRequest ) (* tfprotov6.ApplyResourceChangeResponse , error ) {
67
- ctx = context .WithValue (ctx , config .ContextKeyTFSrc , req .TypeName )
85
+ ctx = config .AddUserAgentExtra (ctx , config.UserAgentExtra {
86
+ Type : "Resource" ,
87
+ Name : req .TypeName ,
88
+ Operation : "ApplyResourceChange" ,
89
+ })
68
90
return s .OldServer .ApplyResourceChange (ctx , req )
69
91
}
70
92
71
93
func (s * WrappedProviderServer ) ImportResourceState (ctx context.Context , req * tfprotov6.ImportResourceStateRequest ) (* tfprotov6.ImportResourceStateResponse , error ) {
72
- ctx = context .WithValue (ctx , config .ContextKeyTFSrc , "import." + req .TypeName )
94
+ ctx = config .AddUserAgentExtra (ctx , config.UserAgentExtra {
95
+ Type : "Resource" ,
96
+ Name : req .TypeName ,
97
+ Operation : "ImportResourceState" ,
98
+ })
73
99
return s .OldServer .ImportResourceState (ctx , req )
74
100
}
75
101
76
102
func (s * WrappedProviderServer ) MoveResourceState (ctx context.Context , req * tfprotov6.MoveResourceStateRequest ) (* tfprotov6.MoveResourceStateResponse , error ) {
77
- ctx = context .WithValue (ctx , config .ContextKeyTFSrc , "move." + req .TargetTypeName )
103
+ ctx = config .AddUserAgentExtra (ctx , config.UserAgentExtra {
104
+ Type : "Resource" ,
105
+ Name : req .TargetTypeName ,
106
+ Operation : "MoveResourceState" ,
107
+ })
78
108
return s .OldServer .MoveResourceState (ctx , req )
79
109
}
80
110
81
111
func (s * WrappedProviderServer ) UpgradeResourceIdentity (ctx context.Context , req * tfprotov6.UpgradeResourceIdentityRequest ) (* tfprotov6.UpgradeResourceIdentityResponse , error ) {
82
- ctx = context .WithValue (ctx , config .ContextKeyTFSrc , req .TypeName )
112
+ ctx = config .AddUserAgentExtra (ctx , config.UserAgentExtra {
113
+ Type : "Resource" ,
114
+ Name : req .TypeName ,
115
+ Operation : "UpgradeResourceIdentity" ,
116
+ })
83
117
return s .OldServer .UpgradeResourceIdentity (ctx , req )
84
118
}
85
119
86
120
func (s * WrappedProviderServer ) ValidateDataResourceConfig (ctx context.Context , req * tfprotov6.ValidateDataResourceConfigRequest ) (* tfprotov6.ValidateDataResourceConfigResponse , error ) {
87
- ctx = context .WithValue (ctx , config .ContextKeyTFSrc , "data." + req .TypeName )
121
+ ctx = config .AddUserAgentExtra (ctx , config.UserAgentExtra {
122
+ Type : "Datasource" ,
123
+ Name : req .TypeName ,
124
+ Operation : "ValidateDataResourceConfig" ,
125
+ })
88
126
return s .OldServer .ValidateDataResourceConfig (ctx , req )
89
127
}
90
128
91
129
func (s * WrappedProviderServer ) ReadDataSource (ctx context.Context , req * tfprotov6.ReadDataSourceRequest ) (* tfprotov6.ReadDataSourceResponse , error ) {
92
- ctx = context .WithValue (ctx , config .ContextKeyTFSrc , "data." + req .TypeName )
130
+ ctx = config .AddUserAgentExtra (ctx , config.UserAgentExtra {
131
+ Type : "Datasource" ,
132
+ Name : req .TypeName ,
133
+ Operation : "ReadDataSource" ,
134
+ })
93
135
return s .OldServer .ReadDataSource (ctx , req )
94
136
}
95
137
96
138
func (s * WrappedProviderServer ) CallFunction (ctx context.Context , req * tfprotov6.CallFunctionRequest ) (* tfprotov6.CallFunctionResponse , error ) {
97
- ctx = context .WithValue (ctx , config .ContextKeyTFSrc , "func." + req .Name )
139
+ ctx = config .AddUserAgentExtra (ctx , config.UserAgentExtra {
140
+ Type : "Function" ,
141
+ Name : req .Name ,
142
+ Operation : "CallFunction" ,
143
+ })
98
144
return s .OldServer .CallFunction (ctx , req )
99
145
}
100
146
@@ -103,21 +149,37 @@ func (s *WrappedProviderServer) GetFunctions(ctx context.Context, req *tfprotov6
103
149
}
104
150
105
151
func (s * WrappedProviderServer ) ValidateEphemeralResourceConfig (ctx context.Context , req * tfprotov6.ValidateEphemeralResourceConfigRequest ) (* tfprotov6.ValidateEphemeralResourceConfigResponse , error ) {
106
- ctx = context .WithValue (ctx , config .ContextKeyTFSrc , req .TypeName )
152
+ ctx = config .AddUserAgentExtra (ctx , config.UserAgentExtra {
153
+ Type : "Ephemeral" ,
154
+ Name : req .TypeName ,
155
+ Operation : "ValidateEphemeralResourceConfig" ,
156
+ })
107
157
return s .OldServer .ValidateEphemeralResourceConfig (ctx , req )
108
158
}
109
159
110
160
func (s * WrappedProviderServer ) OpenEphemeralResource (ctx context.Context , req * tfprotov6.OpenEphemeralResourceRequest ) (* tfprotov6.OpenEphemeralResourceResponse , error ) {
111
- ctx = context .WithValue (ctx , config .ContextKeyTFSrc , req .TypeName )
161
+ ctx = config .AddUserAgentExtra (ctx , config.UserAgentExtra {
162
+ Type : "Ephemeral" ,
163
+ Name : req .TypeName ,
164
+ Operation : "OpenEphemeralResource" ,
165
+ })
112
166
return s .OldServer .OpenEphemeralResource (ctx , req )
113
167
}
114
168
115
169
func (s * WrappedProviderServer ) RenewEphemeralResource (ctx context.Context , req * tfprotov6.RenewEphemeralResourceRequest ) (* tfprotov6.RenewEphemeralResourceResponse , error ) {
116
- ctx = context .WithValue (ctx , config .ContextKeyTFSrc , req .TypeName )
170
+ ctx = config .AddUserAgentExtra (ctx , config.UserAgentExtra {
171
+ Type : "Ephemeral" ,
172
+ Name : req .TypeName ,
173
+ Operation : "RenewEphemeralResource" ,
174
+ })
117
175
return s .OldServer .RenewEphemeralResource (ctx , req )
118
176
}
119
177
120
178
func (s * WrappedProviderServer ) CloseEphemeralResource (ctx context.Context , req * tfprotov6.CloseEphemeralResourceRequest ) (* tfprotov6.CloseEphemeralResourceResponse , error ) {
121
- ctx = context .WithValue (ctx , config .ContextKeyTFSrc , req .TypeName )
179
+ ctx = config .AddUserAgentExtra (ctx , config.UserAgentExtra {
180
+ Type : "Ephemeral" ,
181
+ Name : req .TypeName ,
182
+ Operation : "CloseEphemeralResource" ,
183
+ })
122
184
return s .OldServer .CloseEphemeralResource (ctx , req )
123
185
}
0 commit comments