| 69 | } |
| 70 | |
| 71 | func NewCASClientUseCase(credsProvider *CASCredentialsUseCase, config *conf.Bootstrap_CASServer, l log.Logger, opts ...CASClientOpts) *CASClientUseCase { |
| 72 | helper := servicelogger.ScopedHelper(l, "biz/cas-client") |
| 73 | |
| 74 | // generate a client from the given configuration |
| 75 | defaultCasClientFactory := func(conf *conf.Bootstrap_CASServer, token string) (casclient.DownloaderUploader, func(), error) { |
| 76 | conn, err := grpcconn.New(conf.GetGrpc().GetAddr(), token, grpcconn.WithInsecure(conf.GetInsecure())) |
| 77 | if err != nil { |
| 78 | return nil, nil, fmt.Errorf("failed to create grpc connection: %w", err) |
| 79 | } |
| 80 | |
| 81 | closerFn := func() { |
| 82 | err := conn.Close() |
| 83 | if err != nil { |
| 84 | helper.Error(err) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return casclient.New(conn), closerFn, err |
| 89 | } |
| 90 | |
| 91 | uc := &CASClientUseCase{ |
| 92 | credsProvider: credsProvider, |
| 93 | casServerConf: config, |
| 94 | logger: helper, |
| 95 | casClientFactory: defaultCasClientFactory, |
| 96 | } |
| 97 | |
| 98 | for _, opt := range opts { |
| 99 | opt(uc) |
| 100 | } |
| 101 | |
| 102 | return uc |
| 103 | } |
| 104 | |
| 105 | // The secretID is embedded in the JWT token and is used to identify the secret by the CAS server |
| 106 | func (uc *CASClientUseCase) Upload(ctx context.Context, backendType, secretID string, orgID uuid.UUID, content io.Reader, filename, digest string) error { |