Skip to content

Commit

Permalink
rename Trust Engine to System Trust
Browse files Browse the repository at this point in the history
  • Loading branch information
jliempt committed Dec 17, 2024
1 parent dfd947b commit 66d4680
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 321 deletions.
10 changes: 5 additions & 5 deletions cmd/piper.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type GeneralConfigOptions struct {
VaultServerURL string
VaultNamespace string
VaultPath string
TrustEngineToken string
SystemTrustToken string
HookConfig HookConfiguration
MetaDataResolver func() map[string]config.StepData
GCPJsonKeyFilePath string
Expand All @@ -57,7 +57,7 @@ type HookConfiguration struct {
SplunkConfig SplunkConfiguration `json:"splunk,omitempty"`
PendoConfig PendoConfiguration `json:"pendo,omitempty"`
OIDCConfig OIDCConfiguration `json:"oidc,omitempty"`
TrustEngineConfig TrustEngineConfiguration `json:"trustengine,omitempty"`
SystemTrustConfig SystemTrustConfiguration `json:"systemtrust,omitempty"`
}

type GCPPubSubConfiguration struct {
Expand Down Expand Up @@ -93,7 +93,7 @@ type OIDCConfiguration struct {
RoleID string `json:",roleID,omitempty"`
}

type TrustEngineConfiguration struct {
type SystemTrustConfiguration struct {
ServerURL string `json:"baseURL,omitempty"`
TokenEndPoint string `json:"tokenEndPoint,omitempty"`
TokenQueryParamName string `json:"tokenQueryParamName,omitempty"`
Expand Down Expand Up @@ -386,8 +386,8 @@ func PrepareConfig(cmd *cobra.Command, metadata *config.StepData, stepName strin
}
myConfig.SetVaultCredentials(GeneralConfig.VaultRoleID, GeneralConfig.VaultRoleSecretID, GeneralConfig.VaultToken)

GeneralConfig.TrustEngineToken = os.Getenv("PIPER_trustEngineToken")
myConfig.SetTrustEngineToken(GeneralConfig.TrustEngineToken)
GeneralConfig.SystemTrustToken = os.Getenv("PIPER_systemTrustToken")
myConfig.SetSystemTrustToken(GeneralConfig.SystemTrustToken)

if len(GeneralConfig.StepConfigJSON) != 0 {
// ignore config & defaults in favor of passed stepConfigJSON
Expand Down
4 changes: 2 additions & 2 deletions cmd/sonarExecuteScan_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"regexp"
"strings"

"github.com/SAP/jenkins-library/pkg/trustengine"
"github.com/SAP/jenkins-library/pkg/systemtrust"

Check failure on line 14 in pkg/config/config.go

View workflow job for this annotation

GitHub Actions / Build

no required module provides package github.com/SAP/jenkins-library/pkg/systemtrust; to add it:

Check failure on line 14 in pkg/config/config.go

View workflow job for this annotation

GitHub Actions / generate

no required module provides package github.com/SAP/jenkins-library/pkg/systemtrust; to add it:

Check failure on line 14 in pkg/config/config.go

View workflow job for this annotation

GitHub Actions / lint

no required module provides package github.com/SAP/jenkins-library/pkg/systemtrust; to add it:

Check failure on line 14 in pkg/config/config.go

View workflow job for this annotation

GitHub Actions / unit

no required module provides package github.com/SAP/jenkins-library/pkg/systemtrust; to add it:

piperhttp "github.com/SAP/jenkins-library/pkg/http"
"github.com/SAP/jenkins-library/pkg/log"
Expand All @@ -33,7 +33,7 @@ type Config struct {
accessTokens map[string]string
openFile func(s string, t map[string]string) (io.ReadCloser, error)
vaultCredentials VaultCredentials
trustEngineConfiguration trustengine.Configuration
systemTrustConfiguration systemtrust.Configuration
}

// StepConfig defines the structure for merged step configuration
Expand Down Expand Up @@ -295,12 +295,12 @@ func (c *Config) GetStepConfig(flagValues map[string]interface{}, paramJSON stri
}

// hooks need to have been loaded from the defaults before the server URL is known
err = c.setTrustEngineConfiguration(stepConfig.HookConfig)
err = c.setSystemTrustConfiguration(stepConfig.HookConfig)
if err != nil {
log.Entry().WithError(err).Debug("Trust Engine lookup skipped due to missing or incorrect configuration")
log.Entry().WithError(err).Debug("System Trust lookup skipped due to missing or incorrect configuration")
} else {
trustengineClient := trustengine.PrepareClient(&piperhttp.Client{}, c.trustEngineConfiguration)
resolveAllTrustEngineReferences(&stepConfig, append(parameters, ReportingParameters.Parameters...), c.trustEngineConfiguration, trustengineClient)
systemtrustClient := systemtrust.PrepareClient(&piperhttp.Client{}, c.systemTrustConfiguration)
resolveAllSystemTrustReferences(&stepConfig, append(parameters, ReportingParameters.Parameters...), c.systemTrustConfiguration, systemtrustClient)
}

// finally do the condition evaluation post processing
Expand Down
33 changes: 17 additions & 16 deletions pkg/config/trustengine_test.go → pkg/config/systemtrust_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ package config

import (
"fmt"
piperhttp "github.com/SAP/jenkins-library/pkg/http"
"github.com/SAP/jenkins-library/pkg/trustengine"
"github.com/jarcoal/httpmock"
"net/http"
"testing"

piperhttp "github.com/SAP/jenkins-library/pkg/http"
"github.com/SAP/jenkins-library/pkg/systemtrust"
"github.com/jarcoal/httpmock"

"github.com/stretchr/testify/assert"
)

const secretName = "sonar"
const secretNameInTrustEngine = "sonarTrustengineSecretName"
const secretNameInSystemTrust = "sonarSystemtrustSecretName"
const testServerURL = "https://www.project-piper.io"
const testTokenEndPoint = "tokens"
const testTokenQueryParamName = "systems"
Expand All @@ -24,14 +25,14 @@ const mockSonarToken = "mockSonarToken"
var testFullURL = fmt.Sprintf("%s/%s?%s=", testServerURL, testTokenEndPoint, testTokenQueryParamName)
var mockSingleTokenResponse = fmt.Sprintf("{\"sonar\": \"%s\"}", mockSonarToken)

func TestTrustEngineConfig(t *testing.T) {
func TestSystemTrustConfig(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder(http.MethodGet, testFullURL+"sonar", httpmock.NewStringResponder(200, mockSingleTokenResponse))

stepParams := []StepParameters{createStepParam(secretName, RefTypeTrustengineSecret, secretNameInTrustEngine, secretName)}

var trustEngineConfiguration = trustengine.Configuration{
stepParams := []StepParameters{createStepParam(secretName, RefTypeSystemtrustSecret, secretNameInSystemTrust, secretName)}
systemtrust
var systemTrustConfiguration = systemtrust.Configuration{
Token: "testToken",
ServerURL: testServerURL,
TokenEndPoint: testTokenEndPoint,
Expand All @@ -40,33 +41,33 @@ func TestTrustEngineConfig(t *testing.T) {
client := &piperhttp.Client{}
client.SetOptions(piperhttp.ClientOptions{MaxRetries: -1, UseDefaultTransport: true})

t.Run("Load secret from Trust Engine - secret not set yet by Vault or config.yml", func(t *testing.T) {
t.Run("Load secret from System Trust - secret not set yet by Vault or config.yml", func(t *testing.T) {
stepConfig := &StepConfig{Config: map[string]interface{}{
secretName: "",
}}

resolveAllTrustEngineReferences(stepConfig, stepParams, trustEngineConfiguration, client)
resolveAllSystemTrustReferences(stepConfig, stepParams, systemTrustConfiguration, client)
assert.Equal(t, mockSonarToken, stepConfig.Config[secretName])
})

t.Run("Load secret from Trust Engine - secret already by Vault or config.yml", func(t *testing.T) {
t.Run("Load secret from System Trust - secret already by Vault or config.yml", func(t *testing.T) {
stepConfig := &StepConfig{Config: map[string]interface{}{
secretName: "aMockTokenFromVault",
}}

resolveAllTrustEngineReferences(stepConfig, stepParams, trustEngineConfiguration, client)
resolveAllSystemTrustReferences(stepConfig, stepParams, systemTrustConfiguration, client)
assert.NotEqual(t, mockSonarToken, stepConfig.Config[secretName])
})
}

func createStepParam(name, refType, trustengineSecretNameProperty, defaultSecretNameName string) StepParameters {
systemtrust

Check failure on line 62 in pkg/config/systemtrust_test.go

View workflow job for this annotation

GitHub Actions / format

expected declaration, found systemtrust
func createStepParam(name, refType, systemtrustSecretNameProperty, defaultSecretNameName string) StepParameters {
return StepParameters{
Name: name,
Aliases: []Alias{},
ResourceRef: []ResourceReference{
{
Type: refType,
Name: trustengineSecretNameProperty,
Type: systemtrust
Name: systemtrustSecretNameProperty,
Default: defaultSecretNameName,
},
},
Expand Down
67 changes: 0 additions & 67 deletions pkg/config/trustengine.go

This file was deleted.

16 changes: 8 additions & 8 deletions pkg/documentation/generator/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
vaultBadge = "![Vault](https://img.shields.io/badge/-Vault-lightgrey)"
jenkinsOnlyBadge = "![Jenkins only](https://img.shields.io/badge/-Jenkins%20only-yellowgreen)"
secretBadge = "![Secret](https://img.shields.io/badge/-Secret-yellowgreen)"
trustengineBadge = "![Trust Engine](https://img.shields.io/badge/-Trust%20Engine-lightblue)"
systemtrustBadge = "![System Trust](https://img.shields.io/badge/-System%20Trust-lightblue)"
deprecatedBadge = "![deprecated](https://img.shields.io/badge/-deprecated-red)"
)

Expand Down Expand Up @@ -122,9 +122,9 @@ func parameterFurtherInfo(paramName string, stepData *config.StepData, execution
secretInfo := fmt.Sprintf("%s pass via ENV or Jenkins credentials", secretBadge)

isVaultSecret := param.GetReference("vaultSecret") != nil || param.GetReference("vaultSecretFile") != nil
isTrustengineSecret := param.GetReference(config.RefTypeTrustengineSecret) != nil
if isVaultSecret && isTrustengineSecret {
secretInfo = fmt.Sprintf(" %s %s %s pass via ENV, Vault, Trust Engine or Jenkins credentials", vaultBadge, trustengineBadge, secretBadge)
isSystemtrustSecret := param.GetReference(config.RefTypeSystemtrustSecret) != nil
if isVaultSecret && isSystemtrustSecret {
secretInfo = fmt.Sprintf(" %s %s %s pass via ENV, Vault, System Trust or Jenkins credentials", vaultBadge, systemtrustBadge, secretBadge)
} else if isVaultSecret {
secretInfo = fmt.Sprintf(" %s %s pass via ENV, Vault or Jenkins credentials", vaultBadge, secretBadge)
}
Expand Down Expand Up @@ -347,8 +347,8 @@ func resourceReferenceDetails(resourceRef []config.ResourceReference) string {
resourceDetails = addVaultResourceDetails(resource, resourceDetails)
continue
}
if resource.Type == config.RefTypeTrustengineSecret {
resourceDetails = addTrustEngineResourceDetails(resource, resourceDetails)
if resource.Type == config.RefTypeSystemtrustSecret {
resourceDetails = addSystemTrustResourceDetails(resource, resourceDetails)
}
}

Expand All @@ -369,8 +369,8 @@ func addVaultResourceDetails(resource config.ResourceReference, resourceDetails
return resourceDetails
}

func addTrustEngineResourceDetails(resource config.ResourceReference, resourceDetails string) string {
resourceDetails += "<br/>Trust Engine resource:<br />"
func addSystemTrustResourceDetails(resource config.ResourceReference, resourceDetails string) string {
resourceDetails += "<br/>System Trust resource:<br />"
resourceDetails += fmt.Sprintf("&nbsp;&nbsp;name: `%v`<br />", resource.Name)
resourceDetails += fmt.Sprintf("&nbsp;&nbsp;value: `%v`<br />", resource.Default)

Expand Down
Loading

0 comments on commit 66d4680

Please sign in to comment.