-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support extensions; task kinds; multi-container task pods for providers.
Signed-off-by: Jeff Ortel <jortel@redhat.com>
- Loading branch information
Showing
45 changed files
with
6,941 additions
and
728 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package addon | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/konveyor/tackle2-hub/api" | ||
"github.com/konveyor/tackle2-hub/task" | ||
) | ||
|
||
var ( | ||
EnvRegex = regexp.MustCompile(`(\$\()([^)]+)(\))`) | ||
) | ||
|
||
// EnvInjector inject key into extension metadata. | ||
type EnvInjector struct { | ||
env map[string]string | ||
dict map[string]string | ||
} | ||
|
||
// Inject inject into extension metadata. | ||
func (r *EnvInjector) Inject(extension *api.Extension) { | ||
r.buildEnv(extension) | ||
mp := make(map[string]any) | ||
b, _ := json.Marshal(extension.Metadata) | ||
_ = json.Unmarshal(b, &mp) | ||
mp = r.inject(mp).(map[string]any) | ||
extension.Metadata = mp | ||
} | ||
|
||
// buildEnv builds the extension `env`. | ||
func (r *EnvInjector) buildEnv(extension *api.Extension) { | ||
r.env = make(map[string]string) | ||
for _, env := range extension.Container.Env { | ||
key := task.ExtEnv(extension.Name, env.Name) | ||
r.env[env.Name] = os.Getenv(key) | ||
} | ||
} | ||
|
||
// inject replaces both `dict` keys and `env` environment | ||
// variables referenced in metadata. | ||
func (r *EnvInjector) inject(in any) (out any) { | ||
switch node := in.(type) { | ||
case map[string]any: | ||
for k, v := range node { | ||
node[k] = r.inject(v) | ||
} | ||
out = node | ||
case []any: | ||
var injected []any | ||
for _, n := range node { | ||
injected = append( | ||
injected, | ||
r.inject(n)) | ||
} | ||
out = injected | ||
case string: | ||
for { | ||
match := EnvRegex.FindStringSubmatch(node) | ||
if len(match) < 3 { | ||
break | ||
} | ||
node = strings.Replace( | ||
node, | ||
match[0], | ||
r.env[match[2]], | ||
-1) | ||
} | ||
out = node | ||
default: | ||
out = node | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.