Skip to content

Commit

Permalink
fix: adds specific domain to profile export
Browse files Browse the repository at this point in the history
Co-authored-by: Mike <[email protected]>
Co-authored-by: Nick Ross <[email protected]>
Co-authored-by: Mario Jose Divan Koller <[email protected]>
  • Loading branch information
4 people committed Jan 15, 2025
1 parent 03089e6 commit af59618
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 24 deletions.
3 changes: 2 additions & 1 deletion internal/controller/http/v1/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ func (r *profileRoutes) getByName(c *gin.Context) {

func (r *profileRoutes) export(c *gin.Context) {
name := c.Param("name")
domainName := c.Query("domainName")

item, key, err := r.t.Export(c.Request.Context(), name, "")
item, key, err := r.t.Export(c.Request.Context(), name, domainName, "")
if err != nil {
r.l.Error(err, "http - v1 - export")
ErrorResponse(c, err)
Expand Down
4 changes: 4 additions & 0 deletions internal/mocks/amtexplorer_mocks.go

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

3 changes: 3 additions & 0 deletions internal/mocks/app_mocks.go

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

2 changes: 2 additions & 0 deletions internal/mocks/ciraconfigs_mocks.go

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

5 changes: 5 additions & 0 deletions internal/mocks/devicemanagement_mocks.go

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

2 changes: 2 additions & 0 deletions internal/mocks/domains_mocks.go

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

1 change: 1 addition & 0 deletions internal/mocks/export_mocks.go

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

2 changes: 2 additions & 0 deletions internal/mocks/ieee8021xconfigs_mocks.go

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

1 change: 1 addition & 0 deletions internal/mocks/logger_mocks.go

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

10 changes: 6 additions & 4 deletions internal/mocks/profiles_mocks.go

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

2 changes: 2 additions & 0 deletions internal/mocks/profileswificonfigs_mocks.go

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

2 changes: 2 additions & 0 deletions internal/mocks/wificonfigs_mocks.go

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

1 change: 1 addition & 0 deletions internal/mocks/wsman_mocks.go

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

3 changes: 3 additions & 0 deletions internal/mocks/wsv1_mocks.go

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

2 changes: 1 addition & 1 deletion internal/usecase/profiles/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ type (
Delete(ctx context.Context, profileName, tenantID string) error
Update(ctx context.Context, p *dto.Profile) (*dto.Profile, error)
Insert(ctx context.Context, p *dto.Profile) (*dto.Profile, error)
Export(ctx context.Context, profileName, tenantID string) (string, string, error)
Export(ctx context.Context, profileName, domainName, tenantID string) (string, string, error)
}
)
14 changes: 6 additions & 8 deletions internal/usecase/profiles/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,15 @@ func (uc *UseCase) GetProfileData(ctx context.Context, profileName, tenantID str
return data, nil
}

func (uc *UseCase) GetDomainInformation(ctx context.Context, activation, tenantID string) (entity.Domain, error) {
func (uc *UseCase) GetDomainInformation(ctx context.Context, activation, domainName, tenantID string) (entity.Domain, error) {
var domain entity.Domain

if activation == "acmactivate" {
domainsToExport, err := uc.domains.Get(ctx, 1, 0, tenantID)
if err != nil || len(domainsToExport) == 0 {
return entity.Domain{}, ErrNotFound.WrapWithMessage("Export", "uc.domains.Get", "No domains found")
domain, err := uc.domains.GetByName(ctx, domainName, tenantID)
if err != nil || domain == (&entity.Domain{}) {
return entity.Domain{}, ErrNotFound.WrapWithMessage("Export", "uc.domains.Get", "No domain found")
}

domain = domainsToExport[0]

domain.ProvisioningCertPassword, err = uc.safeRequirements.Decrypt(domain.ProvisioningCertPassword)
if err != nil {
return entity.Domain{}, err
Expand Down Expand Up @@ -333,7 +331,7 @@ func (uc *UseCase) SerializeAndEncryptYAML(configuration config.Configuration) (
}

// Export - will call GetByName and return the profile with the associated wifi configs in YAML format to be downloaded.
func (uc *UseCase) Export(ctx context.Context, profileName, tenantID string) (encryptedYAML, encryptionKey string, err error) {
func (uc *UseCase) Export(ctx context.Context, profileName, domainName, tenantID string) (encryptedYAML, encryptionKey string, err error) {
data, err := uc.GetProfileData(ctx, profileName, tenantID)
if err != nil {
return "", "", err
Expand All @@ -344,7 +342,7 @@ func (uc *UseCase) Export(ctx context.Context, profileName, tenantID string) (en
return "", "", err
}

domainStuff, err := uc.GetDomainInformation(ctx, data.Activation, tenantID)
domainStuff, err := uc.GetDomainInformation(ctx, data.Activation, domainName, tenantID)
if err != nil {
return "", "", err
}
Expand Down
29 changes: 22 additions & 7 deletions internal/usecase/profiles/usecase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,32 +644,47 @@ func TestGetDomainInformation(t *testing.T) {
tests := []struct {
name string
activation string
domainName string
mock func(domainsMock *mocks.MockDomainsRepository)
expected entity.Domain
err error
}{
{
name: "successful retrieval for acmactivate",
activation: "acmactivate",
domainName: "vpro",
mock: func(domainsMock *mocks.MockDomainsRepository) {
domainsMock.EXPECT().
Get(ctx, 1, 0, tenantID).
Return([]entity.Domain{
{ProvisioningCertPassword: "encryptedCert"},
GetByName(ctx, "vpro", tenantID).
Return(&entity.Domain{
ProvisioningCertPassword: "encryptedCert",
}, nil)
},
expected: entity.Domain{
ProvisioningCertPassword: "decrypted",
ProvisioningCertPassword: "",
},
err: nil,
},
{
name: "no domains found",
activation: "acmactivate",
domainName: "",
mock: func(domainsMock *mocks.MockDomainsRepository) {
domainsMock.EXPECT().
Get(ctx, 1, 0, tenantID).
Return([]entity.Domain{}, nil)
GetByName(ctx, "", tenantID).
Return(&entity.Domain{}, nil)
},
expected: entity.Domain{},
err: nil,
},
{
name: "on error",
activation: "acmactivate",
domainName: "badRequest",
mock: func(domainsMock *mocks.MockDomainsRepository) {
domainsMock.EXPECT().
GetByName(ctx, "badRequest", tenantID).
Return(nil, profiles.ErrNotFound)
},
expected: entity.Domain{},
err: profiles.ErrNotFound.WrapWithMessage("Export", "uc.domains.Get", "No domains found"),
Expand All @@ -687,7 +702,7 @@ func TestGetDomainInformation(t *testing.T) {

useCase := profiles.New(nil, nil, nil, nil, nil, domainsMock, cryptoMock)

domain, err := useCase.GetDomainInformation(ctx, tc.activation, tenantID)
domain, err := useCase.GetDomainInformation(ctx, tc.activation, tc.domainName, tenantID)

require.Equal(t, tc.expected, domain)

Expand Down
Loading

0 comments on commit af59618

Please sign in to comment.