Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] #USERNAME# and #GROUP# replacements in key_prefix #1

Open
12nick12 opened this issue Mar 27, 2023 · 4 comments
Open

Comments

@12nick12
Copy link

#USERNAME# and #GROUP# replacements in key_prefix for S3Config

@orware
Copy link
Owner

orware commented Mar 27, 2023

Hello @12nick12,

Are you already making use of my little sftpgo-ldap project here?

I don't recall any spots where I used something related to S3 since I was always just working with paths on the local filesystem so I was hoping you might be able to provide some extra context about the S3Config key_prefix replacement need you have when you have a moment.

@12nick12
Copy link
Author

12nick12 commented Mar 28, 2023

This does create virtual_folders on s3, but the key_prefix isn't replaced, I'm thinking it could be places somewhere around https://github.com/orware/sftpgo-ldap/blob/main/functions.php#L170 with the str_replace, but my PHP isn't too great.

// Note: that for each connection you need to provide a nested array (since you can technically define more than one virtual folder per connection):
$virtual_folders['example'] = [
    [
      //"id" => 0,
      "name" => "private-#USERNAME#",
      //"mapped_path" => 'C:\example-private\#USERNAME#',
      'filesystem' => [
        'provider' => 1,
           's3config' => [
              'bucket' => 'sftpgo-test-99-private',
                          'key_prefix' => "#USERNAME#/",
              'region' => 'us-east-2'
            ]
      ],
      //"used_quota_size" => 0,
      //"used_quota_files" => 0,
      //"last_quota_update" => 0,
      "virtual_path" => "/private",
      "quota_size" => -1,
      "quota_files" => -1
    ],
    [
        //"id" => 0,
        "name" => "public-#USERNAME#",
        //"mapped_path" => 'C:\example-private\#USERNAME#',
        'filesystem' => [
          'provider' => 1,
             's3config' => [
                'bucket' => 'sftpgo-test-99-public',
                'key_prefix' => "#USERNAME#/",
                'region' => 'us-east-2'
              ]
        ],
        //"used_quota_size" => 0,
        //"used_quota_files" => 0,
        //"last_quota_update" => 0,
        "virtual_path" => "/public",
        "quota_size" => -1,
        "quota_files" => -1
      ]
];

@orware
Copy link
Owner

orware commented Mar 28, 2023

I'd really like to look into this in more detail but at the same time I know I don't have a good testing setup for this available just now so it'd likely take me a bit longer to get to looking into this properly for you.

Overall, I think you're on the right track here with the line you pointed out.

You can see the sftpconfig type object I've primarily oriented my code around in the example from my last official release:
https://github.com/orware/sftpgo-ldap/releases/tag/0.9

Since the functions.php file should be present for tweaking/editing on your end, which I did purposefully to allow folks to further tweak things pretty easily should they need to, I think with some adjustments/testing under your current setup you can probably get things working.

Since you are focused on the key_prefix value within the s3config I think some additions are needed to target that value with probably an additional line like this one:

$output['filesystem']['s3config']['key_prefix'] = str_replace('#USERNAME#', $username, $output['filesystem']['s3config']['key_prefix']);

The replacement for groups feels like it might be similar to the above, or a bit trickier, depending on your setup because that code occurs a bit further down in that same function.

Either way, if you do sort it out or continue to work through it and want to share how it's going, please keep me posted and I'll do what I can to assist!

@12nick12
Copy link
Author

awesome, I'll give it a go. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants