#Issues storing *dagger.Secret inside module struct

1 messages ยท Page 1 of 1 (latest)

rapid summit
#

๐Ÿ‘‹ Hey!

I've been getting weird errors when creating secrets inside a module's constructor and trying to use them later on.
The actual use case is exchanging OIDC tokens for a token authenticating to a service, which I then need to use later on.

Here is a reproduction example:
I have a module that generates and stores a secret on initialization:

package main

import (
    "context"

    "dagger/generator/internal/dagger"
)

type Generator struct {
    // +private
    Password *dagger.Secret
}

func New() *Generator {
    return &Generator{
        Password: dag.SetSecret("pass", "admin"),
    }
}

func (m *Generator) Gen(ctx context.Context, name string) error {
    _, err := m.Password.Plaintext(ctx)
    return err
}

I have a second module that depends on the first one and wraps calls to it like so:

package main

import (
    "context"
)

type Keychain struct{}

func (m *Keychain) Get(ctx context.Context, name string) error {
    return dag.Generator().Gen(ctx, name)
}

Finally, I use the second module from a contextual module:

package main

import (
    "context"
    "fmt"
)

type Mymodule struct{}

func (m *Mymodule) Issue(ctx context.Context) error {
    kc := dag.Keychain()

    err := kc.Get(ctx, "a")
    if err != nil {
        return fmt.Errorf("first get: %w", err)
    }

    err = kc.Get(ctx, "b")
    if err != nil {
        return fmt.Errorf("second get: %w", err)
    }
    return nil
}

The first call to kc.Get is succesful.
However, the second one fails (see error in comment).

Any insights on what is going on?
How could I create that secret in a way that I know will not fail?

Thank you for your help!

rare apex
#

I experienced what appears to be the same issue (albeit in Python), you may find this discussion insightful @rapid summit: #1284179165322416220 message

wispy crater
#

silently pinging @crude karma @inland drift and @dense yarrow since this looks like an interesting one we might want to take a look at

dense yarrow
#

love a good clean repro, i haven't played with secrets yet but i'd like to poke at this on monday

crude karma
#

Good luck ๐Ÿ™‚ ๐Ÿ™‚