-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2024-09-18 17:12:23.129943 new snippets
- Loading branch information
1 parent
31ce61d
commit 7ce95a3
Showing
15 changed files
with
643 additions
and
560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//date: 2024-09-18T16:54:15Z | ||
//url: https://api.github.com/gists/133d9815f8bd9b36601b1925952eeb4c | ||
//owner: https://api.github.com/users/aspose-com-kb | ||
|
||
import com.aspose.words.*; | ||
|
||
public class Main | ||
{ | ||
public static void main(String[] args) throws Exception // Adding shapes in Java | ||
{ | ||
// Set the licenses | ||
new License().setLicense("License.lic"); | ||
|
||
Document doc = new Document(); | ||
DocumentBuilder builder = new DocumentBuilder(doc); | ||
|
||
//Inline shape | ||
Shape shape = builder.insertShape(ShapeType.LINE, 200, 200); | ||
shape.setRotation(35.0); | ||
|
||
//Free-floating shape | ||
shape = builder.insertShape | ||
( ShapeType.ARROW,RelativeHorizontalPosition.PAGE,250, | ||
RelativeVerticalPosition.PAGE,150,150,150,WrapType.INLINE); | ||
shape.setRotation(40.0); | ||
builder.writeln(); | ||
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.DOCX); | ||
|
||
// Save shapes as DML | ||
saveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_TRANSITIONAL); | ||
|
||
// Save the document | ||
doc.save("output.docx", saveOptions); | ||
|
||
System.out.println("Shapes added successfully"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#date: 2024-09-18T17:05:04Z | ||
#url: https://api.github.com/gists/124d04536cdeca0cc709c6b43ffd9871 | ||
#owner: https://api.github.com/users/Riko07br | ||
|
||
# Build angular------------------ | ||
FROM node:lts-alpine3.20 as build | ||
|
||
RUN npm install -g @angular/cli | ||
|
||
WORKDIR /app | ||
|
||
COPY package.json . | ||
|
||
RUN npm install | ||
|
||
COPY . . | ||
|
||
RUN npm run build | ||
|
||
# NGINX runner--------------- | ||
FROM nginx:1.21-alpine | ||
|
||
COPY --from=build /app/dist/frontend/browser /usr/share/nginx/html | ||
|
||
COPY ./nginx.conf /etc/nginx/conf.d/default.conf | ||
|
||
EXPOSE 80 4200 | ||
|
||
CMD ["nginx", "-g", "daemon off;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#date: 2024-09-18T16:53:38Z | ||
#url: https://api.github.com/gists/04d0e48c523b9b73b2f1d14d81e2ba3f | ||
#owner: https://api.github.com/users/h00die | ||
|
||
EC2_TOKEN=$(curl -X PUT "http: "**********": 21600" 2>/dev/null || wget -q -O - --method PUT "http://169.254.169.254/latest/api/token" --header "X-aws-ec2-metadata-token-ttl-seconds: 21600" 2>/dev/null) | ||
HEADER="X-aws-ec2-metadata-token: "**********" | ||
URL="http://169.254.169.254/latest/meta-data" | ||
aws_req="" | ||
if [ "$(command -v curl)" ]; then | ||
aws_req="curl -s -f -H '$HEADER'" | ||
elif [ "$(command -v wget)" ]; then | ||
aws_req="wget -q -O - -H '$HEADER'" | ||
else | ||
echo "Neither curl nor wget were found, I can't enumerate the metadata service :(" | ||
fi | ||
printf "ami-id: "; eval $aws_req "$URL/ami-id"; echo "" | ||
printf "instance-action: "; eval $aws_req "$URL/instance-action"; echo "" | ||
printf "instance-id: "; eval $aws_req "$URL/instance-id"; echo "" | ||
printf "instance-life-cycle: "; eval $aws_req "$URL/instance-life-cycle"; echo "" | ||
printf "instance-type: "; eval $aws_req "$URL/instance-type"; echo "" | ||
printf "region: "; eval $aws_req "$URL/placement/region"; echo "" | ||
echo "" | ||
echo "Account Info" | ||
eval $aws_req "$URL/identity-credentials/ec2/info"; echo "" | ||
eval $aws_req "http://169.254.169.254/latest/dynamic/instance-identity/document"; echo "" | ||
echo "" | ||
echo "Network Info" | ||
for mac in $(eval $aws_req "$URL/network/interfaces/macs/" 2>/dev/null); do | ||
echo "Mac: $mac" | ||
printf "Owner ID: "; eval $aws_req "$URL/network/interfaces/macs/$mac/owner-id"; echo "" | ||
printf "Public Hostname: "; eval $aws_req "$URL/network/interfaces/macs/$mac/public-hostname"; echo "" | ||
printf "Security Groups: "; eval $aws_req "$URL/network/interfaces/macs/$mac/security-groups"; echo "" | ||
echo "Private IPv4s:"; eval $aws_req "$URL/network/interfaces/macs/$mac/ipv4-associations/"; echo "" | ||
printf "Subnet IPv4: "; eval $aws_req "$URL/network/interfaces/macs/$mac/subnet-ipv4-cidr-block"; echo "" | ||
echo "PrivateIPv6s:"; eval $aws_req "$URL/network/interfaces/macs/$mac/ipv6s"; echo "" | ||
printf "Subnet IPv6: "; eval $aws_req "$URL/network/interfaces/macs/$mac/subnet-ipv6-cidr-blocks"; echo "" | ||
echo "Public IPv4s:"; eval $aws_req "$URL/network/interfaces/macs/$mac/public-ipv4s"; echo "" | ||
echo "" | ||
done | ||
echo "" | ||
echo "IAM Role" | ||
eval $aws_req "$URL/iam/info" | ||
for role in $(eval $aws_req "$URL/iam/security-credentials/" 2>/dev/null); do | ||
echo "Role: $role" | ||
eval $aws_req "$URL/iam/security-credentials/$role"; echo "" | ||
echo "" | ||
done | ||
echo "" | ||
echo "User Data" | ||
# Search hardcoded credentials | ||
eval $aws_req "http://169.254.169.254/latest/user-data" | ||
echo "" | ||
echo "EC2 Security Credentials" | ||
eval $aws_req "$URL/identity-credentials/ec2/security-credentials/ec2-instance"; echo ""ty-credentials/ec2/security-credentials/ec2-instance"; echo "" |
This file was deleted.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
seeker/snippet/check-artifact-registry-batch-deletions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#date: 2024-09-18T16:58:56Z | ||
#url: https://api.github.com/gists/cc77d7c98cd4c0c02f40f0e777ec3c0c | ||
#owner: https://api.github.com/users/philwhiteuk | ||
|
||
from collections import defaultdict | ||
from datetime import date, datetime, timedelta, UTC | ||
import os | ||
import textwrap | ||
|
||
from dotenv import load_dotenv | ||
from google.cloud import artifactregistry_v1 as artifactregistry, logging | ||
import yaml | ||
|
||
load_dotenv() # take environment variables from .env. | ||
|
||
project_id = os.getenv('PROJECT_ID') | ||
location = os.getenv('LOCATION') | ||
|
||
def get_log(log_date: date = date.today()): | ||
log_file_path = os.path.join(os.path.dirname(__file__), '../var/log', f'{log_date.isoformat()}.yaml') | ||
|
||
if not os.path.exists(log_file_path): | ||
print(f'Fetching log for {log_date.isoformat()}...') | ||
logging_client = logging.Client(project=project_id) | ||
log_query = f''' | ||
protoPayload.methodName="google.devtools.artifactregistry.v1.ArtifactRegistry.BatchDeleteVersions" | ||
AND protoPayload.authenticationInfo.principalEmail:"@gcp-sa-artifactregistry.iam.gserviceaccount.com" | ||
AND protoPayload.request.parent:"projects/{project_id}/locations/{location}" | ||
AND protoPayload.request.validateOnly=true | ||
AND protoPayload.serviceName="artifactregistry.googleapis.com" | ||
AND | ||
(timestamp > {log_date.isoformat()} AND timestamp <= {(log_date + timedelta(days=1)).isoformat()}) | ||
''' | ||
with open(log_file_path, 'a') as f: | ||
for entry in logging_client.list_entries(filter_=log_query): | ||
f.write('---\n') # Separate documents with '---' | ||
yaml.dump(entry.to_api_repr(), f) # Write entry to file | ||
|
||
with open(log_file_path, 'r') as f: | ||
yaml_docs = yaml.safe_load_all(f) | ||
return list(yaml_docs) | ||
|
||
def get_current_inventory(repository: str, package: str): | ||
inventory_path = os.path.join(os.path.dirname(__file__), '../var/inventory', f'{date.today().isoformat()}-{repository}-{package}.yaml') | ||
|
||
if not os.path.exists(inventory_path): | ||
print(f'Fetching most recent inventory for {repository}: {package}...') | ||
artifactregistry_client = artifactregistry.ArtifactRegistryClient() | ||
parent = f'projects/{project_id}/locations/{location}/repositories/{repository}/packages/{package}' | ||
request = artifactregistry.ListVersionsRequest(parent=parent) | ||
with open(inventory_path, 'a') as f: | ||
for entry in artifactregistry_client.list_versions(request=request): | ||
f.write('---\n') # Separate documents with '---' | ||
yaml.dump({'name': entry.name, 'create_time': entry.create_time.isoformat(), 'update_time': entry.update_time.isoformat()}, f) # Write entry to file | ||
|
||
with open(inventory_path, 'r') as f: | ||
yaml_docs = yaml.safe_load_all(f) | ||
return list(yaml_docs) | ||
|
||
def main(): | ||
today = date.today() | ||
print(f'Checking log for {today.isoformat()}...') | ||
log_entries = get_log(log_date=today) | ||
|
||
versions_marked_for_deletion = set() | ||
for log_entry in log_entries: | ||
if log_entry['protoPayload']['request']['names']: | ||
versions_marked_for_deletion.update(log_entry['protoPayload']['request']['names']) | ||
|
||
versions_by_package = defaultdict(list) | ||
for tag in versions_marked_for_deletion: | ||
repository = tag.split('/')[5] | ||
package = tag.split('/')[7] | ||
versions_by_package[f'{repository}/{package}'].append(tag) | ||
|
||
now = datetime.now(UTC) | ||
for package, versions_marked_for_deletion in versions_by_package.items(): | ||
repository = package.split('/')[0] | ||
package = package.split('/')[1] | ||
|
||
all_versions = get_current_inventory(repository=repository, package=package) | ||
assert len(versions_marked_for_deletion) <= len(all_versions) - 100, f'{repository}/{package} is keeping fewer than the minimum 100 versions!' | ||
summary = f''' | ||
Resource: projects/{project_id}/locations/{location}/repositories/{repository}/package/{package} | ||
Total files: {len(all_versions)} | ||
Marked for deletion: {len(versions_marked_for_deletion)} | ||
''' | ||
print(textwrap.dedent(summary)) | ||
|
||
inventory_lookup = dict() | ||
for item in all_versions: | ||
inventory_lookup.update([{ item['name'], datetime.fromisoformat(item['update_time']) }]) | ||
|
||
tag_counter = 0 | ||
for tag in versions_marked_for_deletion: | ||
if tag in inventory_lookup: | ||
timedelta = now - inventory_lookup[tag] | ||
assert timedelta.days >= 5, f'Version {tag} is newer than 5 days!' | ||
print(f'- ✅ {tag.split('/')[-1]} {timedelta.days} days old') | ||
tag_counter += 1 | ||
|
Oops, something went wrong.