Skip to content

Commit

Permalink
optimize transfer controller, add encryption to account and adapt to …
Browse files Browse the repository at this point in the history
…existing environment
  • Loading branch information
bxy4543 committed Jul 4, 2023
1 parent 2f9eedd commit 5c2a6e5
Show file tree
Hide file tree
Showing 11 changed files with 273 additions and 73 deletions.
4 changes: 2 additions & 2 deletions controllers/account/api/v1/account_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ type AccountSpec struct{}
// AccountStatus defines the observed state of Account
type AccountStatus struct {
// EncryptBalance is to encrypt balance
EncryptBalance string `json:"encryptBalance,omitempty"`
EncryptBalance *string `json:"encryptBalance,omitempty"`
// Recharge amount
Balance int64 `json:"balance,omitempty"`
//Deduction amount
DeductionBalance int64 `json:"deductionBalance,omitempty"`
// EncryptDeductionBalance is to encrypt DeductionBalance
EncryptDeductionBalance string `json:"encryptDeductionBalance,omitempty"`
EncryptDeductionBalance *string `json:"encryptDeductionBalance,omitempty"`
// delete in the future
ChargeList []Charge `json:"chargeList,omitempty"`
}
Expand Down
19 changes: 18 additions & 1 deletion controllers/account/api/v1/transfer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package v1

import (
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -34,7 +36,8 @@ const (

// TransferSpec defines the desired state of Transfer
type TransferSpec struct {
To string `json:"to"`
From string `json:"from"`
To string `json:"to"`
// +kubebuilder:validation:Minimum=1000000
Amount int64 `json:"amount"`
}
Expand Down Expand Up @@ -69,3 +72,17 @@ type TransferList struct {
func init() {
SchemeBuilder.Register(&Transfer{}, &TransferList{})
}

func (t *Transfer) ToJSON() string {
return `{
"spec": {
"from": "` + t.Spec.From + `",
"to": "` + t.Spec.To + `",
"amount": ` + fmt.Sprint(t.Spec.Amount) + `
},
"status": {
"reason": "` + t.Status.Reason + `",
"progress": "` + string(rune(t.Status.Progress)) + `"
}
}`
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ spec:
description: Deduction amount
format: int64
type: integer
encryptBalance:
description: EncryptBalance is to encrypt balance
type: string
encryptDeductionBalance:
description: EncryptDeductionBalance is to encrypt DeductionBalance
type: string
type: object
type: object
served: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
creationTimestamp: null
name: transfers.account.sealos.io
spec:
group: account.sealos.io
names:
kind: Transfer
listKind: TransferList
plural: transfers
singular: transfer
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: Transfer is the Schema for the transfers API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: TransferSpec defines the desired state of Transfer
properties:
amount:
format: int64
minimum: 1000000
type: integer
from:
type: string
to:
type: string
required:
- amount
- to
type: object
status:
description: TransferStatus defines the observed state of Transfer
properties:
progress:
type: integer
reason:
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
24 changes: 24 additions & 0 deletions controllers/account/config/rbac/transfer_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# permissions for end users to edit transfers.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: transfer-editor-role
rules:
- apiGroups:
- account.sealos.io
resources:
- transfers
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- account.sealos.io
resources:
- transfers/status
verbs:
- get
20 changes: 20 additions & 0 deletions controllers/account/config/rbac/transfer_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# permissions for end users to view transfers.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: transfer-viewer-role
rules:
- apiGroups:
- account.sealos.io
resources:
- transfers
verbs:
- get
- list
- watch
- apiGroups:
- account.sealos.io
resources:
- transfers/status
verbs:
- get
6 changes: 6 additions & 0 deletions controllers/account/config/samples/account_v1_transfer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: account.sealos.io/v1
kind: Transfer
metadata:
name: transfer-sample
spec:
# TODO(user): Add fields here
Loading

0 comments on commit 5c2a6e5

Please sign in to comment.