2021-07-29 03:41:23 +00:00
|
|
|
using System;
|
2022-07-21 19:04:02 +00:00
|
|
|
using System.Collections.Generic;
|
[program-gen] Fix generated utility functions for filebase64, filebase64sha256, sha1 and mimeType (#14857)
# Description
While writing program tests for generated helper utility functions
`filebase64`, `filebase64sha256`, `sha1` and `mimeType` with the idea to
increase code coverage, it turned out that those are completely broken
in all of the languages containing syntax errors, missing imports and
wrong indentation. This PR fixes them and extends the `functions`
program to show how they now look like and to show that they compile.
Also adding example usage of `stack()`, `project()` and `cwd()` in the
test program.
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-12-15 11:26:00 +00:00
|
|
|
using System.IO;
|
2023-03-24 11:43:46 +00:00
|
|
|
using System.Linq;
|
[program-gen] Fix generated utility functions for filebase64, filebase64sha256, sha1 and mimeType (#14857)
# Description
While writing program tests for generated helper utility functions
`filebase64`, `filebase64sha256`, `sha1` and `mimeType` with the idea to
increase code coverage, it turned out that those are completely broken
in all of the languages containing syntax errors, missing imports and
wrong indentation. This PR fixes them and extends the `functions`
program to show how they now look like and to show that they compile.
Also adding example usage of `stack()`, `project()` and `cwd()` in the
test program.
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-12-15 11:26:00 +00:00
|
|
|
using System.Security.Cryptography;
|
|
|
|
using System.Text;
|
2021-07-29 03:41:23 +00:00
|
|
|
using Pulumi;
|
2022-09-16 23:12:29 +00:00
|
|
|
using Aws = Pulumi.Aws;
|
2021-07-29 03:41:23 +00:00
|
|
|
|
[program-gen] Fix generated utility functions for filebase64, filebase64sha256, sha1 and mimeType (#14857)
# Description
While writing program tests for generated helper utility functions
`filebase64`, `filebase64sha256`, `sha1` and `mimeType` with the idea to
increase code coverage, it turned out that those are completely broken
in all of the languages containing syntax errors, missing imports and
wrong indentation. This PR fixes them and extends the `functions`
program to show how they now look like and to show that they compile.
Also adding example usage of `stack()`, `project()` and `cwd()` in the
test program.
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-12-15 11:26:00 +00:00
|
|
|
|
|
|
|
string ComputeFileBase64Sha256(string path)
|
|
|
|
{
|
|
|
|
var fileData = Encoding.UTF8.GetBytes(File.ReadAllText(path));
|
|
|
|
var hashData = SHA256.Create().ComputeHash(fileData);
|
|
|
|
return Convert.ToBase64String(hashData);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string ComputeSHA1(string input)
|
|
|
|
{
|
|
|
|
var hash = SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(input));
|
|
|
|
return BitConverter.ToString(hash).Replace("-","").ToLowerInvariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string ReadFileBase64(string path)
|
|
|
|
{
|
|
|
|
return Convert.ToBase64String(Encoding.UTF8.GetBytes(File.ReadAllText(path)));
|
|
|
|
}
|
|
|
|
|
2022-07-21 19:04:02 +00:00
|
|
|
return await Deployment.RunAsync(() =>
|
2021-07-29 03:41:23 +00:00
|
|
|
{
|
2022-07-21 19:04:02 +00:00
|
|
|
var encoded = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("haha business"));
|
|
|
|
|
2022-09-16 23:12:29 +00:00
|
|
|
var decoded = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(encoded));
|
|
|
|
|
2022-07-21 19:04:02 +00:00
|
|
|
var joined = string.Join("-", new[]
|
2021-07-29 03:41:23 +00:00
|
|
|
{
|
2022-09-16 23:12:29 +00:00
|
|
|
encoded,
|
|
|
|
decoded,
|
|
|
|
"2",
|
2022-07-21 19:04:02 +00:00
|
|
|
});
|
|
|
|
|
2024-02-11 17:02:12 +00:00
|
|
|
// tests that we initialize "var, err" with ":=" first, then "=" subsequently (Go specific)
|
2022-12-13 23:17:52 +00:00
|
|
|
var zone = Aws.GetAvailabilityZones.Invoke();
|
|
|
|
|
|
|
|
var zone2 = Aws.GetAvailabilityZones.Invoke();
|
|
|
|
|
2022-09-16 23:12:29 +00:00
|
|
|
var bucket = new Aws.S3.Bucket("bucket");
|
|
|
|
|
|
|
|
var encoded2 = bucket.Id.Apply(id => Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(id)));
|
|
|
|
|
|
|
|
var decoded2 = bucket.Id.Apply(id => System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(id)));
|
|
|
|
|
2023-01-31 12:31:00 +00:00
|
|
|
var secretValue = Output.CreateSecret("hello");
|
|
|
|
|
|
|
|
var plainValue = Output.Unsecret(secretValue);
|
|
|
|
|
[program-gen] Fix generated utility functions for filebase64, filebase64sha256, sha1 and mimeType (#14857)
# Description
While writing program tests for generated helper utility functions
`filebase64`, `filebase64sha256`, `sha1` and `mimeType` with the idea to
increase code coverage, it turned out that those are completely broken
in all of the languages containing syntax errors, missing imports and
wrong indentation. This PR fixes them and extends the `functions`
program to show how they now look like and to show that they compile.
Also adding example usage of `stack()`, `project()` and `cwd()` in the
test program.
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-12-15 11:26:00 +00:00
|
|
|
var currentStack = Deployment.Instance.StackName;
|
|
|
|
|
|
|
|
var currentProject = Deployment.Instance.ProjectName;
|
|
|
|
|
|
|
|
var workingDirectory = Directory.GetCurrentDirectory();
|
|
|
|
|
|
|
|
var fileMimeType = "TODO: call mimeType";
|
|
|
|
|
|
|
|
// using the filebase64 function
|
|
|
|
var first = new Aws.S3.BucketObject("first", new()
|
|
|
|
{
|
|
|
|
Bucket = bucket.Id,
|
|
|
|
Source = new StringAsset(ReadFileBase64("./base64.txt")),
|
|
|
|
ContentType = fileMimeType,
|
|
|
|
Tags =
|
|
|
|
{
|
|
|
|
{ "stack", currentStack },
|
|
|
|
{ "project", currentProject },
|
|
|
|
{ "cwd", workingDirectory },
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// using the filebase64sha256 function
|
|
|
|
var second = new Aws.S3.BucketObject("second", new()
|
|
|
|
{
|
|
|
|
Bucket = bucket.Id,
|
|
|
|
Source = new StringAsset(ComputeFileBase64Sha256("./base64.txt")),
|
|
|
|
});
|
|
|
|
|
|
|
|
// using the sha1 function
|
|
|
|
var third = new Aws.S3.BucketObject("third", new()
|
|
|
|
{
|
|
|
|
Bucket = bucket.Id,
|
|
|
|
Source = new StringAsset(ComputeSHA1("content")),
|
|
|
|
});
|
|
|
|
|
2022-07-21 19:04:02 +00:00
|
|
|
});
|
2021-07-29 03:41:23 +00:00
|
|
|
|