-
Notifications
You must be signed in to change notification settings - Fork 54
/
plugins.go
47 lines (44 loc) · 1.63 KB
/
plugins.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
//
// Copyright (c) 2019-2021 Red Hat, Inc.
// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/
//
// SPDX-License-Identifier: EPL-2.0
//
// Contributors:
// Red Hat, Inc. - initial API and implementation
//
package annotate
import (
dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/api/v2/pkg/attributes"
)
// AddSourceAttributesForTemplate adds an attribute 'controller.devfile.io/imported-by=sourceID' to all elements of
// a plugin that support attributes.
func AddSourceAttributesForTemplate(sourceID string, template *dw.DevWorkspaceTemplateSpec) {
for idx, component := range template.Components {
if component.Attributes == nil {
template.Components[idx].Attributes = attributes.Attributes{}
}
template.Components[idx].Attributes.PutString(PluginSourceAttribute, sourceID)
}
for idx, command := range template.Commands {
if command.Attributes == nil {
template.Commands[idx].Attributes = attributes.Attributes{}
}
template.Commands[idx].Attributes.PutString(PluginSourceAttribute, sourceID)
}
for idx, project := range template.Projects {
if project.Attributes == nil {
template.Projects[idx].Attributes = attributes.Attributes{}
}
template.Projects[idx].Attributes.PutString(PluginSourceAttribute, sourceID)
}
for idx, project := range template.StarterProjects {
if project.Attributes == nil {
template.StarterProjects[idx].Attributes = attributes.Attributes{}
}
template.StarterProjects[idx].Attributes.PutString(PluginSourceAttribute, sourceID)
}
}