-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Move endpoints to their own files, rename (#429)
* Rename operations to make more sense * Move methods to separate files
- Loading branch information
Showing
12 changed files
with
623 additions
and
553 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/launchdarkly/ldcli/internal/dev_server/model" | ||
) | ||
|
||
func (s server) DeleteFlagOverride(ctx context.Context, request DeleteFlagOverrideRequestObject) (DeleteFlagOverrideResponseObject, error) { | ||
store := model.StoreFromContext(ctx) | ||
err := store.DeactivateOverride(ctx, request.ProjectKey, request.FlagKey) | ||
if err != nil { | ||
if errors.Is(err, model.ErrNotFound) { | ||
return DeleteFlagOverride404Response{}, nil | ||
} | ||
return nil, err | ||
} | ||
return DeleteFlagOverride204Response{}, 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,22 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/launchdarkly/ldcli/internal/dev_server/model" | ||
) | ||
|
||
func (s server) DeleteProject(ctx context.Context, request DeleteProjectRequestObject) (DeleteProjectResponseObject, error) { | ||
store := model.StoreFromContext(ctx) | ||
deleted, err := store.DeleteDevProject(ctx, request.ProjectKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !deleted { | ||
return DeleteProject404JSONResponse{ErrorResponseJSONResponse{ | ||
Code: "not_found", | ||
Message: "project not found", | ||
}}, nil | ||
} | ||
return DeleteProject204Response{}, 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,33 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/launchdarkly/ldcli/internal/dev_server/model" | ||
) | ||
|
||
func (s server) GetEnvironments(ctx context.Context, request GetEnvironmentsRequestObject) (GetEnvironmentsResponseObject, error) { | ||
store := model.StoreFromContext(ctx) | ||
project, err := store.GetDevProject(ctx, request.ProjectKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if project == nil { | ||
return GetEnvironments404JSONResponse{}, nil | ||
} | ||
|
||
environments, err := model.GetEnvironmentsForProject(ctx, project.Key) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var envReps []Environment | ||
for _, env := range environments { | ||
envReps = append(envReps, Environment{ | ||
Key: env.Key, | ||
Name: env.Name, | ||
}) | ||
} | ||
|
||
return GetEnvironments200JSONResponse(envReps), 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,60 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/launchdarkly/ldcli/internal/dev_server/model" | ||
) | ||
|
||
func (s server) GetProject(ctx context.Context, request GetProjectRequestObject) (GetProjectResponseObject, error) { | ||
store := model.StoreFromContext(ctx) | ||
project, err := store.GetDevProject(ctx, request.ProjectKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if project == nil { | ||
return GetProject404Response{}, nil | ||
} | ||
|
||
response := ProjectJSONResponse{ | ||
LastSyncedFromSource: project.LastSyncTime.Unix(), | ||
Context: project.Context, | ||
SourceEnvironmentKey: project.SourceEnvironmentKey, | ||
FlagsState: &project.AllFlagsState, | ||
} | ||
|
||
if request.Params.Expand != nil { | ||
for _, item := range *request.Params.Expand { | ||
if item == "overrides" { | ||
overrides, err := store.GetOverridesForProject(ctx, request.ProjectKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
respOverrides := make(model.FlagsState) | ||
for _, override := range overrides { | ||
if !override.Active { | ||
continue | ||
} | ||
respOverrides[override.FlagKey] = model.FlagState{ | ||
Value: override.Value, | ||
Version: override.Version, | ||
} | ||
} | ||
response.Overrides = &respOverrides | ||
} | ||
if item == "availableVariations" { | ||
availableVariations, err := store.GetAvailableVariationsForProject(ctx, request.ProjectKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
respAvailableVariations := availableVariationsToResponseFormat(availableVariations) | ||
response.AvailableVariations = &respAvailableVariations | ||
} | ||
} | ||
|
||
} | ||
|
||
return GetProject200JSONResponse{ | ||
response, | ||
}, 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,19 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/launchdarkly/ldcli/internal/dev_server/model" | ||
) | ||
|
||
func (s server) GetProjects(ctx context.Context, _ GetProjectsRequestObject) (GetProjectsResponseObject, error) { | ||
store := model.StoreFromContext(ctx) | ||
projectKeys, err := store.GetDevProjectKeys(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if projectKeys == nil { | ||
projectKeys = make([]string, 0) // HACK to make the json behavior compatible with go. | ||
} | ||
return GetProjects200JSONResponse(projectKeys), 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,60 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/launchdarkly/ldcli/internal/dev_server/model" | ||
) | ||
|
||
func (s server) PatchProject(ctx context.Context, request PatchProjectRequestObject) (PatchProjectResponseObject, error) { | ||
store := model.StoreFromContext(ctx) | ||
project, err := model.UpdateProject(ctx, request.ProjectKey, request.Body.Context, request.Body.SourceEnvironmentKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if project.Key == "" && project.SourceEnvironmentKey == "" { | ||
return PatchProject404Response{}, nil | ||
} | ||
|
||
response := ProjectJSONResponse{ | ||
LastSyncedFromSource: project.LastSyncTime.Unix(), | ||
Context: project.Context, | ||
SourceEnvironmentKey: project.SourceEnvironmentKey, | ||
FlagsState: &project.AllFlagsState, | ||
} | ||
|
||
if request.Params.Expand != nil { | ||
for _, item := range *request.Params.Expand { | ||
if item == "overrides" { | ||
overrides, err := store.GetOverridesForProject(ctx, request.ProjectKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
respOverrides := make(model.FlagsState) | ||
for _, override := range overrides { | ||
if !override.Active { | ||
continue | ||
} | ||
respOverrides[override.FlagKey] = model.FlagState{ | ||
Value: override.Value, | ||
Version: override.Version, | ||
} | ||
} | ||
response.Overrides = &respOverrides | ||
} | ||
if item == "availableVariations" { | ||
availableVariations, err := store.GetAvailableVariationsForProject(ctx, request.ProjectKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
respAvailableVariations := availableVariationsToResponseFormat(availableVariations) | ||
response.AvailableVariations = &respAvailableVariations | ||
} | ||
} | ||
|
||
} | ||
|
||
return PatchProject200JSONResponse{ | ||
response, | ||
}, 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,60 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/launchdarkly/ldcli/internal/dev_server/model" | ||
) | ||
|
||
func (s server) PatchSyncProject(ctx context.Context, request PatchSyncProjectRequestObject) (PatchSyncProjectResponseObject, error) { | ||
store := model.StoreFromContext(ctx) | ||
project, err := model.UpdateProject(ctx, request.ProjectKey, nil, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if project.Key == "" && project.SourceEnvironmentKey == "" { | ||
return PatchSyncProject404Response{}, nil | ||
} | ||
|
||
response := ProjectJSONResponse{ | ||
LastSyncedFromSource: project.LastSyncTime.Unix(), | ||
Context: project.Context, | ||
SourceEnvironmentKey: project.SourceEnvironmentKey, | ||
FlagsState: &project.AllFlagsState, | ||
} | ||
|
||
if request.Params.Expand != nil { | ||
for _, item := range *request.Params.Expand { | ||
if item == "overrides" { | ||
overrides, err := store.GetOverridesForProject(ctx, request.ProjectKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
respOverrides := make(model.FlagsState) | ||
for _, override := range overrides { | ||
if !override.Active { | ||
continue | ||
} | ||
respOverrides[override.FlagKey] = model.FlagState{ | ||
Value: override.Value, | ||
Version: override.Version, | ||
} | ||
} | ||
response.Overrides = &respOverrides | ||
} | ||
if item == "availableVariations" { | ||
availableVariations, err := store.GetAvailableVariationsForProject(ctx, request.ProjectKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
respAvailableVariations := availableVariationsToResponseFormat(availableVariations) | ||
response.AvailableVariations = &respAvailableVariations | ||
} | ||
} | ||
|
||
} | ||
|
||
return PatchSyncProject200JSONResponse{ | ||
response, | ||
}, nil | ||
} |
Oops, something went wrong.