-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add environment command line tool for exporting and importing project…
… config (#302)
- Loading branch information
1 parent
d751768
commit cd0f0f5
Showing
16 changed files
with
609 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package mgmt | ||
|
||
import ( | ||
"github.com/descope/go-sdk/descope/api" | ||
"github.com/descope/go-sdk/descope/internal/utils" | ||
) | ||
|
||
type projectBody struct { | ||
Files map[string]any `json:"files"` | ||
} | ||
|
||
type project struct { | ||
managementBase | ||
} | ||
|
||
func (p *project) ExportRaw() (map[string]any, error) { | ||
body := map[string]any{} | ||
res, err := p.client.DoPostRequest(api.Routes.ManagementProjectExport(), body, nil, p.conf.ManagementKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var export projectBody | ||
if err := utils.Unmarshal([]byte(res.BodyStr), &export); err != nil { | ||
return nil, err // notest | ||
} | ||
return export.Files, nil | ||
} | ||
|
||
func (p *project) ImportRaw(files map[string]any) error { | ||
body := projectBody{Files: files} | ||
_, err := p.client.DoPostRequest(api.Routes.ManagementProjectImport(), body, nil, p.conf.ManagementKey) | ||
return err | ||
} |
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,34 @@ | ||
package mgmt | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/descope/go-sdk/descope/tests/helpers" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestProjectExportRaw(t *testing.T) { | ||
mgmt := newTestMgmt(nil, helpers.DoOkWithBody(func(r *http.Request) { | ||
require.Equal(t, r.Header.Get("Authorization"), "Bearer a:key") | ||
req := map[string]any{} | ||
require.NoError(t, helpers.ReadBody(r, &req)) | ||
}, map[string]any{"files": map[string]any{"foo": "bar"}})) | ||
m, err := mgmt.Project().ExportRaw() | ||
require.NoError(t, err) | ||
require.NotNil(t, m) | ||
require.Equal(t, "bar", m["foo"]) | ||
} | ||
|
||
func TestProjectImportRaw(t *testing.T) { | ||
mgmt := newTestMgmt(nil, helpers.DoOk(func(r *http.Request) { | ||
require.Equal(t, r.Header.Get("Authorization"), "Bearer a:key") | ||
req := map[string]any{} | ||
require.NoError(t, helpers.ReadBody(r, &req)) | ||
files, ok := req["files"].(map[string]any) | ||
require.True(t, ok) | ||
require.Equal(t, "bar", files["foo"]) | ||
})) | ||
err := mgmt.Project().ImportRaw(map[string]any{"foo": "bar"}) | ||
require.NoError(t, err) | ||
} |
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
Oops, something went wrong.