styra

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package styra holds a client and helpers for interacting with the Styra APIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecisionMappingsEquals

func DecisionMappingsEquals(dms1, dms2 map[string]DecisionMapping) bool

DecisionMappingsEquals asserts if two decisionmappings are equal.

func NewHTTPError

func NewHTTPError(statuscode int, body string) error

NewHTTPError creates a new HTTPError based on the statuscode and body from a failed call to the Styra API.

func SubjectsAreEqual

func SubjectsAreEqual(as []*Subject, bs []*Subject) bool

SubjectsAreEqual checks if two lists of Subjects are equal.

Types

type ClaimConfig

type ClaimConfig struct {
	IdentityProvider string `json:"identity_provider,omitempty"`
	Key              string `json:"key"`
	Value            string `json:"value"`
}

ClaimConfig represents a claim configuration.

type Client

type Client struct {
	HTTPClient http.Client
	URL        string
	// contains filtered or unexported fields
}

Client is a client for the Styra APIs.

func (*Client) CreateInvitation

func (c *Client) CreateInvitation(ctx context.Context, email bool, name string) (*CreateInvitationResponse, error)

CreateInvitation calls the POST /v1/invitations endpoint in the Styra API.

func (*Client) CreateRoleBinding

func (c *Client) CreateRoleBinding(
	ctx context.Context,
	request *CreateRoleBindingRequest,
) (*CreateRoleBindingResponse, error)

CreateRoleBinding calls the POST /v2/authz/rolebindings endpoint in the Styra API.

func (*Client) CreateSystem

func (c *Client) CreateSystem(ctx context.Context, request *CreateSystemRequest) (*CreateSystemResponse, error)

CreateSystem calls the POST /v1/systems endpoint in the Styra API.

func (*Client) CreateUpdateSecret

func (c *Client) CreateUpdateSecret(
	ctx context.Context,
	secretID string,
	createUpdateSecretsRequest *CreateUpdateSecretsRequest,
) (*CreateUpdateSecretResponse, error)

CreateUpdateSecret calls the PUT /v1/secrets/{secretId} endpoint in the Styra API.

func (*Client) DeleteDatasource

func (c *Client) DeleteDatasource(ctx context.Context, id string) (*DeleteDatasourceResponse, error)

DeleteDatasource calls the DELETE /v1/datasources/{datasource} endpoint in the Styra API.

func (*Client) DeletePolicy added in v0.9.5

func (c *Client) DeletePolicy(ctx context.Context, policyName string) (*DeletePolicyResponse, error)

DeletePolicy calls the DELETE /v1/policies/{policy} endpoint in the Styra API.

func (*Client) DeleteRoleBindingV2

func (c *Client) DeleteRoleBindingV2(ctx context.Context, id string) (*DeleteRoleBindingV2Response, error)

DeleteRoleBindingV2 calls the DELETE /v2/authz/rolebindings/{id}/subjects endpoint in the Styra API.

func (*Client) DeleteSystem

func (c *Client) DeleteSystem(ctx context.Context, id string) (*DeleteSystemResponse, error)

DeleteSystem calls the DELETE /v1/systems/{system} endpoint in the Styra API.

func (*Client) GetDatasource

func (c *Client) GetDatasource(ctx context.Context, id string) (*GetDatasourceResponse, error)

GetDatasource calls the GET /v1/datasources/{datasource} endpoint in the Styra API.

func (*Client) GetLibrary added in v0.10.0

func (c *Client) GetLibrary(ctx context.Context, id string) (*GetLibraryResponse, error)

GetLibrary calls the GET /v1/libraries/{id} endpoint in the Styra API.

func (*Client) GetOPAConfig

func (c *Client) GetOPAConfig(ctx context.Context, systemID string) (OPAConfig, error)

GetOPAConfig calls the GET /v1/systems/{systemId}/assets/opa-config endpoint in the Styra API.

func (*Client) GetSystem

func (c *Client) GetSystem(ctx context.Context, id string) (*GetSystemResponse, error)

GetSystem calls the GET /v1/systems{system} endpoint in the Styra API.

func (*Client) GetSystemByName added in v0.13.0

func (c *Client) GetSystemByName(ctx context.Context, name string) (*GetSystemResponse, error)

GetSystemByName calls the GET /v1/systems?name=<name> endpoint in the Styra API. If a system exists with this name it will be returned in the response. Otherwise, r.SystemConfig will be nil.

func (*Client) GetUser

func (c *Client) GetUser(ctx context.Context, name string) (*GetUserResponse, error)

GetUser calls the GET /v1/users/{userId} endpoint in the Styra API.

func (*Client) ListRoleBindingsV2

func (c *Client) ListRoleBindingsV2(
	ctx context.Context,
	params *ListRoleBindingsV2Params,
) (*ListRoleBindingsV2Response, error)

ListRoleBindingsV2 calls the GET /v2/authz/rolebindings endpoint in the Styra API.

func (*Client) UpdateRoleBindingSubjects

func (c *Client) UpdateRoleBindingSubjects(
	ctx context.Context,
	id string,
	request *UpdateRoleBindingSubjectsRequest,
) (*UpdateRoleBindingSubjectsResponse, error)

UpdateRoleBindingSubjects calls the POST /v2/authz/rolebindings/{id}/subjects endpoint in the Styra API.

func (*Client) UpdateSystem

func (c *Client) UpdateSystem(
	ctx context.Context,
	id string,
	request *UpdateSystemRequest,
) (*UpdateSystemResponse, error)

UpdateSystem calls the PUT /v1/systems/{system} endpoint in the Styra API.

func (*Client) UpsertDatasource

func (c *Client) UpsertDatasource(
	ctx context.Context,
	id string,
	request *UpsertDatasourceRequest,
) (*UpsertDatasourceResponse, error)

UpsertDatasource calls the PUT /v1/datasources/{datasource} endpoint in the Styra API.

func (*Client) UpsertLibrary added in v0.10.0

func (c *Client) UpsertLibrary(ctx context.Context, id string, request *UpsertLibraryRequest,
) (*UpsertLibraryResponse, error)

UpsertLibrary calls the PUT /v1/libraries/{id} endpoint in the Styra API.

func (*Client) VerifyGitConfiguration

func (c *Client) VerifyGitConfiguration(
	ctx context.Context,
	request *VerfiyGitConfigRequest,
) (*VerfiyGitConfigResponse, error)

VerifyGitConfiguration calls the POST /v1/systems/source-control/verify-config endpoint in the Styra API.

type ClientInterface

type ClientInterface interface {
	GetSystem(ctx context.Context, id string) (*GetSystemResponse, error)
	GetSystemByName(ctx context.Context, name string) (*GetSystemResponse, error)

	CreateUpdateSecret(
		ctx context.Context,
		secretID string,
		request *CreateUpdateSecretsRequest,
	) (*CreateUpdateSecretResponse, error)

	GetUser(ctx context.Context, name string) (*GetUserResponse, error)

	CreateInvitation(ctx context.Context, email bool, name string) (*CreateInvitationResponse, error)

	ListRoleBindingsV2(ctx context.Context, params *ListRoleBindingsV2Params) (*ListRoleBindingsV2Response, error)

	CreateRoleBinding(ctx context.Context, request *CreateRoleBindingRequest) (*CreateRoleBindingResponse, error)

	UpdateRoleBindingSubjects(
		ctx context.Context,
		id string,
		request *UpdateRoleBindingSubjectsRequest,
	) (*UpdateRoleBindingSubjectsResponse, error)

	DeleteRoleBindingV2(ctx context.Context, id string) (*DeleteRoleBindingV2Response, error)

	GetDatasource(ctx context.Context, id string) (*GetDatasourceResponse, error)

	UpsertDatasource(
		ctx context.Context,
		id string,
		request *UpsertDatasourceRequest,
	) (*UpsertDatasourceResponse, error)

	DeleteDatasource(ctx context.Context, id string) (*DeleteDatasourceResponse, error)

	GetLibrary(ctx context.Context, id string) (*GetLibraryResponse, error)
	UpsertLibrary(ctx context.Context, id string, request *UpsertLibraryRequest) (*UpsertLibraryResponse, error)

	UpdateSystem(ctx context.Context, id string, request *UpdateSystemRequest) (*UpdateSystemResponse, error)

	DeleteSystem(ctx context.Context, id string) (*DeleteSystemResponse, error)

	CreateSystem(ctx context.Context, request *CreateSystemRequest) (*CreateSystemResponse, error)

	GetOPAConfig(ctx context.Context, systemID string) (OPAConfig, error)

	VerifyGitConfiguration(ctx context.Context, request *VerfiyGitConfigRequest) (*VerfiyGitConfigResponse, error)

	DeletePolicy(ctx context.Context, policyName string) (*DeletePolicyResponse, error)
}

ClientInterface defines the interface for the Styra client.

func New

func New(url string, token string) ClientInterface

New creates a new Styra ClientInterface.

type CreateInvitationRequest

type CreateInvitationRequest struct {
	UserID string `json:"user_id"`
}

CreateInvitationRequest is the request body for the POST /v1/invitations endpoint in the Styra API.

type CreateInvitationResponse

type CreateInvitationResponse struct {
	StatusCode int
	Body       []byte
}

CreateInvitationResponse is the response type for calls to the POST /v1/invitations endpoint in the Styra API.

type CreateRoleBindingRequest

type CreateRoleBindingRequest struct {
	ResourceFilter *ResourceFilter `json:"resource_filter"`
	RoleID         Role            `json:"role_id"`
	Subjects       []*Subject      `json:"subjects"`
}

CreateRoleBindingRequest is the request body for the POST /v2/authz/rolebindings endpoint in the Styra API.

type CreateRoleBindingResponse

type CreateRoleBindingResponse struct {
	Rolebinding *RoleBindingConfig `json:"rolebinding"`
	StatusCode  int
	Body        []byte
}

CreateRoleBindingResponse is the response body for the POST /v2/authz/rolebindings endpoint in the Styra API.

type CreateSystemRequest

type CreateSystemRequest struct {
	*SystemConfig
}

CreateSystemRequest is the request body for the POST /v1/systems endpoint in the Styra API.

type CreateSystemResponse

type CreateSystemResponse struct {
	StatusCode   int
	Body         []byte
	SystemConfig *SystemConfig
}

CreateSystemResponse is the response body for the POST /v1/systems endpoint in the Styra API.

type CreateUpdateSecretResponse

type CreateUpdateSecretResponse struct {
	StatusCode int
	Body       []byte
}

CreateUpdateSecretResponse is the response type for calls to the PUT /v1/secrets/{secretId} endpoint in the Styra API.

type CreateUpdateSecretsRequest

type CreateUpdateSecretsRequest struct {
	Description string `json:"description"`
	Name        string `json:"name"`
	Secret      string `json:"secret"`
}

CreateUpdateSecretsRequest is the response body for the PUT /v1/secrets/{secretId} endpoint in the Styra API.

type DatasourceConfig

type DatasourceConfig struct {
	Category    string `json:"category"`
	Type        string `json:"type,omitempty"`
	Optional    bool   `json:"optional,omitempty"`
	Commit      string `json:"commit,omitempty"`
	Credentials string `json:"credentials,omitempty"`
	Description string `json:"description,omitempty"`
	Enabled     bool   `json:"enabled,omitempty"`
	ID          string `json:"id,omitempty"`
	Path        string `json:"path,omitempty"`
	Reference   string `json:"reference,omitempty"`
	URL         string `json:"url,omitempty"`
}

DatasourceConfig defines the structure of a datasource configuration.

type DecisionMapping

type DecisionMapping struct {
	Allowed *DecisionMappingAllowed `json:"allowed,omitempty"`
	Columns []DecisionMappingColumn `json:"columns,omitempty"`
	Reason  *DecisionMappingReason  `json:"reason,omitempty"`
}

DecisionMapping defines the structure of a decision mapping.

type DecisionMappingAllowed

type DecisionMappingAllowed struct {
	Expected interface{} `json:"expected,omitempty"`
	Negated  bool        `json:"negated,omitempty"`
	Path     string      `json:"path"`
}

DecisionMappingAllowed defines the structure of the allow element in a decision mapping.

type DecisionMappingColumn

type DecisionMappingColumn struct {
	Key  string `json:"key"`
	Path string `json:"path"`
	Type string `json:"type,omitempty"`
}

DecisionMappingColumn defines the structure of the column element in a decision mapping.

type DecisionMappingReason

type DecisionMappingReason struct {
	Path string `json:"path"`
}

DecisionMappingReason defines the structure of the reason element in a decision mapping.

type DeleteDatasourceResponse

type DeleteDatasourceResponse struct {
	StatusCode int
	Body       []byte
}

DeleteDatasourceResponse is the response type for calls to the DELETE /v1/datasources/{datasource} endpoint in the Styra API.

type DeletePolicyResponse added in v0.9.5

type DeletePolicyResponse struct {
	StatusCode int
	Body       []byte
}

DeletePolicyResponse is the response type for calls to the DELETE /v1/policies/{policy} endpoint in the Styra API.

type DeleteRoleBindingV2Response

type DeleteRoleBindingV2Response struct {
	StatusCode int
	Body       []byte
}

DeleteRoleBindingV2Response is the response type for calls to the DELETE /v2/authz/rolebindings/{id}/subjects endpoint in the Styra API

type DeleteSystemResponse

type DeleteSystemResponse struct {
	StatusCode int
	Body       []byte
}

DeleteSystemResponse is the response type for calls to the DELETE /v1/systems/{system} endpoint in the Styra API.

type DeploymentParameters added in v0.6.0

type DeploymentParameters struct {
	Discovery *v1beta1.DiscoveryOverrides `json:"discovery,omitempty"`
}

DeploymentParameters are additional OPA deployment parameters for the system.

type GetDatasourceResponse

type GetDatasourceResponse struct {
	StatusCode       int
	Body             []byte
	DatasourceConfig *DatasourceConfig
}

GetDatasourceResponse stores the response body for the GET /v1/datasources/{datasource} endpoint in the Styra API.

type GetLibraryResponse added in v0.10.0

type GetLibraryResponse struct {
	Statuscode            int
	Body                  []byte
	LibraryEntityExpanded *LibraryEntityExpanded
}

GetLibraryResponse is the response type for calls to the GET /v1/libraries/{id} endpoint in the Styra API.

type GetSystemResponse

type GetSystemResponse struct {
	StatusCode   int
	Body         []byte
	SystemConfig *SystemConfig
}

GetSystemResponse is the response body for the GET /v1/systems{system} endpoint in the Styra API.

type GetUserResponse

type GetUserResponse struct {
	StatusCode int
	Body       []byte
}

GetUserResponse is the response type for calls to the GET /v1/users endpoint in the Styra API.

type GitRepoConfig

type GitRepoConfig struct {
	Commit      string `json:"commit"`
	Credentials string `json:"credentials"`
	Path        string `json:"path"`
	Reference   string `json:"reference"`
	URL         string `json:"url"`
}

GitRepoConfig defines the structure of a git repo configuration.

type HTTPError

type HTTPError struct {
	StatusCode int
	Body       string
	Message    string `yaml:"message,omitempty"`
}

HTTPError represents an error that occurred when interacting with the Styra API.

func (*HTTPError) Error

func (styraerror *HTTPError) Error() string

Error implements the error interface.

type LibraryDatasourceConfig added in v0.10.0

type LibraryDatasourceConfig struct {
	Category string `json:"category"`
	ID       string `json:"id"`
}

LibraryDatasourceConfig defines metadata of a datasource

type LibraryEntityExpanded added in v0.10.0

type LibraryEntityExpanded struct {
	DataSources   []LibraryDatasourceConfig   `json:"datasources"`
	Description   string                      `json:"description"`
	ID            string                      `json:"id"`
	ReadOnly      bool                        `json:"read_only"`
	SourceControl *LibrarySourceControlConfig `json:"source_control"`
}

LibraryEntityExpanded is the type that defines of a Library

type LibraryGitRepoConfig added in v0.10.0

type LibraryGitRepoConfig struct {
	Commit      string `json:"commit"`
	Credentials string `json:"credentials"`
	Path        string `json:"path"`
	Reference   string `json:"reference"`
	URL         string `json:"url"`
}

LibraryGitRepoConfig defines the Git configurations a library can be defined by

type LibrarySourceControlConfig added in v0.10.0

type LibrarySourceControlConfig struct {
	LibraryOrigin *LibraryGitRepoConfig `json:"library_origin"`
}

LibrarySourceControlConfig is a struct from styra where we only use a single field but kept for clarity when comparing to the API

type ListRoleBindingsV2Params

type ListRoleBindingsV2Params struct {
	ResourceKind RoleBindingKind
	ResourceID   string
	RoleID       Role
	SubjectKind  SubjectKind
}

ListRoleBindingsV2Params is the URL params for the GET /v2/authz/rolebindings endpoint in the Styra API.

type ListRoleBindingsV2Response

type ListRoleBindingsV2Response struct {
	Rolebindings []*RoleBindingConfig `json:"rolebindings"`
	StatusCode   int
	Body         []byte
}

ListRoleBindingsV2Response is the response body for the GET /v2/authz/rolebindings endpoint in the Styra API.

type OPAConfig

type OPAConfig struct {
	HostURL    string
	Token      string
	SystemID   string
	SystemType string
}

OPAConfig stores the information retrieved from calling the GET /v1/systems/{systemId}/assets/opa-config endpoint in the Styra API.

type ResourceFilter

type ResourceFilter struct {
	ID   string          `json:"id"`
	Kind RoleBindingKind `json:"kind"`
}

ResourceFilter is a resource filter. This is used to limit what resources are targeted in the Styra APIs.

type Role

type Role string

Role represents a role in Styra.

const (
	// RoleSystemViewer is the Styra SystemViewer role.
	RoleSystemViewer Role = "SystemViewer"

	// RoleSystemPolicyEditor is the Styra SystemPolicyEditor role.
	RoleSystemPolicyEditor Role = "SystemPolicyEditor"

	// RoleLibraryViewer is the Styra LibraryViewer role.
	RoleLibraryViewer Role = "LibraryViewer"
)

type RoleBindingConfig

type RoleBindingConfig struct {
	ID       string     `json:"id"`
	Subjects []*Subject `json:"subjects"`
	RoleID   Role       `json:"role_id"`
}

RoleBindingConfig defines the structure of a rolebinding configuration. This is used for binding a list of subjects to a specific role.

type RoleBindingKind

type RoleBindingKind string

RoleBindingKind is the kind of the role binding.

const (
	// RoleBindingKindSystem is a RoleBindingKind used when the role is for a
	// System.
	RoleBindingKindSystem RoleBindingKind = "system"
	// RoleBindingKindLibrary is a RoleBindingKind used when the role is for a
	// Library.
	RoleBindingKindLibrary RoleBindingKind = "library"
)

type SourceControlConfig

type SourceControlConfig struct {
	Origin GitRepoConfig `json:"origin"`
}

SourceControlConfig defines the structure of a source control configuration.

type Subject

type Subject struct {
	ID          string       `json:"id,omitempty"`
	Kind        SubjectKind  `json:"kind"`
	ClaimConfig *ClaimConfig `json:"claim_config,omitempty"`
}

Subject specifies a subject.

type SubjectKind

type SubjectKind string

SubjectKind is the kind of a subject.

const (
	// SubjectKindUser is a SubjectKind used when the subject is a user.
	SubjectKindUser SubjectKind = "user"

	// SubjectKindClaim is a SubjectKind used when the subject is a claim.
	SubjectKindClaim SubjectKind = "claim"
)

type SystemConfig

type SystemConfig struct {
	DecisionMappings     map[string]DecisionMapping `json:"decision_mappings,omitempty"`
	Description          string                     `json:"description,omitempty"`
	Name                 string                     `json:"name"`
	ReadOnly             bool                       `json:"read_only"`
	SourceControl        *SourceControlConfig       `json:"source_control,omitempty"`
	Type                 string                     `json:"type"`
	ID                   string                     `json:"id"`
	Datasources          []*DatasourceConfig        `json:"datasources,omitempty"`
	DeploymentParameters *DeploymentParameters      `json:"deployment_parameters,omitempty"`
}

SystemConfig represents the configuration of a system in the Styra APIs.

type UpdateRoleBindingSubjectsRequest

type UpdateRoleBindingSubjectsRequest struct {
	Subjects []*Subject `json:"subjects"`
}

UpdateRoleBindingSubjectsRequest is the request body for the POST /v2/authz/rolebindings/{id}/subjects endpoint in the Styra API.

type UpdateRoleBindingSubjectsResponse

type UpdateRoleBindingSubjectsResponse struct {
	StatusCode int
	Body       []byte
}

UpdateRoleBindingSubjectsResponse is the response type for calls to the POST /v2/authz/rolebindings/{id}/subjects endpoint in the Styra API.

type UpdateSystemRequest

type UpdateSystemRequest struct {
	*SystemConfig
}

UpdateSystemRequest is the request body for the the PUT /v1/systems/{system} endpoint in the Styra API.

type UpdateSystemResponse

type UpdateSystemResponse struct {
	StatusCode   int
	Body         []byte
	SystemConfig *SystemConfig
}

UpdateSystemResponse is the response body for the PUT /v1/systems/{system} endpoint in the Styra API.

type UpsertDatasourceRequest

type UpsertDatasourceRequest struct {
	Category    string `json:"category"`
	Description string `json:"description,omitempty"`
	Enabled     bool   `json:"enabled"`
	Commit      string `json:"commit,omitempty"`
	Credentials string `json:"credentials,omitempty"`
	Reference   string `json:"reference,omitempty"`
	URL         string `json:"url,omitempty"`
	Path        string `json:"path,omitempty"`
}

UpsertDatasourceRequest is the request body for the PUT /v1/datasources/{datasource} endpoint in the Styra API.

type UpsertDatasourceResponse

type UpsertDatasourceResponse struct {
	StatusCode int
	Body       []byte
}

UpsertDatasourceResponse is the response type for calls to the PUT /v1/datasources/{datasource} endpoint in the Styra API.

type UpsertLibraryRequest added in v0.10.0

type UpsertLibraryRequest struct {
	Description   string                      `json:"description"`
	ReadOnly      bool                        `json:"read_only"`
	SourceControl *LibrarySourceControlConfig `json:"source_control"`
}

UpsertLibraryRequest is the request body for the PUT /v1/libraries/{id} endpoint in the Styra API.

type UpsertLibraryResponse added in v0.10.0

type UpsertLibraryResponse struct {
	StatusCode int
	Body       []byte
}

UpsertLibraryResponse is the response body for the PUT /v1/libraries/{id} endpoint in the Styra API.

type VerfiyGitConfigRequest

type VerfiyGitConfigRequest struct {
	Commit      string `json:"commit"`
	ID          string `json:"id"`
	Credentials string `json:"credentials"`
	Path        string `json:"path"`
	Reference   string `json:"reference"`
	URL         string `json:"url"`
}

VerfiyGitConfigRequest is the request body for the POST /v1/systems/source-control/verify-config endpoint in the Styra API.

type VerfiyGitConfigResponse

type VerfiyGitConfigResponse struct {
	StatusCode int
	Body       []byte
}

VerfiyGitConfigResponse is the response type for calls to the POST /v1/systems/source-control/verify-config endpoint in the Styra API.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL