Skip to content

Commit

Permalink
feat: Remove the sync endpoint in favor of patch project endpoint (#431)
Browse files Browse the repository at this point in the history
* Remove the sync endpoint in favor of patch project endpoint

* update sync command
  • Loading branch information
cdelst authored Sep 14, 2024
1 parent b3227d2 commit d3622a0
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 201 deletions.
5 changes: 3 additions & 2 deletions cmd/dev_server/dev_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package dev_server
import (
"fmt"

cmdAnalytics "github.com/launchdarkly/ldcli/cmd/analytics"
"github.com/launchdarkly/ldcli/internal/analytics"
"github.com/spf13/cobra"
"github.com/spf13/viper"

cmdAnalytics "github.com/launchdarkly/ldcli/cmd/analytics"
"github.com/launchdarkly/ldcli/internal/analytics"

"github.com/launchdarkly/ldcli/cmd/cliflags"
resourcecmd "github.com/launchdarkly/ldcli/cmd/resources"
"github.com/launchdarkly/ldcli/internal/dev_server"
Expand Down
14 changes: 9 additions & 5 deletions cmd/dev_server/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,21 @@ func NewSyncProjectCmd(client resources.Client) *cobra.Command {

func syncProject(client resources.Client) func(*cobra.Command, []string) error {
return func(cmd *cobra.Command, args []string) error {

path := getDevServerUrl() + "/dev/projects/" + viper.GetString(cliflags.ProjectFlag) + "/sync"
res, err := client.MakeUnauthenticatedRequest(
project := viper.GetString(cliflags.ProjectFlag)
path := fmt.Sprintf("%s/dev/projects/%s", getDevServerUrl(), project)
_, err := client.MakeUnauthenticatedRequest(
"PATCH",
path,
nil,
// An empty body sent to the patch project endpoint = sync project
[]byte("{}"),
)
if err != nil {
return output.NewCmdOutputError(err, viper.GetString(cliflags.OutputFlag))
}
fmt.Fprint(cmd.OutOrStdout(), string(res))
_, err = fmt.Fprintf(cmd.OutOrStdout(), "'%s' project synced successfully\n", project)
if err != nil {
return err
}

return nil
}
Expand Down
14 changes: 1 addition & 13 deletions internal/dev_server/api/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ paths:
items:
type: string
uniqueItems: true
/dev/projects/{projectKey}/sync:
patch:
summary: updates the flag state for the given project and source environment
operationId: patchSyncProject
parameters:
- $ref: "#/components/parameters/projectKey"
- $ref: "#/components/parameters/projectExpand"
responses:
200:
$ref: "#/components/responses/Project"
404:
description: No project found
/dev/projects/{projectKey}:
get:
summary: get the specified project and its configuration for syncing from the LaunchDarkly Service
Expand All @@ -49,7 +37,7 @@ paths:
404:
description: No project found
patch:
summary: updates the project context or sourceEnvironmentKey
summary: updates the project context or sourceEnvironmentKey then syncs. Input an empty body to only force a sync.
operationId: patchProject
parameters:
- $ref: "#/components/parameters/projectKey"
Expand Down
60 changes: 0 additions & 60 deletions internal/dev_server/api/patch_sync_project.go

This file was deleted.

121 changes: 4 additions & 117 deletions internal/dev_server/api/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/dev_server/ui/dist/index.html

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions internal/dev_server/ui/src/Sync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ import { FlagVariation } from './api.ts';

const syncProject = async (selectedProject: string) => {
const res = await fetch(
apiRoute(
`/dev/projects/${selectedProject}/sync?expand=availableVariations`,
),
apiRoute(`/dev/projects/${selectedProject}?expand=availableVariations`),
{
method: 'PATCH',
body: JSON.stringify({}),
},
);

Expand Down

0 comments on commit d3622a0

Please sign in to comment.