Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cmd/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
artifactImportCmd.Flags().StringP("name", "n", "", "Artifact name")
artifactImportCmd.Flags().StringP("type", "t", "", "Artifact type")
artifactImportCmd.Flags().StringP("file", "f", "", "Artifact file")
artifactImportCmd.MarkFlagRequired("name")

Check failure on line 40 in cmd/artifact.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `artifactImportCmd.MarkFlagRequired` is not checked (errcheck)
artifactImportCmd.MarkFlagRequired("type")

Check failure on line 41 in cmd/artifact.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `artifactImportCmd.MarkFlagRequired` is not checked (errcheck)
artifactImportCmd.MarkFlagRequired("file")

Check failure on line 42 in cmd/artifact.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `artifactImportCmd.MarkFlagRequired` is not checked (errcheck)

// Get
artifactGetCmd := &cobra.Command{
Expand Down Expand Up @@ -176,11 +176,11 @@
}

func renderArtifact(artifact *api.Artifact) error {
specsJSON := "{}"
if artifact.Specs != nil {
specsBytes, err := json.MarshalIndent(artifact.Specs, "", " ")
prettyPayload := "{}"
if artifact.Payload != nil {
payloadBytes, err := json.MarshalIndent(artifact.Payload, "", " ")
if err == nil {
specsJSON = string(specsBytes)
prettyPayload = string(payloadBytes)
}
}

Expand All @@ -200,7 +200,7 @@
Type string
Field string
Origin string
SpecsJSON string
Payload string
Formats []string
CreatedAt string
UpdatedAt string
Expand All @@ -212,7 +212,7 @@
Type: artifact.Type,
Field: artifact.Field,
Origin: artifact.Origin,
SpecsJSON: specsJSON,
Payload: prettyPayload,
Formats: artifact.Formats,
CreatedAt: artifact.CreatedAt.Format("2006-01-02 15:04:05"),
UpdatedAt: artifact.UpdatedAt.Format("2006-01-02 15:04:05"),
Expand Down
4 changes: 2 additions & 2 deletions cmd/templates/artifact.get.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

{{if .Formats}}**Available Formats:** {{range $i, $f := .Formats}}{{if $i}}, {{end}}{{$f}}{{end}}{{end}}

{{if ne .SpecsJSON "{}"}}## Specs
{{if ne .Payload "{}"}}## Payload
```json
{{.SpecsJSON}}
{{.Payload}}
```
{{end}}
8 changes: 4 additions & 4 deletions pkg/api/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Artifact struct {
Name string `json:"name"`
Type string `json:"type"`
Field string `json:"field,omitempty"`
Specs map[string]any `json:"specs,omitempty"`
Payload map[string]any `json:"payload,omitempty"`
Formats []string `json:"formats,omitempty"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitempty"`
Expand All @@ -34,8 +34,8 @@ type ArtifactPackage struct {
Slug string `json:"slug"`
}

func CreateArtifact(ctx context.Context, mdClient *client.Client, artifactName string, artifactType string, artifactData map[string]any, artifactSpecs map[string]any) (*Artifact, error) {
response, err := createArtifact(ctx, mdClient.GQL, mdClient.Config.OrganizationID, artifactName, artifactSpecs, artifactType, artifactData)
func CreateArtifact(ctx context.Context, mdClient *client.Client, artifactName string, artifactType string, artifactPayload map[string]any) (*Artifact, error) {
response, err := createArtifact(ctx, mdClient.GQL, mdClient.Config.OrganizationID, artifactName, artifactType, artifactPayload)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -75,7 +75,7 @@ func (response *getArtifactResponse) toArtifact() *Artifact {
Name: response.Artifact.Name,
Type: response.Artifact.Type,
Field: response.Artifact.Field,
Specs: response.Artifact.Specs,
Payload: response.Artifact.Payload,
Formats: response.Artifact.Formats,
CreatedAt: response.Artifact.CreatedAt,
UpdatedAt: response.Artifact.UpdatedAt,
Expand Down
39 changes: 35 additions & 4 deletions pkg/api/artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,37 @@ import (
"github.com/massdriver-cloud/massdriver-sdk-go/massdriver/config"
)

func TestCreateArtifact(t *testing.T) {
gqlClient := gqlmock.NewClientWithSingleJSONResponse(map[string]any{
"data": map[string]any{
"createArtifact": map[string]any{
"result": map[string]any{
"id": "artifact-id",
"name": "artifact-name",
},
"successful": true,
},
},
})
mdClient := client.Client{
GQL: gqlClient,
}

got, err := api.CreateArtifact(t.Context(), &mdClient, "artifact-name", "artifact-type", map[string]any{})
if err != nil {
t.Fatal(err)
}

want := &api.Artifact{
Name: "artifact-name",
ID: "artifact-id",
}

if !reflect.DeepEqual(got, want) {
t.Errorf("Wanted %v but got %v", want, got)
}
}

func TestGetArtifact(t *testing.T) {
type test struct {
name string
Expand All @@ -26,7 +57,7 @@ func TestGetArtifact(t *testing.T) {
"name": "my-artifact",
"type": "aws-s3",
"field": "bucket",
"specs": map[string]any{
"payload": map[string]any{
"bucket": "my-bucket",
},
"formats": []string{"json", "yaml"},
Expand All @@ -48,7 +79,7 @@ func TestGetArtifact(t *testing.T) {
Name: "my-artifact",
Type: "aws-s3",
Field: "bucket",
Specs: map[string]any{
Payload: map[string]any{
"bucket": "my-bucket",
},
Formats: []string{"json", "yaml"},
Expand Down Expand Up @@ -100,8 +131,8 @@ func TestGetArtifact(t *testing.T) {
if got.Origin != tc.want.Origin {
t.Errorf("got Origin %v, want %v", got.Origin, tc.want.Origin)
}
if !reflect.DeepEqual(got.Specs, tc.want.Specs) {
t.Errorf("got Specs %v, want %v", got.Specs, tc.want.Specs)
if !reflect.DeepEqual(got.Payload, tc.want.Payload) {
t.Errorf("got Payload %v, want %v", got.Payload, tc.want.Payload)
}
if !reflect.DeepEqual(got.Formats, tc.want.Formats) {
t.Errorf("got Formats %v, want %v", got.Formats, tc.want.Formats)
Expand Down
41 changes: 0 additions & 41 deletions pkg/api/artifacts_test.go

This file was deleted.

7 changes: 3 additions & 4 deletions pkg/api/genqlient.graphql
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# ARTIFACTS

mutation createArtifact($organizationId: ID!, $artifactName: String!, $artifactSpecs: JSON!, $artifactType: String! $artifactData: JSON!) {
mutation createArtifact($organizationId: ID!, $artifactName: String!, $artifactType: String!, $artifactPayload: JSON!) {
createArtifact(
organizationId: $organizationId,
name: $artifactName,
specs: $artifactSpecs,
type: $artifactType,
data: $artifactData
payload: $artifactPayload
) {
result {
name
Expand Down Expand Up @@ -54,7 +53,7 @@ query getArtifact($organizationId: ID!, $id: ID!) {
name
type
field
specs
payload
formats
createdAt
updatedAt
Expand Down
46 changes: 38 additions & 8 deletions pkg/api/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ type RootQueryType {
integrationTypes: [IntegrationType]

"List all integrations enabled for an organization"
integrations(organizationId: ID!): [Integration]
integrations(organizationId: ID!): [IntegrationConfig]

environment(
organizationId: ID!
Expand Down Expand Up @@ -375,7 +375,22 @@ type RootMutationType {
revokeGroupAccess(organizationId: ID!, groupId: ID!, permission: PermissionRevokeInput!): ProjectPayload

"Create an artifact"
createArtifact(organizationId: ID!, name: String!, type: String!, specs: JSON!, data: JSON!): ArtifactPayload
createArtifact(
organizationId: ID!

name: String!

type: String!

"[Deprecated] Use payload instead. Required when payload is not provided."
specs: JSON

"[Deprecated] Use payload instead. Required when payload is not provided."
data: JSON

"Artifact payload containing all artifact data. Provide this OR both data and specs."
payload: JSON
): ArtifactPayload

"Update an artifact"
updateArtifact(organizationId: ID!, id: ID!, params: ArtifactUpdateParams!): ArtifactPayload
Expand Down Expand Up @@ -478,7 +493,7 @@ type RootMutationType {
enableIntegration(organizationId: ID!, integrationTypeId: String!, config: JSON!, auth: JSON!): IntegrationPayload

"Disable an integration for an organization"
disableIntegration(organizationId: ID!, integrationTypeId: String!): Boolean
disableIntegration(organizationId: ID!, integrationConfigId: ID!): IntegrationPayload

"Create an environment"
createEnvironment(organizationId: ID!, projectId: ID!, name: String!, slug: String!, description: String): EnvironmentPayload
Expand Down Expand Up @@ -1690,19 +1705,25 @@ type EnvironmentPayload {
result: Environment
}

enum IntegrationStatus {
DISABLED
ENABLED
}

type IntegrationType {
name: String!
id: String!
configSchema: JSON!
authSchema: JSON!
}

type Integration {
type IntegrationConfig {
id: ID!
organizationId: ID!
integrationType: String!
config: JSON!
auth: JSON!
status: IntegrationStatus!
resources: [String!]!
createdAt: DateTime!
updatedAt: DateTime!
}
Expand All @@ -1715,7 +1736,7 @@ type IntegrationPayload {
messages: [ValidationMessage]

"The object created\/updated\/deleted by the mutation. May be null if mutation failed."
result: Integration
result: IntegrationConfig
}

"A connection between two nodes in the diagram"
Expand Down Expand Up @@ -2795,14 +2816,19 @@ input ArtifactsInput {
filter: ArtifactsFilters
}

"Allowed params used in updated artifacts. Provisioned artifacts can only have their name updated. Imported artifacts can update specs, data, or name"
"Allowed params used in updated artifacts. Provisioned artifacts can only have their name updated. Imported artifacts can update specs, data, payload, or name. Use payload for new integrations; data\/specs are deprecated."
input ArtifactUpdateParams {
"The new name of the artifact"
name: String

"[Deprecated] Use payload instead. Artifact specs for backward compatibility."
specs: JSON

"[Deprecated] Use payload instead. Artifact data for backward compatibility."
data: JSON

"Artifact payload containing all artifact data."
payload: JSON
}

type Artifact {
Expand All @@ -2818,7 +2844,11 @@ type Artifact {
"The bundle's artifact field (output field) that produced this artifact."
field: String

specs: JSON
"Artifact specs for backward compatibility."
specs: JSON @deprecated(reason: "Use payload instead")

"Complete artifact payload containing all artifact data. Fields marked with $md.sensitive in the artifact definition will be masked as [SENSITIVE]. Use downloadArtifact to retrieve unmasked values. See https:\/\/docs.massdriver.cloud\/json-schema-cheat-sheet\/massdriver-annotations for more details."
payload: JSON

packageId: ID @deprecated(reason: "Use package{id} instead")

Expand Down
Loading
Loading