Skip to content

Commit

Permalink
Allow to contruct cli-yaml from internal model
Browse files Browse the repository at this point in the history
commit_hash:2f4e114f55335b45c042951d104c77dc4fa086bf
  • Loading branch information
laskoviymishka committed Dec 23, 2024
1 parent a446a0f commit b8e63c9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
28 changes: 26 additions & 2 deletions cmd/trcli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/doublecloud/transfer/library/go/core/xerrors"
"github.com/doublecloud/transfer/pkg/abstract"
"github.com/doublecloud/transfer/pkg/abstract/model"
"github.com/doublecloud/transfer/pkg/transformer"
"github.com/mitchellh/mapstructure"
"gopkg.in/yaml.v2"
sig_yaml "sigs.k8s.io/yaml"
Expand Down Expand Up @@ -52,9 +53,9 @@ func ParseTransfer(yaml []byte) (*model.Transfer, error) {
transfer := transfer(source, target, tr)

transfer.FillDependentFields()
if len(tr.Transformation.Transformers) > 0 {
if tr.Transformation != nil && len(tr.Transformation.Transformers) > 0 {
transfer.Transformation = &model.Transformation{
Transformers: &tr.Transformation,
Transformers: tr.Transformation,
ExtraTransformers: nil,
Executor: nil,
RuntimeJobIndex: 0,
Expand Down Expand Up @@ -187,3 +188,26 @@ func transfer(source model.Source, target model.Destination, tr *TransferYamlVie
transfer.TypeSystemVersion = tr.TypeSystemVersion
return transfer
}

func NewYamlView(tr *model.Transfer) *TransferYamlView {
var transformations *transformer.Transformers
if tr.Transformation != nil {
transformations = tr.Transformation.Transformers
}
return &TransferYamlView{
ID: tr.ID,
TransferName: tr.TransferName,
Description: tr.Description,
Labels: tr.LabelsRaw(),
Status: tr.Status,
Type: tr.Type,
FolderID: tr.FolderID,
CloudID: tr.CloudID,
Src: Endpoint{Type: tr.SrcType(), Params: tr.Src},
Dst: Endpoint{Type: tr.DstType(), Params: tr.Dst},
RegularSnapshot: tr.RegularSnapshot,
Transformation: transformations,
DataObjects: tr.DataObjects,
TypeSystemVersion: tr.TypeSystemVersion,
}
}
11 changes: 3 additions & 8 deletions cmd/trcli/config/model.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package config

import (
"time"

"github.com/doublecloud/transfer/pkg/abstract"
"github.com/doublecloud/transfer/pkg/abstract/model"
"github.com/doublecloud/transfer/pkg/transformer"
"gopkg.in/yaml.v2"
)

type Endpoint struct {
ID, Name string
Type abstract.ProviderType
Params any
Type abstract.ProviderType
Params any
}

func (e Endpoint) RawParams() string {
Expand Down Expand Up @@ -45,12 +42,10 @@ type TransferYamlView struct {
Type abstract.TransferType
FolderID string
CloudID string
CreatedAt time.Time `db:"created_at"`
Runtime Runtime
Src Endpoint
Dst Endpoint
RegularSnapshot *abstract.RegularSnapshot `yaml:"regular_snapshot"`
Transformation transformer.Transformers `yaml:"transformation"`
Transformation *transformer.Transformers `yaml:"transformation"`
DataObjects *model.DataObjects `yaml:"data_objects"`
TypeSystemVersion int `yaml:"type_system_version"`
}

0 comments on commit b8e63c9

Please sign in to comment.