Skip to content

Commit

Permalink
Make SSH key non-required
Browse files Browse the repository at this point in the history
Signed-off-by: Ondra Machacek <[email protected]>
  • Loading branch information
machacekondra committed Nov 18, 2024
1 parent 56041f4 commit d06d67b
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 61 deletions.
42 changes: 21 additions & 21 deletions api/v1alpha1/agent/spec.gen.go

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

2 changes: 0 additions & 2 deletions api/v1alpha1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ components:
- statusInfo
- createdAt
- updatedAt
- sshKey

SourceCreate:
type: object
Expand All @@ -273,7 +272,6 @@ components:
type: string
required:
- name
- sshKey

SourceList:
type: array
Expand Down
58 changes: 29 additions & 29 deletions api/v1alpha1/spec.gen.go

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

6 changes: 3 additions & 3 deletions api/v1alpha1/types.gen.go

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

2 changes: 2 additions & 0 deletions data/ignition.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ passwd:
users:
- name: core
password_hash: "$y$j9T$hUUbW8zoB.Qcmpwm4/RuK1$FMtuDAxNLp3sEa2PnGiJdXr8uYbvUNPlVDXpcJim529"
{{if .SshKey}}
ssh_authorized_keys:
- {{.SshKey}}
{{end}}

storage:
links:
Expand Down
6 changes: 4 additions & 2 deletions internal/image/ova.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const ResponseWriterKey Key = 0
type Ova struct {
Id uuid.UUID
Writer io.Writer
SshKey string
SshKey *string
}

// IgnitionData defines modifiable fields in ignition config
Expand Down Expand Up @@ -124,10 +124,12 @@ func writeOvf(tw *tar.Writer) error {
func (o *Ova) generateIgnition() (string, error) {
ignData := IgnitionData{
SourceId: o.Id.String(),
SshKey: o.SshKey,
PlannerService: util.GetEnv("CONFIG_SERVER", "http://127.0.0.1:7443"),
MigrationPlannerAgentImage: util.GetEnv("MIGRATION_PLANNER_AGENT_IMAGE", "quay.io/kubev2v/migration-planner-agent"),
}
if o.SshKey != nil {
ignData.SshKey = *o.SshKey
}

if insecureRegistry := os.Getenv("INSECURE_REGISTRY"); insecureRegistry != "" {
ignData.InsecureRegistry = insecureRegistry
Expand Down
2 changes: 1 addition & 1 deletion internal/store/model/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Source struct {
Name string
Status string
StatusInfo string
SshKey string
SshKey *string
Inventory *JSONField[api.Inventory] `gorm:"type:jsonb"`
CredUrl *string
Agents []Agent `gorm:"constraint:OnDelete:SET NULL;"`
Expand Down
16 changes: 15 additions & 1 deletion internal/store/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,23 @@ var _ = Describe("source store", Ordered, func() {

Context("create", func() {
It("successfully creates one source", func() {
sshKey := "some key"
source, err := s.Source().Create(context.TODO(), v1alpha1.SourceCreate{
Name: "name-1",
SshKey: "some key",
SshKey: &sshKey,
})
Expect(err).To(BeNil())
Expect(source).NotTo(BeNil())

var count int
tx := gormdb.Raw("SELECT COUNT(*) FROM sources;").Scan(&count)
Expect(tx.Error).To(BeNil())
Expect(count).To(Equal(1))
})

It("successfully creates one source without sshkey", func() {
source, err := s.Source().Create(context.TODO(), v1alpha1.SourceCreate{
Name: "name-1",
})
Expect(err).To(BeNil())
Expect(source).NotTo(BeNil())
Expand Down
6 changes: 4 additions & 2 deletions internal/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var _ = Describe("Store", Ordered, func() {
var (
store st.Store
gormDB *gorm.DB
sshKey string
)

BeforeAll(func() {
Expand All @@ -24,6 +25,7 @@ var _ = Describe("Store", Ordered, func() {
db, err := st.InitDB(cfg, log)
Expect(err).To(BeNil())
gormDB = db
sshKey = "ssh-key"

store = st.NewStore(db, log.WithField("test", "store"))
Expect(store).ToNot(BeNil())
Expand All @@ -38,7 +40,7 @@ var _ = Describe("Store", Ordered, func() {
ctx, err := store.NewTransactionContext(context.TODO())
Expect(err).To(BeNil())

source, err := store.Source().Create(ctx, api.SourceCreate{Name: "test", SshKey: "some key"})
source, err := store.Source().Create(ctx, api.SourceCreate{Name: "test", SshKey: &sshKey})
Expect(source).ToNot(BeNil())
Expect(err).To(BeNil())

Expand All @@ -56,7 +58,7 @@ var _ = Describe("Store", Ordered, func() {
ctx, err := store.NewTransactionContext(context.TODO())
Expect(err).To(BeNil())

source, err := store.Source().Create(ctx, api.SourceCreate{Name: "test", SshKey: "some key"})
source, err := store.Source().Create(ctx, api.SourceCreate{Name: "test", SshKey: &sshKey})
Expect(source).ToNot(BeNil())
Expect(err).To(BeNil())

Expand Down

0 comments on commit d06d67b

Please sign in to comment.