Skip to content

Commit ac46ce9

Browse files
committed
Simplify more by removing custom hash
Signed-off-by: Yury Tsarev <[email protected]>
1 parent f43775a commit ac46ce9

File tree

5 files changed

+4
-39
lines changed

5 files changed

+4
-39
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ spec:
6464
| Field | Type | Description |
6565
|-------|------|-------------|
6666
| `dataField` | string | **Required**. Field to monitor for changes (e.g., `spec.resources`) |
67-
| `hashAlgorithm` | string | Algorithm to use for hash calculation. Supported values: `md5`, `sha256`, `sha512`. Default: `sha256` |
6867
| `approvalField` | string | Status field to check for approval. Default: `status.approved` |
6968
| `currentHashField` | string | Status field to store the approved hash. Default: `status.currentHash` |
7069
| `detailedCondition` | bool | Whether to add detailed information to conditions. Default: `true` |
@@ -172,7 +171,6 @@ spec:
172171
kind: Input
173172
dataField: "spec.resources"
174173
approvalField: "status.approved"
175-
hashAlgorithm: "sha256"
176174
currentHashField: "status.currentHash"
177175
detailedCondition: true
178176
approvalMessage: "Cluster changes require admin approval"

fn.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ package main
33
import (
44
"context"
55
"crypto/sha256"
6-
"crypto/sha512"
76
"encoding/hex"
87
"encoding/json"
9-
"hash"
108
"strings"
119

1210
"github.com/upbound/function-approve/input/v1beta1"
@@ -159,11 +157,6 @@ func (f *Function) parseInput(req *fnv1.RunFunctionRequest, rsp *fnv1.RunFunctio
159157
}
160158

161159
// Set default values if not provided
162-
if in.HashAlgorithm == nil {
163-
defaultAlgo := "sha256"
164-
in.HashAlgorithm = &defaultAlgo
165-
}
166-
167160
if in.ApprovalField == nil {
168161
defaultField := "status.approved"
169162
in.ApprovalField = &defaultField
@@ -418,26 +411,17 @@ func (f *Function) extractDataToHash(req *fnv1.RunFunctionRequest, in *v1beta1.I
418411
return data, nil
419412
}
420413

421-
// calculateHash calculates hash for the given data using the specified algorithm
422-
func (f *Function) calculateHash(data interface{}, in *v1beta1.Input) string {
414+
// calculateHash calculates hash for the given data using SHA256
415+
func (f *Function) calculateHash(data interface{}, _ *v1beta1.Input) string {
423416
// Create a JSON representation of the data
424417
jsonData, err := json.Marshal(data)
425418
if err != nil {
426419
f.log.Debug("Error marshaling data to JSON", "error", err)
427420
return ""
428421
}
429422

430-
// Choose hash algorithm
431-
var h hash.Hash
432-
switch *in.HashAlgorithm {
433-
case "sha512":
434-
h = sha512.New()
435-
default:
436-
// Default to sha256
437-
h = sha256.New()
438-
}
439-
440-
// Calculate hash
423+
// Calculate SHA256 hash
424+
h := sha256.New()
441425
h.Write(jsonData)
442426
return hex.EncodeToString(h.Sum(nil))
443427
}

input/v1beta1/input.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ type Input struct {
2323
// For example: "spec.resources"
2424
DataField string `json:"dataField"`
2525

26-
// HashAlgorithm defines which hash algorithm to use for calculating hashes
27-
// Supported values: "md5", "sha256", "sha512"
28-
// Default is "sha256"
29-
// +optional
30-
HashAlgorithm *string `json:"hashAlgorithm,omitempty"`
31-
3226
// ApprovalField defines the status field to check for the approval decision
3327
// Default is "status.approved"
3428
// +optional

input/v1beta1/zz_generated.deepcopy.go

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/input/approve.fn.crossplane.io_inputs.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ spec:
5353
DetailedCondition adds a detailed condition about approval status
5454
Default is true
5555
type: boolean
56-
hashAlgorithm:
57-
description: |-
58-
HashAlgorithm defines which hash algorithm to use for calculating hashes
59-
Supported values: "md5", "sha256", "sha512"
60-
Default is "sha256"
61-
type: string
6256
kind:
6357
description: |-
6458
Kind is a string value representing the REST resource this object represents.

0 commit comments

Comments
 (0)