-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added GET enterprise API endpoint. (#26555)
For #26218 - Added `GET /api/_version_/fleet/android_enterprise` andpoint and tests - Set up some testing infrastructure for Android service tests -- see new README.md # Checklist for submitter - [x] Added/updated automated tests - [x] Manual QA for all new/changed functionality
- Loading branch information
Showing
29 changed files
with
854 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package mock | ||
|
||
//go:generate go run ../../../mock/mockimpl/impl.go -o proxy.go "p *Proxy" "android.Proxy" | ||
//go:generate go run ../../../mock/mockimpl/impl.go -o datastore.go "ds *Datastore" "android.Datastore" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Automatically generated by mockimpl. DO NOT EDIT! | ||
|
||
package mock | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/fleetdm/fleet/v4/server/mdm/android" | ||
"github.com/jmoiron/sqlx" | ||
) | ||
|
||
var _ android.Datastore = (*Datastore)(nil) | ||
|
||
type CreateEnterpriseFunc func(ctx context.Context) (uint, error) | ||
|
||
type GetEnterpriseByIDFunc func(ctx context.Context, ID uint) (*android.EnterpriseDetails, error) | ||
|
||
type GetEnterpriseFunc func(ctx context.Context) (*android.Enterprise, error) | ||
|
||
type UpdateEnterpriseFunc func(ctx context.Context, enterprise *android.EnterpriseDetails) error | ||
|
||
type DeleteAllEnterprisesFunc func(ctx context.Context) error | ||
|
||
type DeleteOtherEnterprisesFunc func(ctx context.Context, ID uint) error | ||
|
||
type CreateDeviceTxFunc func(ctx context.Context, tx sqlx.ExtContext, device *android.Device) (*android.Device, error) | ||
|
||
type UpdateDeviceTxFunc func(ctx context.Context, tx sqlx.ExtContext, device *android.Device) error | ||
|
||
type Datastore struct { | ||
CreateEnterpriseFunc CreateEnterpriseFunc | ||
CreateEnterpriseFuncInvoked bool | ||
|
||
GetEnterpriseByIDFunc GetEnterpriseByIDFunc | ||
GetEnterpriseByIDFuncInvoked bool | ||
|
||
GetEnterpriseFunc GetEnterpriseFunc | ||
GetEnterpriseFuncInvoked bool | ||
|
||
UpdateEnterpriseFunc UpdateEnterpriseFunc | ||
UpdateEnterpriseFuncInvoked bool | ||
|
||
DeleteAllEnterprisesFunc DeleteAllEnterprisesFunc | ||
DeleteAllEnterprisesFuncInvoked bool | ||
|
||
DeleteOtherEnterprisesFunc DeleteOtherEnterprisesFunc | ||
DeleteOtherEnterprisesFuncInvoked bool | ||
|
||
CreateDeviceTxFunc CreateDeviceTxFunc | ||
CreateDeviceTxFuncInvoked bool | ||
|
||
UpdateDeviceTxFunc UpdateDeviceTxFunc | ||
UpdateDeviceTxFuncInvoked bool | ||
|
||
mu sync.Mutex | ||
} | ||
|
||
func (ds *Datastore) CreateEnterprise(ctx context.Context) (uint, error) { | ||
ds.mu.Lock() | ||
ds.CreateEnterpriseFuncInvoked = true | ||
ds.mu.Unlock() | ||
return ds.CreateEnterpriseFunc(ctx) | ||
} | ||
|
||
func (ds *Datastore) GetEnterpriseByID(ctx context.Context, ID uint) (*android.EnterpriseDetails, error) { | ||
ds.mu.Lock() | ||
ds.GetEnterpriseByIDFuncInvoked = true | ||
ds.mu.Unlock() | ||
return ds.GetEnterpriseByIDFunc(ctx, ID) | ||
} | ||
|
||
func (ds *Datastore) GetEnterprise(ctx context.Context) (*android.Enterprise, error) { | ||
ds.mu.Lock() | ||
ds.GetEnterpriseFuncInvoked = true | ||
ds.mu.Unlock() | ||
return ds.GetEnterpriseFunc(ctx) | ||
} | ||
|
||
func (ds *Datastore) UpdateEnterprise(ctx context.Context, enterprise *android.EnterpriseDetails) error { | ||
ds.mu.Lock() | ||
ds.UpdateEnterpriseFuncInvoked = true | ||
ds.mu.Unlock() | ||
return ds.UpdateEnterpriseFunc(ctx, enterprise) | ||
} | ||
|
||
func (ds *Datastore) DeleteAllEnterprises(ctx context.Context) error { | ||
ds.mu.Lock() | ||
ds.DeleteAllEnterprisesFuncInvoked = true | ||
ds.mu.Unlock() | ||
return ds.DeleteAllEnterprisesFunc(ctx) | ||
} | ||
|
||
func (ds *Datastore) DeleteOtherEnterprises(ctx context.Context, ID uint) error { | ||
ds.mu.Lock() | ||
ds.DeleteOtherEnterprisesFuncInvoked = true | ||
ds.mu.Unlock() | ||
return ds.DeleteOtherEnterprisesFunc(ctx, ID) | ||
} | ||
|
||
func (ds *Datastore) CreateDeviceTx(ctx context.Context, tx sqlx.ExtContext, device *android.Device) (*android.Device, error) { | ||
ds.mu.Lock() | ||
ds.CreateDeviceTxFuncInvoked = true | ||
ds.mu.Unlock() | ||
return ds.CreateDeviceTxFunc(ctx, tx, device) | ||
} | ||
|
||
func (ds *Datastore) UpdateDeviceTx(ctx context.Context, tx sqlx.ExtContext, device *android.Device) error { | ||
ds.mu.Lock() | ||
ds.UpdateDeviceTxFuncInvoked = true | ||
ds.mu.Unlock() | ||
return ds.UpdateDeviceTxFunc(ctx, tx, device) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package mock | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/fleetdm/fleet/v4/server/mdm/android" | ||
) | ||
|
||
func (s *Datastore) InitCommonMocks() { | ||
s.CreateEnterpriseFunc = func(ctx context.Context) (uint, error) { | ||
return 1, nil | ||
} | ||
s.UpdateEnterpriseFunc = func(ctx context.Context, enterprise *android.EnterpriseDetails) error { | ||
return nil | ||
} | ||
s.GetEnterpriseFunc = func(ctx context.Context) (*android.Enterprise, error) { | ||
return &android.Enterprise{}, nil | ||
} | ||
s.GetEnterpriseByIDFunc = func(ctx context.Context, ID uint) (*android.EnterpriseDetails, error) { | ||
return &android.EnterpriseDetails{}, nil | ||
} | ||
s.DeleteAllEnterprisesFunc = func(ctx context.Context) error { | ||
return nil | ||
} | ||
s.DeleteOtherEnterprisesFunc = func(ctx context.Context, ID uint) error { | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Automatically generated by mockimpl. DO NOT EDIT! | ||
|
||
package mock | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/fleetdm/fleet/v4/server/mdm/android" | ||
"google.golang.org/api/androidmanagement/v1" | ||
) | ||
|
||
var _ android.Proxy = (*Proxy)(nil) | ||
|
||
type SignupURLsCreateFunc func(callbackURL string) (*android.SignupDetails, error) | ||
|
||
type EnterprisesCreateFunc func(ctx context.Context, req android.ProxyEnterprisesCreateRequest) (string, string, error) | ||
|
||
type EnterprisesPoliciesPatchFunc func(enterpriseID string, policyName string, policy *androidmanagement.Policy) error | ||
|
||
type EnterprisesEnrollmentTokensCreateFunc func(enterpriseName string, token *androidmanagement.EnrollmentToken) (*androidmanagement.EnrollmentToken, error) | ||
|
||
type EnterpriseDeleteFunc func(enterpriseID string) error | ||
|
||
type Proxy struct { | ||
SignupURLsCreateFunc SignupURLsCreateFunc | ||
SignupURLsCreateFuncInvoked bool | ||
|
||
EnterprisesCreateFunc EnterprisesCreateFunc | ||
EnterprisesCreateFuncInvoked bool | ||
|
||
EnterprisesPoliciesPatchFunc EnterprisesPoliciesPatchFunc | ||
EnterprisesPoliciesPatchFuncInvoked bool | ||
|
||
EnterprisesEnrollmentTokensCreateFunc EnterprisesEnrollmentTokensCreateFunc | ||
EnterprisesEnrollmentTokensCreateFuncInvoked bool | ||
|
||
EnterpriseDeleteFunc EnterpriseDeleteFunc | ||
EnterpriseDeleteFuncInvoked bool | ||
|
||
mu sync.Mutex | ||
} | ||
|
||
func (p *Proxy) SignupURLsCreate(callbackURL string) (*android.SignupDetails, error) { | ||
p.mu.Lock() | ||
p.SignupURLsCreateFuncInvoked = true | ||
p.mu.Unlock() | ||
return p.SignupURLsCreateFunc(callbackURL) | ||
} | ||
|
||
func (p *Proxy) EnterprisesCreate(ctx context.Context, req android.ProxyEnterprisesCreateRequest) (string, string, error) { | ||
p.mu.Lock() | ||
p.EnterprisesCreateFuncInvoked = true | ||
p.mu.Unlock() | ||
return p.EnterprisesCreateFunc(ctx, req) | ||
} | ||
|
||
func (p *Proxy) EnterprisesPoliciesPatch(enterpriseID string, policyName string, policy *androidmanagement.Policy) error { | ||
p.mu.Lock() | ||
p.EnterprisesPoliciesPatchFuncInvoked = true | ||
p.mu.Unlock() | ||
return p.EnterprisesPoliciesPatchFunc(enterpriseID, policyName, policy) | ||
} | ||
|
||
func (p *Proxy) EnterprisesEnrollmentTokensCreate(enterpriseName string, token *androidmanagement.EnrollmentToken) (*androidmanagement.EnrollmentToken, error) { | ||
p.mu.Lock() | ||
p.EnterprisesEnrollmentTokensCreateFuncInvoked = true | ||
p.mu.Unlock() | ||
return p.EnterprisesEnrollmentTokensCreateFunc(enterpriseName, token) | ||
} | ||
|
||
func (p *Proxy) EnterpriseDelete(enterpriseID string) error { | ||
p.mu.Lock() | ||
p.EnterpriseDeleteFuncInvoked = true | ||
p.mu.Unlock() | ||
return p.EnterpriseDeleteFunc(enterpriseID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package mock | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/fleetdm/fleet/v4/server/mdm/android" | ||
"google.golang.org/api/androidmanagement/v1" | ||
) | ||
|
||
func (p *Proxy) InitCommonMocks() { | ||
p.EnterpriseDeleteFunc = func(enterpriseID string) error { | ||
return nil | ||
} | ||
p.SignupURLsCreateFunc = func(callbackURL string) (*android.SignupDetails, error) { | ||
return &android.SignupDetails{}, nil | ||
} | ||
p.EnterprisesCreateFunc = func(ctx context.Context, req android.ProxyEnterprisesCreateRequest) (string, string, error) { | ||
return "enterpriseName", "projects/project/topics/topic", nil | ||
} | ||
p.EnterprisesPoliciesPatchFunc = func(enterpriseID string, policyName string, policy *androidmanagement.Policy) error { | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package android | ||
|
||
import ( | ||
"context" | ||
|
||
"google.golang.org/api/androidmanagement/v1" | ||
) | ||
|
||
type Proxy interface { | ||
SignupURLsCreate(callbackURL string) (*SignupDetails, error) | ||
EnterprisesCreate(ctx context.Context, req ProxyEnterprisesCreateRequest) (string, string, error) | ||
EnterprisesPoliciesPatch(enterpriseID string, policyName string, policy *androidmanagement.Policy) error | ||
EnterprisesEnrollmentTokensCreate(enterpriseName string, token *androidmanagement.EnrollmentToken) (*androidmanagement.EnrollmentToken, error) | ||
EnterpriseDelete(enterpriseID string) error | ||
} | ||
|
||
type ProxyEnterprisesCreateRequest struct { | ||
androidmanagement.Enterprise | ||
EnterpriseToken string | ||
SignupUrlName string | ||
PubSubPushURL string | ||
} |
Oops, something went wrong.