25 lines
711 B
Go
25 lines
711 B
Go
package admission
|
|
|
|
import "fmt"
|
|
|
|
var currentService *Service
|
|
|
|
func setCurrentService(service *Service) { currentService = service }
|
|
|
|
// VerifiedProfile is a Sense-internal projection, not a cross-product contract.
|
|
func VerifiedProfile(deviceID, token string) (Profile, error) {
|
|
if currentService == nil {
|
|
return Profile{}, fmt.Errorf("admission service is not ready")
|
|
}
|
|
result, ok := currentService.Get(deviceID)
|
|
if !ok {
|
|
return Profile{}, fmt.Errorf("device admission has not been verified")
|
|
}
|
|
for _, profile := range result.Profiles {
|
|
if profile.Token == token && profile.Verification.Status == "ready" {
|
|
return profile, nil
|
|
}
|
|
}
|
|
return Profile{}, fmt.Errorf("verified profile not found")
|
|
}
|