Skip to content

Commit 37d5a21

Browse files
committed
Fix the missing OAuth metadata from the registry
Signed-off-by: Radoslav Dimitrov <[email protected]>
1 parent 44698d5 commit 37d5a21

File tree

1 file changed

+99
-1
lines changed

1 file changed

+99
-1
lines changed

pkg/types/registry.go

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,38 @@ func (r *RegistryEntry) UnmarshalYAML(unmarshal func(interface{}) error) error {
192192
}
193193
}
194194

195-
// Unmarshal extended fields (examples, license) separately
195+
// Unmarshal extended fields (examples, license, oauth, headers, env_vars) separately
196196
type extendedFields struct {
197197
Examples []Example `yaml:"examples,omitempty"`
198198
License string `yaml:"license,omitempty"`
199+
// OAuth configuration in simplified YAML format
200+
OAuth *struct {
201+
Issuer string `yaml:"issuer,omitempty"`
202+
AuthorizeURL string `yaml:"authorize_url,omitempty"`
203+
TokenURL string `yaml:"token_url,omitempty"`
204+
ClientID string `yaml:"client_id,omitempty"`
205+
Scopes []string `yaml:"scopes,omitempty"`
206+
UsePKCE *bool `yaml:"use_pkce,omitempty"`
207+
OAuthParams map[string]string `yaml:"oauth_params,omitempty"`
208+
CallbackPort int `yaml:"callback_port,omitempty"`
209+
} `yaml:"oauth,omitempty"`
210+
// Headers for remote server authentication
211+
Headers []struct {
212+
Name string `yaml:"name"`
213+
Description string `yaml:"description"`
214+
Required bool `yaml:"required"`
215+
Default string `yaml:"default,omitempty"`
216+
Secret bool `yaml:"secret,omitempty"`
217+
Choices []string `yaml:"choices,omitempty"`
218+
} `yaml:"headers,omitempty"`
219+
// Environment variables for server configuration
220+
EnvVars []struct {
221+
Name string `yaml:"name"`
222+
Description string `yaml:"description"`
223+
Required bool `yaml:"required"`
224+
Default string `yaml:"default,omitempty"`
225+
Secret bool `yaml:"secret,omitempty"`
226+
} `yaml:"env_vars,omitempty"`
199227
}
200228
var extended extendedFields
201229
if err := unmarshal(&extended); err != nil {
@@ -204,5 +232,75 @@ func (r *RegistryEntry) UnmarshalYAML(unmarshal func(interface{}) error) error {
204232
r.Examples = extended.Examples
205233
r.License = extended.License
206234

235+
// Handle OAuth configuration transformation for remote servers
236+
if r.RemoteServerMetadata != nil && extended.OAuth != nil {
237+
r.RemoteServerMetadata.OAuthConfig = &registry.OAuthConfig{
238+
Issuer: extended.OAuth.Issuer,
239+
AuthorizeURL: extended.OAuth.AuthorizeURL,
240+
TokenURL: extended.OAuth.TokenURL,
241+
ClientID: extended.OAuth.ClientID,
242+
Scopes: extended.OAuth.Scopes,
243+
OAuthParams: extended.OAuth.OAuthParams,
244+
CallbackPort: extended.OAuth.CallbackPort,
245+
}
246+
// Set UsePKCE default or explicit value
247+
if extended.OAuth.UsePKCE != nil {
248+
r.RemoteServerMetadata.OAuthConfig.UsePKCE = *extended.OAuth.UsePKCE
249+
} else {
250+
r.RemoteServerMetadata.OAuthConfig.UsePKCE = true // default to true
251+
}
252+
}
253+
254+
// Handle Headers transformation for remote servers
255+
if r.RemoteServerMetadata != nil && len(extended.Headers) > 0 {
256+
r.RemoteServerMetadata.Headers = make([]*registry.Header, len(extended.Headers))
257+
for i, h := range extended.Headers {
258+
r.RemoteServerMetadata.Headers[i] = &registry.Header{
259+
Name: h.Name,
260+
Description: h.Description,
261+
Required: h.Required,
262+
Default: h.Default,
263+
Secret: h.Secret,
264+
Choices: h.Choices,
265+
}
266+
}
267+
}
268+
269+
// Handle EnvVars transformation for remote servers
270+
if r.RemoteServerMetadata != nil && len(extended.EnvVars) > 0 {
271+
r.RemoteServerMetadata.EnvVars = make([]*registry.EnvVar, len(extended.EnvVars))
272+
for i, e := range extended.EnvVars {
273+
r.RemoteServerMetadata.EnvVars[i] = &registry.EnvVar{
274+
Name: e.Name,
275+
Description: e.Description,
276+
Required: e.Required,
277+
Default: e.Default,
278+
Secret: e.Secret,
279+
}
280+
}
281+
}
282+
283+
// Handle custom metadata fields for remote servers (homepage, license, author, etc.)
284+
if r.RemoteServerMetadata != nil {
285+
// Extract custom fields from the raw YAML that aren't part of the standard schema
286+
customFields := make(map[string]interface{})
287+
288+
// Check for common custom fields
289+
if val, exists := raw["homepage"]; exists {
290+
customFields["homepage"] = val
291+
}
292+
if val, exists := raw["license"]; exists {
293+
customFields["license"] = val
294+
}
295+
if val, exists := raw["author"]; exists {
296+
customFields["author"] = val
297+
}
298+
299+
// Set custom metadata if we found any custom fields
300+
if len(customFields) > 0 {
301+
r.RemoteServerMetadata.CustomMetadata = customFields
302+
}
303+
}
304+
207305
return nil
208306
}

0 commit comments

Comments
 (0)