Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/auth-account-operations #122

Merged
merged 11 commits into from
Nov 11, 2020
Merged
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ coverage-horusec-analytic:
deployments/scripts/coverage.sh 98 "./horusec-analytic"
coverage-horusec-auth:
chmod +x deployments/scripts/coverage.sh
deployments/scripts/coverage.sh 98 "./horusec-auth"
deployments/scripts/coverage.sh 97 "./horusec-auth"

# Check lint of project setup on file .golangci.yml
lint:
Expand Down
5 changes: 5 additions & 0 deletions deployments/docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ services:
HORUSEC_ENABLE_APPLICATION_ADMIN: "false"
HORUSEC_APPLICATION_ADMIN_DATA: "{\"username\": \"horusec-admin\", \"email\":\"horusec-admin@example.com\", \"password\":\"Devpass0*\"}"
HORUSEC_AUTH_TYPE: "horusec"
HORUSEC_BROKER_HOST: "127.0.0.1"
HORUSEC_BROKER_PORT: "5672"
HORUSEC_BROKER_USERNAME: "guest"
HORUSEC_BROKER_PASSWORD: "guest"
HORUSEC_AUTH_DISABLE_EMAIL_SERVICE: "true"
horusec-analytic:
build:
context: ../
Expand Down
5 changes: 5 additions & 0 deletions deployments/docker-compose.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ services:
HORUSEC_ENABLE_APPLICATION_ADMIN: "false"
HORUSEC_APPLICATION_ADMIN_DATA: "{\"username\": \"horusec-admin\", \"email\":\"horusec-admin@example.com\", \"password\":\"Devpass0*\"}"
HORUSEC_AUTH_TYPE: "horusec"
HORUSEC_BROKER_HOST: "127.0.0.1"
HORUSEC_BROKER_PORT: "5672"
HORUSEC_BROKER_USERNAME: "guest"
HORUSEC_BROKER_PASSWORD: "guest"
HORUSEC_AUTH_DISABLE_EMAIL_SERVICE: "true"
horusec-analytic:
build:
context: ../
Expand Down
5 changes: 5 additions & 0 deletions deployments/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ services:
HORUSEC_ENABLE_APPLICATION_ADMIN: "false"
HORUSEC_APPLICATION_ADMIN_DATA: "{\"username\": \"horusec-admin\", \"email\":\"horusec-admin@example.com\", \"password\":\"Devpass0*\"}"
HORUSEC_AUTH_TYPE: "horusec"
HORUSEC_BROKER_HOST: "127.0.0.1"
HORUSEC_BROKER_PORT: "5672"
HORUSEC_BROKER_USERNAME: "guest"
HORUSEC_BROKER_PASSWORD: "guest"
HORUSEC_AUTH_DISABLE_EMAIL_SERVICE: "true"
horusec-account:
image: horuszup/horusec-account:latest
depends_on:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ package account

import (
SQL "github.com/ZupIT/horusec/development-kit/pkg/databases/relational"
accountEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/account"
authEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/auth"
"github.com/google/uuid"
)

type IAccount interface {
Create(account *accountEntities.Account) error
GetByAccountID(accountID uuid.UUID) (*accountEntities.Account, error)
GetByEmail(email string) (*accountEntities.Account, error)
Update(account *accountEntities.Account) error
GetByUsername(username string) (*accountEntities.Account, error)
Create(account *authEntities.Account) error
GetByAccountID(accountID uuid.UUID) (*authEntities.Account, error)
GetByEmail(email string) (*authEntities.Account, error)
Update(account *authEntities.Account) error
GetByUsername(username string) (*authEntities.Account, error)
DeleteAccount(accountID uuid.UUID) error
}

Expand All @@ -41,32 +41,32 @@ func NewAccountRepository(databaseRead SQL.InterfaceRead, databaseWrite SQL.Inte
}
}

func (a *Account) Create(account *accountEntities.Account) error {
func (a *Account) Create(account *authEntities.Account) error {
return a.databaseWrite.Create(account, account.GetTable()).GetError()
}

func (a *Account) GetByAccountID(accountID uuid.UUID) (*accountEntities.Account, error) {
account := &accountEntities.Account{}
func (a *Account) GetByAccountID(accountID uuid.UUID) (*authEntities.Account, error) {
account := &authEntities.Account{}
filter := a.databaseRead.SetFilter(map[string]interface{}{"account_id": accountID})
result := a.databaseRead.Find(account, filter, account.GetTable())
return account, result.GetError()
}

func (a *Account) GetByEmail(email string) (*accountEntities.Account, error) {
account := &accountEntities.Account{}
func (a *Account) GetByEmail(email string) (*authEntities.Account, error) {
account := &authEntities.Account{}
filter := a.databaseRead.SetFilter(map[string]interface{}{"email": email})
result := a.databaseRead.Find(account, filter, account.GetTable())
return account, result.GetError()
}

func (a *Account) Update(account *accountEntities.Account) error {
func (a *Account) Update(account *authEntities.Account) error {
account.SetUpdatedAt()
return a.databaseWrite.Update(account.ToMap(), map[string]interface{}{"account_id": account.AccountID},
account.GetTable()).GetError()
}

func (a *Account) GetByUsername(username string) (*accountEntities.Account, error) {
account := &accountEntities.Account{}
func (a *Account) GetByUsername(username string) (*authEntities.Account, error) {
account := &authEntities.Account{}
filter := a.databaseRead.SetFilter(map[string]interface{}{"username": username})
result := a.databaseRead.Find(account, filter, account.GetTable())
return account, result.GetError()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package account

import (
authEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/auth"
"testing"

"github.com/ZupIT/horusec/development-kit/pkg/databases/relational"
accountEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/account"
"github.com/ZupIT/horusec/development-kit/pkg/utils/repository/response"
"github.com/google/uuid"
"github.com/jinzhu/gorm"
Expand All @@ -35,7 +35,7 @@ func TestCreate(t *testing.T) {

repository := NewAccountRepository(mockRead, mockWrite)

assert.NoError(t, repository.Create(&accountEntities.Account{}))
assert.NoError(t, repository.Create(&authEntities.Account{}))
})
}

Expand All @@ -46,7 +46,7 @@ func TestGetByAccountID(t *testing.T) {

resp := &response.Response{}
mockRead.On("SetFilter").Return(&gorm.DB{})
mockRead.On("Find").Return(resp.SetData(&accountEntities.Account{}))
mockRead.On("Find").Return(resp.SetData(&authEntities.Account{}))

repository := NewAccountRepository(mockRead, mockWrite)
account, err := repository.GetByAccountID(uuid.New())
Expand All @@ -63,7 +63,7 @@ func TestGetByEmail(t *testing.T) {

resp := &response.Response{}
mockRead.On("SetFilter").Return(&gorm.DB{})
mockRead.On("Find").Return(resp.SetData(&accountEntities.Account{}))
mockRead.On("Find").Return(resp.SetData(&authEntities.Account{}))

repository := NewAccountRepository(mockRead, mockWrite)
account, err := repository.GetByEmail("test@test.com")
Expand All @@ -83,7 +83,7 @@ func TestUpdate(t *testing.T) {

repository := NewAccountRepository(mockRead, mockWrite)

assert.NoError(t, repository.Update(&accountEntities.Account{}))
assert.NoError(t, repository.Update(&authEntities.Account{}))
})
}

Expand All @@ -94,7 +94,7 @@ func TestGetByUsername(t *testing.T) {

resp := &response.Response{}
mockRead.On("SetFilter").Return(&gorm.DB{})
mockRead.On("Find").Return(resp.SetData(&accountEntities.Account{}))
mockRead.On("Find").Return(resp.SetData(&authEntities.Account{}))

repository := NewAccountRepository(mockRead, mockWrite)
account, err := repository.GetByUsername("test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package accountcompany

import (
SQL "github.com/ZupIT/horusec/development-kit/pkg/databases/relational"
"github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles"
"github.com/ZupIT/horusec/development-kit/pkg/entities/roles"
accountEnums "github.com/ZupIT/horusec/development-kit/pkg/enums/account"
"github.com/google/uuid"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ package accountcompany

import (
"errors"
"github.com/ZupIT/horusec/development-kit/pkg/entities/roles"
"testing"

"github.com/ZupIT/horusec/development-kit/pkg/databases/relational"
"github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles"
rolesEnum "github.com/ZupIT/horusec/development-kit/pkg/enums/account"
errorsEnum "github.com/ZupIT/horusec/development-kit/pkg/enums/errors"
"github.com/ZupIT/horusec/development-kit/pkg/utils/repository/response"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package accountrepository

import (
SQL "github.com/ZupIT/horusec/development-kit/pkg/databases/relational"
"github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles"
"github.com/ZupIT/horusec/development-kit/pkg/entities/roles"
"github.com/google/uuid"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ package accountrepository

import (
"errors"
"github.com/ZupIT/horusec/development-kit/pkg/entities/roles"
"testing"

"github.com/ZupIT/horusec/development-kit/pkg/databases/relational"
"github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles"
"github.com/ZupIT/horusec/development-kit/pkg/utils/repository/response"
"github.com/google/uuid"
"github.com/jinzhu/gorm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ package analysis
import (
"errors"
SQL "github.com/ZupIT/horusec/development-kit/pkg/databases/relational"
"github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles"
authEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/auth"
dashboardEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/dashboard"
"github.com/ZupIT/horusec/development-kit/pkg/entities/roles"
rolesEnum "github.com/ZupIT/horusec/development-kit/pkg/enums/account"
"github.com/ZupIT/horusec/development-kit/pkg/enums/confidence"
enumHorusec "github.com/ZupIT/horusec/development-kit/pkg/enums/horusec"
Expand Down Expand Up @@ -52,7 +53,7 @@ func insertAnalysisData() error {

databaseWrite := adapter.NewRepositoryWrite()

account := &accountEntities.Account{
account := &authEntities.Account{
Email: "test@test.com",
Username: "test",
CreatedAt: time.Now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ package company

import (
"fmt"
"github.com/ZupIT/horusec/development-kit/pkg/entities/roles"

SQL "github.com/ZupIT/horusec/development-kit/pkg/databases/relational"
accountEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/account"
"github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles"
"github.com/google/uuid"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package company
import (
SQL "github.com/ZupIT/horusec/development-kit/pkg/databases/relational"
accountEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/account"
"github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles"
"github.com/ZupIT/horusec/development-kit/pkg/entities/roles"
mockUtils "github.com/ZupIT/horusec/development-kit/pkg/utils/mock"
"github.com/google/uuid"
"github.com/stretchr/testify/mock"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (
"errors"
"github.com/ZupIT/horusec/development-kit/pkg/databases/relational/adapter"
"github.com/ZupIT/horusec/development-kit/pkg/databases/relational/config"
authEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/auth"
"github.com/ZupIT/horusec/development-kit/pkg/entities/roles"
rolesEnum "github.com/ZupIT/horusec/development-kit/pkg/enums/account"
"os"
"testing"
"time"

"github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles"

"github.com/ZupIT/horusec/development-kit/pkg/databases/relational"
accountEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/account"
"github.com/ZupIT/horusec/development-kit/pkg/utils/repository/response"
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestGetAllOfAccount(t *testing.T) {
databaseWrite := adapter.NewRepositoryWrite()
databaseRead := adapter.NewRepositoryRead()

account := &accountEntities.Account{
account := &authEntities.Account{
Email: "test@test.com",
Username: "test",
CreatedAt: time.Now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ package repository

import (
"fmt"
"github.com/ZupIT/horusec/development-kit/pkg/entities/roles"

SQL "github.com/ZupIT/horusec/development-kit/pkg/databases/relational"
accountEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/account"
"github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles"
"github.com/ZupIT/horusec/development-kit/pkg/enums/account"
"github.com/ZupIT/horusec/development-kit/pkg/enums/errors"
"github.com/google/uuid"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package repository
import (
SQL "github.com/ZupIT/horusec/development-kit/pkg/databases/relational"
accountEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/account"
"github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles"
"github.com/ZupIT/horusec/development-kit/pkg/entities/roles"
mockUtils "github.com/ZupIT/horusec/development-kit/pkg/utils/mock"
"github.com/google/uuid"
"github.com/stretchr/testify/mock"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ package repository

import (
"errors"
authEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/auth"
"github.com/ZupIT/horusec/development-kit/pkg/entities/roles"
"os"
"testing"
"time"

"github.com/ZupIT/horusec/development-kit/pkg/databases/relational/adapter"
"github.com/ZupIT/horusec/development-kit/pkg/databases/relational/config"
"github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles"
rolesEnum "github.com/ZupIT/horusec/development-kit/pkg/enums/account"

"github.com/ZupIT/horusec/development-kit/pkg/databases/relational"
Expand Down Expand Up @@ -131,7 +132,7 @@ func TestList(t *testing.T) {
databaseWrite := adapter.NewRepositoryWrite()
databaseRead := adapter.NewRepositoryRead()

account := &accountEntities.Account{
account := &authEntities.Account{
Email: "test@test.com",
Username: "test",
CreatedAt: time.Now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import (
"github.com/ZupIT/horusec/development-kit/pkg/databases/relational/adapter"
"github.com/ZupIT/horusec/development-kit/pkg/databases/relational/config"
accountEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/account"
"github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles"
"github.com/ZupIT/horusec/development-kit/pkg/entities/api/dto"
authEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/auth"
horusecEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/horusec"
"github.com/ZupIT/horusec/development-kit/pkg/entities/roles"
rolesEnum "github.com/ZupIT/horusec/development-kit/pkg/enums/account"
"github.com/ZupIT/horusec/development-kit/pkg/utils/repository/response"
"github.com/google/uuid"
Expand All @@ -41,7 +42,7 @@ func TestGetAllVulnManagementData(t *testing.T) {
databaseWrite := adapter.NewRepositoryWrite()
databaseRead := adapter.NewRepositoryRead()

account := &accountEntities.Account{
account := &authEntities.Account{
Email: "test@test.com",
Username: "test",
CreatedAt: time.Now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package account
package dto

import (
"github.com/dgrijalva/jwt-go"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package account
package dto

import (
"github.com/dgrijalva/jwt-go"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package account
package dto

import (
"encoding/json"
"github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles"
"github.com/ZupIT/horusec/development-kit/pkg/entities/roles"
accountEnums "github.com/ZupIT/horusec/development-kit/pkg/enums/account"
validation "github.com/go-ozzo/ozzo-validation/v4"
"github.com/go-ozzo/ozzo-validation/v4/is"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package account
package dto

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package account
package dto

import "github.com/google/uuid"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package account
package dto

import (
"github.com/google/uuid"
Expand Down
Loading