-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef56c38
commit c7d2801
Showing
7 changed files
with
121 additions
and
41 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 |
---|---|---|
@@ -1,65 +1,60 @@ | ||
package blueprint | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/port-labs/port-k8s-exporter/pkg/port" | ||
"github.com/port-labs/port-k8s-exporter/pkg/port/cli" | ||
) | ||
|
||
func NewBlueprint(portClient *cli.PortClient, blueprint port.Blueprint) (*port.Blueprint, error) { | ||
pb := &port.ResponseBody{} | ||
resp, err := portClient.Client.R(). | ||
SetResult(&pb). | ||
SetBody(blueprint). | ||
Post("v1/blueprints") | ||
_, err := portClient.Authenticate(context.Background(), portClient.ClientID, portClient.ClientSecret) | ||
if err != nil { | ||
return nil, err | ||
return nil, fmt.Errorf("error authenticating with Port: %v", err) | ||
} | ||
if !pb.OK { | ||
return nil, fmt.Errorf("failed to create blueprint, got: %s", resp.Body()) | ||
|
||
bp, err := cli.NewBlueprint(portClient, blueprint) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating Port blueprint: %v", err) | ||
} | ||
return &pb.Blueprint, nil | ||
return bp, nil | ||
} | ||
|
||
func PatchBlueprint(portClient *cli.PortClient, blueprint port.Blueprint) (*port.Blueprint, error) { | ||
pb := &port.ResponseBody{} | ||
resp, err := portClient.Client.R(). | ||
SetResult(&pb). | ||
SetBody(blueprint). | ||
Patch(fmt.Sprintf("v1/blueprints/%s", blueprint.Identifier)) | ||
_, err := portClient.Authenticate(context.Background(), portClient.ClientID, portClient.ClientSecret) | ||
if err != nil { | ||
return nil, err | ||
return nil, fmt.Errorf("error authenticating with Port: %v", err) | ||
} | ||
if !pb.OK { | ||
return nil, fmt.Errorf("failed to patch blueprint, got: %s", resp.Body()) | ||
|
||
bp, err := cli.PatchBlueprint(portClient, blueprint) | ||
if err != nil { | ||
return nil, fmt.Errorf("error patching Port blueprint: %v", err) | ||
} | ||
return &pb.Blueprint, nil | ||
return bp, nil | ||
} | ||
|
||
func DeleteBlueprint(portClient *cli.PortClient, blueprintIdentifier string) error { | ||
pb := &port.ResponseBody{} | ||
resp, err := portClient.Client.R(). | ||
SetResult(&pb). | ||
Delete(fmt.Sprintf("v1/blueprints/%s", blueprintIdentifier)) | ||
_, err := portClient.Authenticate(context.Background(), portClient.ClientID, portClient.ClientSecret) | ||
if err != nil { | ||
return err | ||
return fmt.Errorf("error authenticating with Port: %v", err) | ||
} | ||
if !pb.OK { | ||
return fmt.Errorf("failed to delete blueprint, got: %s", resp.Body()) | ||
|
||
err = cli.DeleteBlueprint(portClient, blueprintIdentifier) | ||
if err != nil { | ||
return fmt.Errorf("error deleting Port blueprint: %v", err) | ||
} | ||
return nil | ||
} | ||
|
||
func GetBlueprint(portClient *cli.PortClient, blueprintIdentifier string) (*port.Blueprint, error) { | ||
pb := &port.ResponseBody{} | ||
resp, err := portClient.Client.R(). | ||
SetResult(&pb). | ||
Get(fmt.Sprintf("v1/blueprints/%s", blueprintIdentifier)) | ||
_, err := portClient.Authenticate(context.Background(), portClient.ClientID, portClient.ClientSecret) | ||
if err != nil { | ||
return nil, err | ||
return nil, fmt.Errorf("error authenticating with Port: %v", err) | ||
} | ||
if !pb.OK { | ||
return nil, fmt.Errorf("failed to get blueprint, got: %s", resp.Body()) | ||
|
||
bp, err := cli.GetBlueprint(portClient, blueprintIdentifier) | ||
if err != nil { | ||
return nil, fmt.Errorf("error getting Port blueprint: %v", err) | ||
} | ||
return &pb.Blueprint, nil | ||
return bp, 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,64 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"github.com/port-labs/port-k8s-exporter/pkg/port" | ||
) | ||
|
||
func NewBlueprint(portClient *PortClient, blueprint port.Blueprint) (*port.Blueprint, error) { | ||
pb := &port.ResponseBody{} | ||
resp, err := portClient.Client.R(). | ||
SetResult(&pb). | ||
SetBody(blueprint). | ||
Post("v1/blueprints") | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !pb.OK { | ||
return nil, fmt.Errorf("failed to create blueprint, got: %s", resp.Body()) | ||
} | ||
return &pb.Blueprint, nil | ||
} | ||
|
||
func PatchBlueprint(portClient *PortClient, blueprint port.Blueprint) (*port.Blueprint, error) { | ||
pb := &port.ResponseBody{} | ||
resp, err := portClient.Client.R(). | ||
SetResult(&pb). | ||
SetBody(blueprint). | ||
Patch(fmt.Sprintf("v1/blueprints/%s", blueprint.Identifier)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !pb.OK { | ||
return nil, fmt.Errorf("failed to patch blueprint, got: %s", resp.Body()) | ||
} | ||
return &pb.Blueprint, nil | ||
} | ||
|
||
func DeleteBlueprint(portClient *PortClient, blueprintIdentifier string) error { | ||
pb := &port.ResponseBody{} | ||
resp, err := portClient.Client.R(). | ||
SetResult(&pb). | ||
Delete(fmt.Sprintf("v1/blueprints/%s", blueprintIdentifier)) | ||
if err != nil { | ||
return err | ||
} | ||
if !pb.OK { | ||
return fmt.Errorf("failed to delete blueprint, got: %s", resp.Body()) | ||
} | ||
return nil | ||
} | ||
|
||
func GetBlueprint(portClient *PortClient, blueprintIdentifier string) (*port.Blueprint, error) { | ||
pb := &port.ResponseBody{} | ||
resp, err := portClient.Client.R(). | ||
SetResult(&pb). | ||
Get(fmt.Sprintf("v1/blueprints/%s", blueprintIdentifier)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !pb.OK { | ||
return nil, fmt.Errorf("failed to get blueprint, got: %s", resp.Body()) | ||
} | ||
return &pb.Blueprint, 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,20 @@ | ||
package testing_init | ||
|
||
import ( | ||
"github.com/port-labs/port-k8s-exporter/pkg/config" | ||
"os" | ||
"path" | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
func init() { | ||
_, filename, _, _ := runtime.Caller(0) | ||
dir := path.Join(path.Dir(filename), "..") | ||
err := os.Chdir(dir) | ||
if err != nil { | ||
panic(err) | ||
} | ||
testing.Init() | ||
config.Init() | ||
} |