Skip to content

Commit 9db9aad

Browse files
committed
Updates comments to extension source files
1 parent 566bb4e commit 9db9aad

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

cli/azd/pkg/extensions/file_source.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/azure/azure-dev/cli/azd/pkg/config"
99
)
1010

11+
// newFileSource creates a new file base registry source.
1112
func newFileSource(name string, path string) (Source, error) {
1213
absolutePath, err := getAbsolutePath(path)
1314
if err != nil {
@@ -22,6 +23,7 @@ func newFileSource(name string, path string) (Source, error) {
2223
return newJsonSource(name, string(registryBytes))
2324
}
2425

26+
// getAbsolutePath converts a relative path to an absolute path.
2527
func getAbsolutePath(filePath string) (string, error) {
2628
// Check if the path is absolute
2729
if filepath.IsAbs(filePath) {

cli/azd/pkg/extensions/json_source.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
)
77

8+
// newJsonSource creates a new JSON base registry source.
89
func newJsonSource(name string, jsonRegistry string) (Source, error) {
910
var registry *Registry
1011
err := json.Unmarshal([]byte(jsonRegistry), &registry)

cli/azd/pkg/extensions/manager.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ func (m *Manager) Initialize() error {
7777
return err
7878
}
7979

80-
// configDir, err := config.GetUserConfigDir()
81-
// if err != nil {
82-
// return fmt.Errorf("failed to get user config directory: %w", err)
83-
// }
84-
85-
//registryCachePath := filepath.Join(configDir, registryCacheFilePath)
86-
//m.registryCache = cache.NewFileCache(registryCachePath, registryCacheDuration, m.loadRegistry)
8780
m.userConfig = userConfig
8881

8982
return nil

cli/azd/pkg/extensions/source.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type registrySource struct {
3333
registry *Registry
3434
}
3535

36-
// NewJsonTemplateSource creates a new template source from a JSON string.
36+
// newRegistrySource creates a new registry source.
3737
func newRegistrySource(name string, registry *Registry) (Source, error) {
3838
if err := validateRegistry(*registry); err != nil {
3939
return nil, fmt.Errorf("failed to validate registry: %w", err)
@@ -49,6 +49,7 @@ func (ts *registrySource) Name() string {
4949
return ts.name
5050
}
5151

52+
// ListTemplates returns a list of templates from the extension source.
5253
func (s *registrySource) ListExtensions(ctx context.Context) ([]*ExtensionMetadata, error) {
5354
for _, extension := range s.registry.Extensions {
5455
extension.Source = s.name
@@ -57,23 +58,25 @@ func (s *registrySource) ListExtensions(ctx context.Context) ([]*ExtensionMetada
5758
return s.registry.Extensions, nil
5859
}
5960

60-
func (s *registrySource) GetExtension(ctx context.Context, name string) (*ExtensionMetadata, error) {
61+
// GetExtension returns an extension by id.
62+
func (s *registrySource) GetExtension(ctx context.Context, id string) (*ExtensionMetadata, error) {
6163
allTemplates, err := s.ListExtensions(ctx)
6264
if err != nil {
6365
return nil, fmt.Errorf("failed listing templates: %w", err)
6466
}
6567

6668
matchingIndex := slices.IndexFunc(allTemplates, func(extension *ExtensionMetadata) bool {
67-
return strings.EqualFold(extension.Id, name)
69+
return strings.EqualFold(extension.Id, id)
6870
})
6971

7072
if matchingIndex == -1 {
71-
return nil, fmt.Errorf("extension with name '%s' was not found, %w", name, ErrExtensionNotFound)
73+
return nil, fmt.Errorf("extension with name '%s' was not found, %w", id, ErrExtensionNotFound)
7274
}
7375

7476
return allTemplates[matchingIndex], nil
7577
}
7678

79+
// validateRegistry validates the registry content and its signature
7780
func validateRegistry(registry Registry) error {
7881
if registry.Signature == "" {
7982
log.Println("Registry signature is empty, skipping signature verification")

cli/azd/pkg/extensions/source_manager.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/azure/azure-dev/cli/azd/pkg/ioc"
1313
)
1414

15+
// SourceKind represents the type of extension source.
1516
type SourceKind string
1617

1718
const (
@@ -28,12 +29,14 @@ var (
2829
ErrSourceTypeInvalid = errors.New("invalid extension source type")
2930
)
3031

32+
// SourceConfig represents the configuration for an extension source.
3133
type SourceConfig struct {
3234
Name string `json:"name,omitempty"`
3335
Type SourceKind `json:"type,omitempty"`
3436
Location string `json:"location,omitempty"`
3537
}
3638

39+
// SourceManager manages extension sources.
3740
type SourceManager struct {
3841
serviceLocator ioc.ServiceLocator
3942
configManager config.UserConfigManager
@@ -52,6 +55,7 @@ func NewSourceManager(
5255
}
5356
}
5457

58+
// Get returns an extension source by name.
5559
func (sm *SourceManager) Get(ctx context.Context, name string) (*SourceConfig, error) {
5660
sources, err := sm.List(ctx)
5761
if err != nil {
@@ -68,6 +72,7 @@ func (sm *SourceManager) Get(ctx context.Context, name string) (*SourceConfig, e
6872

6973
}
7074

75+
// Add adds a new extension source.
7176
func (sm *SourceManager) Add(ctx context.Context, name string, source *SourceConfig) error {
7277
newKey := normalizeKey(name)
7378

@@ -85,6 +90,7 @@ func (sm *SourceManager) Add(ctx context.Context, name string, source *SourceCon
8590
return sm.addInternal(source)
8691
}
8792

93+
// Remove removes an extension source.
8894
func (sm *SourceManager) Remove(ctx context.Context, name string) error {
8995
name = normalizeKey(name)
9096

@@ -117,6 +123,7 @@ func (sm *SourceManager) Remove(ctx context.Context, name string) error {
117123
return nil
118124
}
119125

126+
// List returns a list of extension sources.
120127
func (sm *SourceManager) List(ctx context.Context) ([]*SourceConfig, error) {
121128
config, err := sm.configManager.Load()
122129
if err != nil {
@@ -184,6 +191,7 @@ func (sm *SourceManager) CreateSource(ctx context.Context, config *SourceConfig)
184191
return source, nil
185192
}
186193

194+
// addInternal adds a new extension source to the user configuration.
187195
func (sm *SourceManager) addInternal(source *SourceConfig) error {
188196
config, err := sm.configManager.Load()
189197
if err != nil {
@@ -204,6 +212,7 @@ func (sm *SourceManager) addInternal(source *SourceConfig) error {
204212
return nil
205213
}
206214

215+
// normalizeKey normalizes a key for use in the configuration.
207216
func normalizeKey(key string) string {
208217
key = strings.ToLower(key)
209218
key = strings.ReplaceAll(key, " ", "-")

cli/azd/pkg/extensions/url_source.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
1111
)
1212

13+
// newUrlSource creates a new URL extension source.
1314
func newUrlSource(ctx context.Context, name string, url string, transport policy.Transporter) (Source, error) {
1415
pipeline := runtime.NewPipeline("azd-extensions", "1.0.0", runtime.PipelineOptions{}, &policy.ClientOptions{
1516
Transport: transport,

0 commit comments

Comments
 (0)