capactio / capact

Simple way to manage applications and infrastructure.
https://capact.io
Apache License 2.0
80 stars 19 forks source link

Add support for ctx update and attach id for downloaded TypeInstance #713

Closed mszostok closed 2 years ago

mszostok commented 2 years ago

Description

Changes proposed in this pull request:

Passing TypeInstance ID

The e2e test proves that it works.

Update context

  1. Patch backend to simulate update context:

    cat <<EOF | git apply -
    diff --git a/internal/secret-storage-backend/server.go b/internal/secret-storage-backend/server.go
    index d4f171b9..2edf3054 100644
    --- a/internal/secret-storage-backend/server.go
    +++ b/internal/secret-storage-backend/server.go
    @@ -183,7 +183,9 @@ func (h *Handler) OnUpdate(_ context.Context, request *pb.OnUpdateValueAndContex
            return nil, err
        }
    
    -   return &pb.OnUpdateResponse{}, nil
    +   return &pb.OnUpdateResponse{
    +       Context: []byte("{\"updatekey\": \"updateVal2\"}"),
    +   }, nil
     }
    
     // OnLock handles TypeInstance locking by setting a secret entry in a given provider.
    
    EOF
  2. Run Backend:

    APP_SUPPORTED_PROVIDERS=dotenv APP_LOGGER_DEV_MODE=true go run ./cmd/secret-storage-backend/main.go
  3. Run Local Hub:

    APP_LOGGER_LEVEL="debug" APP_NEO4J_ENDPOINT=bolt://localhost:7687 APP_NEO4J_PASSWORD=okon APP_HUB_MODE=local npm run dev
  4. Create dotenv backend:

    cat > /tmp/dotenv-ti.yaml << ENDOFFILE
    typeInstances:
      - alias: aws-backend
        typeRef:
          path: cap.type.aws.secrets-manager.storage
          revision: 0.1.0
        value:
          url: "localhost:50051"
          acceptValue: true
          contextSchema: {
            "type": "object",
            "additionalProperties": true
          }
    ENDOFFILE
    capact typeinstance create -f /tmp/dotenv-ti.yaml -ojson
  5. Create TypeInstance:

    mutation CreateTypeInstancesWithCtxEmpty {
        createTypeInstances(
            in: {
                typeInstances: [
                    {
                        alias: "static-data"
                        typeRef: { path: "cap.type.static.data", revision: "0.1.0" }
                        value: { key: "test" }
                        backend: { id: <backend_id_from_previous_step> }
                    }
                ]
                usesRelations: []
            }
        ) {
            id
            alias
        }
    }
  6. Update TypeInstance:

    mutation UpdateData($typeInstanceID: ID!) {
        updateTypeInstances(
            in: [
                { id: $typeInstanceID, typeInstance: { value: { name: "update v4" } } }
            ]
        ) {
            ...TypeInstance
        }
    }
    
    fragment TypeInstance on TypeInstance {
        id
        createdAt {
            formatted
        }
        typeRef {
            path
            revision
        }
        lockedBy
        backend {
            id
            abstract
        }
    
        latestResourceVersion {
            ...TypeInstanceResourceVersion
        }
    }
    
    fragment TypeInstanceResourceVersion on TypeInstanceResourceVersion {
        resourceVersion
        createdBy
        metadata {
            attributes {
                path
                revision
            }
        }
        spec {
            value
            backend {
                context
            }
        }
    }

    Variable:

    {
        "typeInstanceID": "ac3b5dfa-d7e6-4579-a5f5-9ae2fe0b22b6"
    }

Related issue(s)