Skip to content

Commit

Permalink
chore: add changes from suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Chief-Rishab committed Aug 12, 2023
1 parent 5ace2c5 commit f840205
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 26 deletions.
6 changes: 3 additions & 3 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,22 @@ func StartServer(logger *log.Zap, cfg *config.Frontier) error {
}

// session service initialization and cleanup
if err := deps.SessionService.InitSessions(context.Background()); err != nil {
if err := deps.SessionService.InitSessions(ctx); err != nil {
logger.Warn("sessions database cleanup failed", "err", err)
}
defer func() {
logger.Debug("cleaning up cron jobs")
deps.SessionService.Close()
}()

if err := deps.DomainService.InitDomainVerification(context.Background()); err != nil {
if err := deps.DomainService.InitDomainVerification(ctx); err != nil {
logger.Warn("domains database cleanup failed", "err", err)
}
defer func() {
deps.DomainService.Close()
}()

if err := deps.AuthnService.InitFlows(context.Background()); err != nil {
if err := deps.AuthnService.InitFlows(ctx); err != nil {
logger.Warn("flows database cleanup failed", "err", err)
}
defer func() {
Expand Down
2 changes: 1 addition & 1 deletion core/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Domain struct {
Name string
OrgID string
Token string
State string
State Status
UpdatedAt time.Time
CreatedAt time.Time
}
2 changes: 1 addition & 1 deletion core/domain/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package domain

type Filter struct {
OrgID string
State string
State Status
Name string
}
13 changes: 8 additions & 5 deletions core/domain/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ func (s Service) VerifyDomain(ctx context.Context, id string) (Domain, error) {
}

for _, txtRecord := range txtRecords {
if txtRecord == domain.Token {
domain.State = Verified.String()
s.repository.Update(ctx, domain)
if strings.TrimSpace(txtRecord) == strings.TrimSpace(domain.Token) {
domain.State = Verified
domain, err = s.repository.Update(ctx, domain)
if err != nil {
return Domain{}, err
}
return domain, nil
}
}
Expand Down Expand Up @@ -136,7 +139,7 @@ func (s Service) Join(ctx context.Context, orgID string, userId string) error {
// check if user domain matches the org whitelisted domains
orgTrustedDomains, err := s.List(ctx, Filter{
OrgID: orgID,
State: Verified.String(),
State: Verified,
})
if err != nil {
return err
Expand All @@ -160,7 +163,7 @@ func (s Service) Join(ctx context.Context, orgID string, userId string) error {
func (s Service) ListOrgByDomain(ctx context.Context, domain string) ([]string, error) {
domains, err := s.repository.List(ctx, Filter{
Name: domain,
State: Verified.String(),
State: Verified,
})
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/authn/org-domain.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To verify domain ownership, Frontier provides a verification token which needs t

4. **Add Verification Code to DNS Records**: Once you're in the DNS management section, look for the option to add new DNS records. Choose the record type "TXT" (Text), which allows you to add free-form text information to the domain's DNS records.

Frontier verification token looks something like this `_frontier-challenge:1234567890123456`. The token is a combination of a prefix `_frontier-challenge:` and a random string of 16 characters. The prefix is used to identify the token as a Frontier verification token. The random string is used to ensure that the token is unique and not guessable.
Frontier verification token looks something like this `_frontier-domain-verification=LB6U2lSQgGS55HOy6kpWFqkngRC8TMEjyrakfmYC2D0s+nfy/WkFSg==`. The token is a combination of a prefix `_frontier-domain-verification=` and a random string of 40 characters. The prefix is used to identify the token as a Frontier verification token. The random string is used to ensure that the token is unique and not guessable.

5. **Paste Verification code**: Copy a verification code which the above Frontier API returns. This is the same record Frontier expects in the DNS record of the domain an Organization claims to own.

Expand Down
10 changes: 5 additions & 5 deletions internal/api/v1beta1/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
var (
grpcDomainNotFoundErr = status.Errorf(codes.NotFound, "domain whitelist request doesn't exist")
grpcDomainAlreadyExistsErr = status.Errorf(codes.AlreadyExists, "domain name already exists for that organization")
grpcInvalidHostErr = status.Errorf(codes.NotFound, "invalid domain. No such host found")
grpcInvalidHostErr = status.Errorf(codes.NotFound, "invalid domain, no such host found")
grpcTXTRecordNotFound = status.Errorf(codes.NotFound, "required TXT record not found for domain verification")
grpcDomainMisMatchErr = status.Errorf(codes.InvalidArgument, "user and org's whitelisted domains doesn't match")
)
Expand Down Expand Up @@ -150,7 +150,7 @@ func (h Handler) VerifyOrgDomain(ctx context.Context, request *frontierv1beta1.V
}
}

return &frontierv1beta1.VerifyOrgDomainResponse{State: domainResp.State}, nil
return &frontierv1beta1.VerifyOrgDomainResponse{State: domainResp.State.String()}, nil
}

func (h Handler) ListOrganizationDomains(ctx context.Context, request *frontierv1beta1.ListOrganizationDomainsRequest) (*frontierv1beta1.ListOrganizationDomainsResponse, error) {
Expand All @@ -160,7 +160,7 @@ func (h Handler) ListOrganizationDomains(ctx context.Context, request *frontierv
return nil, grpcBadBodyError
}

domains, err := h.domainService.List(ctx, domain.Filter{OrgID: request.GetOrgId(), State: request.GetState()})
domains, err := h.domainService.List(ctx, domain.Filter{OrgID: request.GetOrgId(), State: domain.Status(request.GetState())})
if err != nil {
logger.Error(err.Error())
return nil, grpcInternalServerError
Expand All @@ -173,7 +173,7 @@ func (h Handler) ListOrganizationDomains(ctx context.Context, request *frontierv
Name: d.Name,
OrgId: d.OrgID,
Token: d.Token,
State: d.State,
State: d.State.String(),
CreatedAt: timestamppb.New(d.CreatedAt),
UpdatedAt: timestamppb.New(d.UpdatedAt),
})
Expand All @@ -188,7 +188,7 @@ func transformDomainToPB(from domain.Domain) frontierv1beta1.Domain {
Name: from.Name,
OrgId: from.OrgID,
Token: from.Token,
State: from.State,
State: from.State.String(),
CreatedAt: timestamppb.New(from.CreatedAt),
UpdatedAt: timestamppb.New(from.UpdatedAt),
}
Expand Down
19 changes: 9 additions & 10 deletions internal/store/postgres/domain.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package postgres

import (
"database/sql"
"time"

"github.com/raystack/frontier/core/domain"
)

type Domain struct {
ID string `db:"id"`
OrgID string `db:"org_id"`
Name string `db:"name"`
Token string `db:"token"`
State string `db:"state"`
UpdatedAt sql.NullTime `db:"updated_at"`
CreatedAt time.Time `db:"created_at"`
ID string `db:"id"`
OrgID string `db:"org_id"`
Name string `db:"name"`
Token string `db:"token"`
State string `db:"state"`
UpdatedAt time.Time `db:"updated_at"`
CreatedAt time.Time `db:"created_at"`
}

func (d Domain) transform() domain.Domain {
Expand All @@ -23,8 +22,8 @@ func (d Domain) transform() domain.Domain {
OrgID: d.OrgID,
Name: d.Name,
Token: d.Token,
State: d.State,
UpdatedAt: d.UpdatedAt.Time,
State: domain.Status(d.State),
UpdatedAt: d.UpdatedAt,
CreatedAt: d.CreatedAt,
}
}

0 comments on commit f840205

Please sign in to comment.